[FIX] Basic patches for product_extended

This commit is contained in:
Josse Colpaert 2014-09-17 10:42:52 +02:00
parent 0f9a9fbae3
commit 7a69b329b1
1 changed files with 13 additions and 12 deletions

View File

@ -36,15 +36,15 @@ class product_product(osv.osv):
testdict = {} testdict = {}
for prod_id in ids: for prod_id in ids:
bom_obj = self.pool.get('mrp.bom') bom_obj = self.pool.get('mrp.bom')
bom_ids = bom_obj.search(cr, uid, [('product_id','=', prod_id), ('bom_line_ids', '!=', False)], context=context) bom_id = bom_obj._bom_find(cr, uid, False, product_id = prod_id, context=context)
if bom_ids: if bom_id:
bom_id = bom_ids[0]
# In recursive mode, it will first compute the prices of child boms # In recursive mode, it will first compute the prices of child boms
if recursive: if recursive:
#Search the products that are components of this bom of prod_id #Search the products that are components of this bom of prod_id
boms = bom_obj.search(cr, uid, [('bom_id', '=', bom_id)], context=context) bom = bom_obj.browse(cr, uid, bom_id, context=context)
#Call compute_price on these subproducts #Call compute_price on these subproducts
prod_set = set([x.product_id.id for x in bom_obj.browse(cr, uid, boms, context=context)]) prod_set = set([x.product_id.id for x in bom.bom_line_ids])
res = self.compute_price(cr, uid, list(prod_set), recursive=recursive, test=test, real_time_accounting = real_time_accounting, context=context) res = self.compute_price(cr, uid, list(prod_set), recursive=recursive, test=test, real_time_accounting = real_time_accounting, context=context)
if test: if test:
testdict.update(res) testdict.update(res)
@ -63,9 +63,9 @@ class product_product(osv.osv):
context={} context={}
price = 0 price = 0
uom_obj = self.pool.get("product.uom") uom_obj = self.pool.get("product.uom")
if bom.bom_line_ids: tmpl_obj = self.pool.get('product.template')
for sbom in bom.bom_line_ids: for sbom in bom.bom_line_ids:
my_qty = sbom.bom_line_ids and 1.0 or sbom.product_qty my_qty = sbom.product_qty
price += uom_obj._compute_price(cr, uid, sbom.product_id.uom_id.id, sbom.product_id.standard_price, sbom.product_uom.id) * my_qty price += uom_obj._compute_price(cr, uid, sbom.product_id.uom_id.id, sbom.product_id.standard_price, sbom.product_uom.id) * my_qty
if bom.routing_id: if bom.routing_id:
@ -79,15 +79,16 @@ class product_product(osv.osv):
#Convert on product UoM quantities #Convert on product UoM quantities
if price > 0: if price > 0:
price = uom_obj._compute_price(cr, uid, bom.product_uom.id, price / bom.product_qty, bom.product_id.uom_id.id) price = uom_obj._compute_price(cr, uid, bom.product_uom.id, price / bom.product_qty, bom.product_id.uom_id.id)
product = self.pool.get("product.product").browse(cr, uid, bom.product_id.id, context=context)
product = tmpl_obj.browse(cr, uid, bom.product_tmpl_id.id, context=context)
if not test: if not test:
if (product.valuation != "real_time" or not real_time_accounting): if (product.valuation != "real_time" or not real_time_accounting):
self.write(cr, uid, [bom.product_id.id], {'standard_price' : price}, context=context) tmpl_obj.write(cr, uid, [product.id], {'standard_price' : price}, context=context)
else: else:
#Call wizard function here #Call wizard function here
wizard_obj = self.pool.get("stock.change.standard.price") wizard_obj = self.pool.get("stock.change.standard.price")
ctx = context.copy() ctx = context.copy()
ctx.update({'active_id': bom.product_id.id}) ctx.update({'active_id': product.id, 'active_model': 'product.template'})
wiz_id = wizard_obj.create(cr, uid, {'new_price': price}, context=ctx) wiz_id = wizard_obj.create(cr, uid, {'new_price': price}, context=ctx)
wizard_obj.change_price(cr, uid, [wiz_id], context=ctx) wizard_obj.change_price(cr, uid, [wiz_id], context=ctx)
return price return price