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
price_obj = self.pool.get('product.pricelist')
47
product_obj = self.pool.get('product.product')
48
product_brw = product and product_obj.browse(cr,uid,product,context=context)
49
res = super(sale_order_line,self).product_id_change(cr, uid, ids, pricelist, product, qty=qty,
50
uom=uom, qty_uos=qty_uos, uos=uos, name=name, partner_id=partner_id,
51
lang=lang, update_tax=update_tax, date_order=date_order, packaging=packaging, fiscal_position=fiscal_position, flag=flag,context=context)
52
if context.get('price_change',False):
53
price = price_obj.price_get(cr, uid, [context.get('price_change',False)], product, qty, context=context)
54
res.get('value',{}).update({'price_unit': round(price.get(context.get('price_change',False)),2)})
55
res.get('value',False) and product_brw and product_brw.categ_id and res.get('value',False).update({'categ_id':product_brw.categ_id.id })
56
res.get('value',False) and 'price_unit' in res.get('value',False) and res['value'].pop('price_unit')
60
def price_unit(self,cr,uid,ids,price_list,product_id,qty,context=None):
62
Calculating the amount of model _compute_price method product.uom
67
if price_list and product_id and qty:
68
price_obj = self.pool.get('product.pricelist')
69
price = price_obj.price_get(cr, uid, [price_list], product_id, qty, context=context)
70
res['value'].update({'price_unit': round(price.get(price_list),2)})
73
_inherit = 'sale.order.line'
75
'product_id': fields.many2one('product.product', 'Product', domain=[('sale_ok', '=', True)], change_default=True),
76
'price_list_ids':fields.many2one('product.pricelist','Select Price'),
77
'cost_structure_id':fields.many2one('cost.structure','Cost Structure'),
78
'categ_id':fields.many2one('product.category','Category',help='Category by product selected'),
84
class sale_order(osv.osv):
88
_inherit = 'sale.order'
91
def _price_status(self, cr, uid, ids, field_name, arg, context=None):
93
Check That the products sold are not sold at a price less than or greater than the price rago allocated in the product.
94
Failure to comply with this will print a message informing the product that is not complying with this requirement
102
context.update({'query':False})
103
pricelist_obj = self.pool.get('product.pricelist')
104
for order in len(ids) == 1 and self.browse(cr,uid,ids,context=context) or []:
105
for line in order.order_line:
106
price_compute = line.product_id and [ pricelist_obj.price_get(cr, uid, [i.price_list_id and i.price_list_id.id ],
107
line.product_id.id, line.product_uom_qty, context=context).get(i.price_list_id.id) for i in line.product_id.price_list_item_ids or line.product_id.category_item_ids]
109
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
110
if property_cost_structure and len(price_compute) == len([i for i in price_compute if round(line.price_unit,2) < round(i,2)]):
111
product.append(u'Intenta vender el producto %s a un precio menor al estimado para su venta'%line.product_id.name)
112
res[order.id] = {'status_bool':True}
114
elif property_cost_structure and len(price_compute) == len([i for i in price_compute if round(line.price_unit,2) > round(i,2)]):
115
product.append(u'Intenta vender el producto %s a un precio mayor al estimado para su venta'%line.product_id.name)
116
res[order.id] = {'status_bool':True}
119
elif not property_cost_structure:
120
product.append(u'El producto %s no tiene una estructura de costo'%line.product_id.name)
121
res[order.id] = {'status_bool':True}
124
res[order.id] = '\n'.join(product)
126
res[order.id] = {'status_bool':False}
128
res[order.id] = '\n'.join(product)
135
'status_price':fields.function(_price_status, method=True,type="text", store=True, string='Status Price'),
136
'status_bool':fields.function(_price_status, method=True,type="boolean", string='Status Price'),
146
def price_unit_confirm(self,cr,uid,ids,context=None):
148
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
153
context.update({'query':False})
154
sale_brw = self.browse(cr,uid,ids and ids[0],context=context)
155
pricelist_obj = self.pool.get('product.pricelist')
156
for line in len(ids) == 1 and sale_brw.order_line or []:
157
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
158
price_compute = line.product_id and [ pricelist_obj.price_get(cr, uid, [i.price_list_id and i.price_list_id.id ],
159
line.product_id.id, line.product_uom_qty, context=context).get(i.price_list_id.id) for i in line.product_id.price_list_item_ids or line.product_id.category_item_ids]
161
if property_cost_structure and len(price_compute) == len([i for i in price_compute if round(line.price_unit,2) < round(i,2)]):
162
product.append(u'Intenta vender el producto %s a un precio menor al estimado para su venta'%line.product_id.name)
164
elif property_cost_structure and len(price_compute) == len([i for i in price_compute if round(line.price_unit,2) > round(i,2)]):
165
product.append(u'Intenta vender el producto %s a un precio mayor al estimado para su venta'%line.product_id.name)
168
elif not property_cost_structure:
169
product.append(u'The product %s has not a cost structure'%line.product_id.name)
172
raise osv.except_osv(_('Error'), _('\n'.join(product)))