[FIX] mrp_subproduct: update qty to produce now change accordingly the qty of subproducts created
lp bug: https://launchpad.net/bugs/904170 fixed bzr revid: qdp-launchpad@openerp.com-20120214155746-zyejucj0745obtps
This commit is contained in:
parent
9effc0ba64
commit
471d403d81
|
@ -48,7 +48,12 @@ class change_production_qty(osv.osv_memory):
|
|||
if 'product_qty' in fields:
|
||||
res.update({'product_qty': prod.product_qty})
|
||||
return res
|
||||
|
||||
|
||||
def _update_product_to_produce(self, cr, uid, prod, qty, context=None):
|
||||
move_lines_obj = self.pool.get('stock.move')
|
||||
for m in prod.move_created_ids:
|
||||
move_lines_obj.write(cr, uid, [m.id], {'product_qty': qty})
|
||||
|
||||
def change_prod_qty(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Changes the Quantity of Product.
|
||||
|
@ -57,7 +62,7 @@ class change_production_qty(osv.osv_memory):
|
|||
@param uid: ID of the user currently logged in
|
||||
@param ids: List of IDs selected
|
||||
@param context: A standard dictionary
|
||||
@return:
|
||||
@return:
|
||||
"""
|
||||
record_id = context and context.get('active_id',False)
|
||||
assert record_id, _('Active Id is not found')
|
||||
|
@ -67,7 +72,7 @@ class change_production_qty(osv.osv_memory):
|
|||
prod = prod_obj.browse(cr, uid, record_id, context=context)
|
||||
prod_obj.write(cr, uid,prod.id, {'product_qty': wiz_qty.product_qty})
|
||||
prod_obj.action_compute(cr, uid, [prod.id])
|
||||
|
||||
|
||||
move_lines_obj = self.pool.get('stock.move')
|
||||
for move in prod.move_lines:
|
||||
bom_point = prod.bom_id
|
||||
|
@ -78,20 +83,19 @@ class change_production_qty(osv.osv_memory):
|
|||
raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
|
||||
prod_obj.write(cr, uid, [prod.id], {'bom_id': bom_id})
|
||||
bom_point = bom_obj.browse(cr, uid, [bom_id])[0]
|
||||
|
||||
|
||||
if not bom_id:
|
||||
raise osv.except_osv(_('Error'), _("Couldn't find bill of material for product"))
|
||||
|
||||
|
||||
factor = prod.product_qty * prod.product_uom.factor / bom_point.product_uom.factor
|
||||
res = bom_obj._bom_explode(cr, uid, bom_point, factor / bom_point.product_qty, [])
|
||||
for r in res[0]:
|
||||
if r['product_id'] == move.product_id.id:
|
||||
move_lines_obj.write(cr, uid, [move.id], {'product_qty' : r['product_qty']})
|
||||
for m in prod.move_created_ids:
|
||||
move_lines_obj.write(cr, uid, [m.id], {'product_qty': wiz_qty.product_qty})
|
||||
|
||||
self._update_product_to_produce(cr, uid, prod, wiz_qty.product_qty, context=context)
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
change_production_qty()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -61,12 +61,14 @@ class mrp_bom(osv.osv):
|
|||
_columns={
|
||||
'sub_products':fields.one2many('mrp.subproduct', 'bom_id', 'sub_products'),
|
||||
}
|
||||
|
||||
mrp_bom()
|
||||
|
||||
class mrp_production(osv.osv):
|
||||
_description = 'Production'
|
||||
_inherit= 'mrp.production'
|
||||
|
||||
|
||||
def action_confirm(self, cr, uid, ids):
|
||||
""" Confirms production order and calculates quantity based on subproduct_type.
|
||||
@return: Newly generated picking Id.
|
||||
|
@ -124,4 +126,22 @@ class mrp_production(osv.osv):
|
|||
return super(mrp_production, self)._get_subproduct_factor(cr, uid, production_id, move_id, context=context)
|
||||
|
||||
mrp_production()
|
||||
|
||||
class change_production_qty(osv.osv_memory):
|
||||
_inherit = 'change.production.qty'
|
||||
|
||||
def _update_product_to_produce(self, cr, uid, prod, qty, context=None):
|
||||
bom_obj = self.pool.get('mrp.bom')
|
||||
move_lines_obj = self.pool.get('stock.move')
|
||||
prod_obj = self.pool.get('mrp.production')
|
||||
for m in prod.move_created_ids:
|
||||
if m.product_id.id == prod.product_id.id:
|
||||
move_lines_obj.write(cr, uid, [m.id], {'product_qty': qty})
|
||||
else:
|
||||
for sub_product_line in prod.bom_id.sub_products:
|
||||
if sub_product_line.product_id.id == m.product_id.id:
|
||||
factor = prod_obj._get_subproduct_factor(cr, uid, prod.id, m.id, context=context)
|
||||
subproduct_qty = sub_product_line.subproduct_type == 'variable' and qty * factor or sub_product_line.product_qty
|
||||
move_lines_obj.write(cr, uid, [m.id], {'product_qty': subproduct_qty})
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue