2
# -*- encoding: utf-8 -*-
3
###########################################################################
4
# Module Writen to OpenERP, Open Source Management Solution
5
# Copyright (C) OpenERP Venezuela (<http://openerp.com.ve>).
7
###############Credits######################################################
8
# Coded by: Vauxoo C.A.
9
# Planified by: Nhomar Hernandez
10
# Audited by: Vauxoo C.A.
11
#############################################################################
12
# This program is free software: you can redistribute it and/or modify
13
# it under the terms of the GNU Affero General Public License as published by
14
# the Free Software Foundation, either version 3 of the License, or
15
# (at your option) any later version.
17
# This program is distributed in the hope that it will be useful,
18
# but WITHOUT ANY WARRANTY; without even the implied warranty of
19
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
# GNU Affero General Public License for more details.
22
# You should have received a copy of the GNU Affero General Public License
23
# along with this program. If not, see <http://www.gnu.org/licenses/>.
24
################################################################################
26
from osv import fields, osv
28
from tools.translate import _
29
from tools import config
31
import decimal_precision as dp
34
class sale_order_line(osv.osv):
36
def product_id_change(self, cr, uid, ids, pricelist, product, qty=0,
37
uom=False, qty_uos=0, uos=False, name='', partner_id=False,
38
lang=False, update_tax=True, date_order=False, packaging=False, fiscal_position=False, flag=False,context=None):
40
Overridden the method of product line sales, to replace the unit price calculation and selection of the cost structure
41
that handles the product, and later to filter the prices for the product selected
46
product_obj = self.pool.get('product.product')
47
product_brw = product and product_obj.browse(cr,uid,product,context=context)
48
res = super(sale_order_line,self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
49
uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
50
lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag)
52
res.get('value',False) and product_brw and product_brw.property_cost_structure and res.get('value',False).update({'cost_structure_id':product_brw and product_brw.property_cost_structure and product_brw.property_cost_structure.id })
53
res.get('value',False) and 'price_unit' in res.get('value',False) and res['value'].pop('price_unit')
57
def price_unit(self,cr,uid,ids,price_method,product_uom,qty,context=None):
59
Calculating the amount of model _compute_price method product.uom
65
if price_method and product_uom:
66
price_obj = self.pool.get('method.price')
67
uom_obj = self.pool.get('product.uom')
68
uom_brw = uom_obj.browse(cr,uid,product_uom,context=context)
69
price_brw = price_obj.browse(cr,uid,price_method,context=context)
70
price = price_brw and price_brw.unit_price
71
price = uom_obj._compute_price(cr, uid, product_uom, price, to_uom_id=False)
73
e = uom_obj._compute_qty(cr, uid, product_uom, qty, to_uom_id=product_uom)
74
res['value'].update({'price_unit': round(price,2)})
77
_inherit = 'sale.order.line'
79
'price_structure_id':fields.many2one('method.price','Select Price'),
80
'cost_structure_id':fields.many2one('cost.structure','Cost Structure'),
86
class sale_order(osv.osv):
90
_inherit = 'sale.order'
93
def _price_status(self, cr, uid, ids, field_name, arg, context=None):
95
Check That the products sold are not sold at a price less than or greater than the price rago allocated in the product.
96
Failure to comply with this will print a message informing the product that is not complying with this requirement
104
cost_obj = self.pool.get('cost.structure')
105
for order in self.browse(cr,uid,ids,context=context):
106
for line in order.order_line:
107
property_cost_structure = line and line.product_id and line.product_id.property_cost_structure and line.product_id.property_cost_structure.id or False
108
if property_cost_structure and len(line.product_id.method_cost_ids) == len([i.id for i in line.product_id.method_cost_ids if round(line.price_unit,2) < round(i.unit_price,2)]):
109
product.append(u'Intenta vender el producto %s a un precio menor al estimado para su venta'%line.product_id.name)
110
res[order.id] = {'status_bool':True}
112
elif property_cost_structure and len(line.product_id.method_cost_ids) == len([i.id for i in line.product_id.method_cost_ids if round(line.price_unit,2) > round(i.unit_price,2)]):
113
product.append(u'Intenta vender el producto %s a un precio mayor al estimado para su venta'%line.product_id.name)
114
res[order.id] = {'status_bool':True}
117
elif not property_cost_structure:
118
product.append(u'El producto %s no tiene una estructura de costo'%line.product_id.name)
119
res[order.id] = {'status_bool':True}
122
res[order.id] = '\n'.join(product)
124
res[order.id] = {'status_bool':False}
126
res[order.id] = '\n'.join(product)
133
'status_price':fields.function(_price_status, method=True,type="text", store=True, string='Status Price'),
134
'status_bool':fields.function(_price_status, method=True,type="boolean", string='Status Price'),
144
def price_unit_confirm(self,cr,uid,ids,context=None):
146
Workflow condition does not allow the sale process if at least one product is being sold in the price range set out in its cost structure
151
sale_brw = self.browse(cr,uid,ids and ids[0],context=context)
152
for line in sale_brw.order_line:
153
property_cost_structure = line and line.product_id and line.product_id.property_cost_structure and line.product_id.property_cost_structure.id or False
154
if property_cost_structure and len(line.product_id.method_cost_ids) == len([i.id for i in line.product_id.method_cost_ids if round(line.price_unit,2) < round(i.unit_price,2)]):
155
product.append(u'Intenta vender el producto %s a un precio menor al estimado para su venta'%line.product_id.name)
157
elif property_cost_structure and len(line.product_id.method_cost_ids) == len([i.id for i in line.product_id.method_cost_ids if round(line.price_unit,2) > round(i.unit_price,2)]):
158
product.append(u'Intenta vender el producto %s a un precio mayor al estimado para su venta'%line.product_id.name)
161
elif not property_cost_structure:
162
product.append(u'The product %s has not a cost structure'%line.product_id.name)
165
raise osv.except_osv(_('Error'), _('\n'.join(product)))