Kirti Savalia(OpenERP) has proposed merging
lp:~openerp-dev/openobject-addons/trunk-904170-product2consume-ksa into
lp:openobject-addons.
Requested reviews:
Rucha (Open ERP) (rpa-openerp)
For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-904170-product2consume-ksa/+merge/90390
[1]when subproduct with quantity type set to "fixed" it is not changed when use
the change quantity wizard
[2]split the quantity in products to consume and use the change quantity wizard.
[3]split the quantity in products to consume and produce the quantity according
to wizard "produce & cosume".
[4]Refactor the original code such a way and add new function
production_consume_produce_line_data for the finish product line and clean the
code.
Thanks
KSA
--
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-904170-product2consume-ksa/+merge/90390
Your team OpenERP R&D Team is subscribed to branch
lp:~openerp-dev/openobject-addons/trunk-904170-product2consume-ksa.
=== modified file 'mrp/mrp.py'
--- mrp/mrp.py 2011-12-31 07:57:20 +0000
+++ mrp/mrp.py 2012-01-27 09:37:31 +0000
@@ -722,7 +722,7 @@
if qty_avail <= 0.0:
# there will be nothing to consume for this raw material
continue
-
+ remain_qty = 0
raw_product = [move for move in production.move_lines if move.product_id.id==scheduled.product_id.id]
if raw_product:
# qtys we have to consume
@@ -735,9 +735,26 @@
if qty <= 0.0:
# we already have more qtys consumed than we need
continue
-
- raw_product[0].action_consume(qty, raw_product[0].location_id.id, context=context)
-
+ remain_qty = 0
+ move_qty_check = 0
+ move_wizard_qty = qty
+ for data in raw_product:
+ if remain_qty >0:
+ qty = remain_qty
+ if move_qty_check == move_wizard_qty:
+ break
+ if data.product_qty == qty:
+ data.action_consume(qty, data.location_id.id, context=context)
+ move_qty_check += qty
+ break
+ elif data.product_qty > qty:
+ data.action_consume(qty, data.location_id.id, context=context)
+ move_qty_check += qty
+ remain_qty = data.product_qty - qty
+ else:
+ data.action_consume(data.product_qty, data.location_id.id, context=context)
+ move_qty_check += data.product_qty
+ remain_qty = qty - data.product_qty
if production_mode == 'consume_produce':
# To produce remaining qty of final product
#vals = {'state':'confirmed'}
@@ -1049,4 +1066,4 @@
}
mrp_production_product_line()
-# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
\ No newline at end of file
=== modified file 'mrp/wizard/change_production_qty.py'
--- mrp/wizard/change_production_qty.py 2011-10-31 11:38:30 +0000
+++ mrp/wizard/change_production_qty.py 2012-01-27 09:37:31 +0000
@@ -48,10 +48,10 @@
if 'product_qty' in fields:
res.update({'product_qty': prod.product_qty})
return res
-
- def change_prod_qty(self, cr, uid, ids, context=None):
+
+ def production_consume_produce_line_data(self, cr, uid, ids, context=None):
"""
- Changes the Quantity of Product.
+ Changes the Quantity for consume and Finish product line.
@param self: The object pointer.
@param cr: A database cursor
@param uid: ID of the user currently logged in
@@ -69,24 +69,42 @@
prod_obj.action_compute(cr, uid, [prod.id])
move_lines_obj = self.pool.get('stock.move')
- for move in prod.move_lines:
+ remain_qty = 0
+ for scheduled in prod.product_lines:
bom_point = prod.bom_id
bom_id = prod.bom_id.id
- if not bom_point:
- bom_id = bom_obj._bom_find(cr, uid, prod.product_id.id, prod.product_uom.id)
- if not 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']})
+ raw_product = [move for move in prod.move_lines if move.product_id.id==scheduled.product_id.id]
+ r_qty = res[0][1]['product_qty']
+ count = 0
+ for data in raw_product:
+ if count == 0:
+ move_lines_obj.write(cr, uid, data.id, {'product_qty': r_qty})
+ count += 1
+ else:
+ cr.execute("delete from stock_move where id=%s", (data.id,))
+ count += 1
+
+ return {}
+
+ def change_prod_qty(self, cr, uid, ids, context=None):
+ """
+ Changes the Quantity of Product.
+ @param self: The object pointer.
+ @param cr: A database cursor
+ @param uid: ID of the user currently logged in
+ @param ids: List of IDs selected
+ @param context: A standard dictionary
+ @return:
+ """
+ record_id = context and context.get('active_id',False)
+ assert record_id, _('Active Id is not found')
+ move_lines_obj = self.pool.get('stock.move')
+ prod_obj = self.pool.get('mrp.production')
+ self.production_consume_produce_line_data(cr, uid, ids, context=context)
+ prod = prod_obj.browse(cr, uid, record_id, context=context)
+ for wiz_qty in self.browse(cr, uid, ids, context=context):
for m in prod.move_created_ids:
move_lines_obj.write(cr, uid, [m.id], {'product_qty': wiz_qty.product_qty})
=== modified file 'mrp_subproduct/mrp_subproduct.py'
--- mrp_subproduct/mrp_subproduct.py 2011-11-11 13:59:06 +0000
+++ mrp_subproduct/mrp_subproduct.py 2012-01-27 09:37:31 +0000
@@ -124,4 +124,40 @@
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 change_prod_qty(self, cr, uid, ids, context=None):
+ """
+ Changes the Quantity of Product.
+ @param self: The object pointer.
+ @param cr: A database cursor
+ @param uid: ID of the user currently logged in
+ @param ids: List of IDs selected
+ @param context: A standard dictionary
+ @return:
+ """
+ record_id = context and context.get('active_id',False)
+ assert record_id, _('Active Id is not found')
+ prod_obj = self.pool.get('mrp.production')
+ move_lines_obj = self.pool.get('stock.move')
+ self.production_consume_produce_line_data(cr, uid, ids, context=context)
+ prod = prod_obj.browse(cr, uid, record_id, context=context)
+ for wiz_qty in self.browse(cr, uid, ids, context=context):
+ for m in prod.move_created_ids:
+ for sub_product in prod.bom_id.sub_products:
+ if sub_product.product_id.id == m.product_id.id:
+ if sub_product.subproduct_type == 'fixed':
+ move_lines_obj.write(cr, uid, [m.id], {'product_qty': sub_product.product_qty})
+ break
+ else:
+ move_lines_obj.write(cr, uid, [m.id], {'product_qty': sub_product.product_qty * wiz_qty.product_qty})
+ break
+ else:
+ move_lines_obj.write(cr, uid, [m.id], {'product_qty': wiz_qty.product_qty})
+
+ return {}
+
+change_production_qty()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help : https://help.launchpad.net/ListHelp