credativ team mailing list archive
-
credativ team
-
Mailing list archive
-
Message #01565
[Bug 733156] Re: Cannot post consume on production order
Got the solution by adding a flag variable in action_produce function in
mrp.py.
Here is the code... but check it once by yourself.
def action_produce(self, cr, uid, production_id, production_qty, production_mode, context=None):
""" To produce final product based on production mode (consume/consume&produce).
If Production mode is consume, all stock move lines of raw materials will be done/consumed.
If Production mode is consume & produce, all stock move lines of raw materials will be done/consumed
and stock move lines of final product will be also done/produced.
@param production_id: the ID of mrp.production object
@param production_qty: specify qty to produce
@param production_mode: specify production mode (consume/consume&produce).
@return: True
"""
count=0
stock_mov_obj = self.pool.get('stock.move')
production = self.browse(cr, uid, production_id, context=context)
final_product_todo = []
produced_qty = 0
if production_mode == 'consume_produce':
produced_qty = production_qty
for produced_product in production.move_created_ids2:
if (produced_product.scrapped) or (produced_product.product_id.id <> production.product_id.id):
continue
produced_qty += produced_product.product_qty
if production_mode in ['consume', 'consume_produce']:
consumed_products = {}
check = {}
scrapped = map(lambda x:x.scrapped, production.move_lines2).count(True)
for consumed_product in production.move_lines2:
consumed = consumed_product.product_qty
if consumed_product.scrapped:
continue
if not consumed_products.get(consumed_product.product_id.id, False):
consumed_products[consumed_product.product_id.id] = consumed_product.product_qty
check[consumed_product.product_id.id] = 0
for f in production.product_lines:
if f.product_id.id == consumed_product.product_id.id:
if (len(production.move_lines2) - scrapped) > len(production.product_lines):
check[consumed_product.product_id.id] += consumed_product.product_qty
consumed = check[consumed_product.product_id.id]
rest_consumed = produced_qty * f.product_qty / production.product_qty - consumed
consumed_products[consumed_product.product_id.id] = rest_consumed
for raw_product in production.move_lines:
count=0
for f in production.product_lines:
if f.product_id.id == raw_product.product_id.id and count==0:
count=count+1
consumed_qty = consumed_products.get(raw_product.product_id.id, 0)
if consumed_qty == 0:
consumed_qty = production_qty * f.product_qty / production.product_qty
if consumed_qty > 0:
stock_mov_obj.action_consume(cr, uid, [raw_product.id], consumed_qty, production.location_src_id.id, context=context)
if production_mode == 'consume_produce':
# To produce remaining qty of final product
vals = {'state':'confirmed'}
#final_product_todo = [x.id for x in production.move_created_ids]
#stock_mov_obj.write(cr, uid, final_product_todo, vals)
#stock_mov_obj.action_confirm(cr, uid, final_product_todo, context)
produced_products = {}
for produced_product in production.move_created_ids2:
if produced_product.scrapped:
continue
if not produced_products.get(produced_product.product_id.id, False):
produced_products[produced_product.product_id.id] = 0
produced_products[produced_product.product_id.id] += produced_product.product_qty
for produce_product in production.move_created_ids:
produced_qty = produced_products.get(produce_product.product_id.id, 0)
rest_qty = production.product_qty - produced_qty
if rest_qty <= production_qty:
production_qty = rest_qty
if rest_qty > 0 :
stock_mov_obj.action_consume(cr, uid, [produce_product.id], production_qty, context=context)
for raw_product in production.move_lines2:
new_parent_ids = []
parent_move_ids = [x.id for x in raw_product.move_history_ids]
for final_product in production.move_created_ids2:
if final_product.id not in parent_move_ids:
new_parent_ids.append(final_product.id)
for new_parent_id in new_parent_ids:
stock_mov_obj.write(cr, uid, [raw_product.id], {'move_history_ids': [(4, new_parent_id)]})
wf_service = netsvc.LocalService("workflow")
wf_service.trg_validate(uid, 'mrp.production', production_id, 'button_produce_done', cr)
return True
Hope this will resolve your problem.
--
You received this bug notification because you are a member of OpenERP
Framework Experts, which is subscribed to OpenERP Addons.
https://bugs.launchpad.net/bugs/733156
Title:
Cannot post consume on production order
Status in OpenERP Addons (modules):
Confirmed
Bug description:
Using v6, I defined a BOM wich has same raw material on 2 lines - because the raw material is added in 2 steps of production process.
eg. in demo database - change CPU_GEN BOM, raw material CPU1 exists with qty=1 then add new line (after other raw materials) CPU1 with qty=2. Make Production order CPU_GEN qty=3
When posting consumption with regular user (even new admin user - not uid 1 admin) the following message shows:
Quantities, UoMs, Products and Locations cannot be modified on stock moves that have already been processed (except by the Administrator). If I take each line of raw material and post, the consume is made without problems.
When posting with admin (uid=1) the consume is posted. This is because is a uid = 1 verification when changing stock moves.
I noticed that consumption lines are different from products to consume :to consume - 2 lines with qty=3 and 6, consumed - 3 lines each with qty=3.
There are 2 issues:
- cannot post consumption in the above situation
- split of consumption lines
To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-addons/+bug/733156/+subscriptions