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.
@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')
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
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:
_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.
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: