Merge lp:~openerp-dev/openobject-addons/6.1-opw-575816-cbi into lp:openobject-addons/6.1

Proposed by Chris Biersbach (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/6.1-opw-575816-cbi
Merge into: lp:openobject-addons/6.1
Diff against target: 67 lines (+38/-1)
2 files modified
mrp/mrp.py (+35/-0)
stock/stock.py (+3/-1)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/6.1-opw-575816-cbi
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+139398@code.launchpad.net

Description of the change

The original branch:
https://code.launchpad.net/~openerp-dev/openobject-addons/6.1-opw-575816-rha

The issue that was encountered: When cancelling a manufacturing order that had already been partially produced, the remaining good to consume were not returned to the stock

The reason: well, I guess someone forgot to implement this part of cancelling

The fix: I based myself on rha's patch that already creates a picking to return the goods to their previous stock location. However, the customer still complained that the journal entries are not correct. The account moves corresponding to the stock moves in the new picking need to credit the destination accoutn and not the source account, so I did this additional change.

To post a comment you must log in.

Unmerged revisions

7078. By Chris Biersbach (OpenERP)

[FIX] Cancelling a partially produced manufacturing order now correctly returns all the remaining products to consume to their previous stock location.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'mrp/mrp.py'
--- mrp/mrp.py 2012-10-05 10:44:47 +0000
+++ mrp/mrp.py 2012-12-12 08:17:19 +0000
@@ -615,6 +615,37 @@
615 line['production_id'] = production.id615 line['production_id'] = production.id
616 workcenter_line_obj.create(cr, uid, line)616 workcenter_line_obj.create(cr, uid, line)
617 return len(results)617 return len(results)
618
619 def _reallocate_picking(self, cr, uid, production, context=None):
620 """ Goods remain allocated while cancelling 'ready to produce'
621 production order. It creates new picking to release the goods
622 back to stock.
623 """
624 if context is None:
625 context = {}
626 consumed_info = {}
627 move_obj = self.pool.get('stock.move')
628 picking_obj = self.pool.get('stock.picking')
629 for consumed_move in production.move_lines2:
630 if consumed_move.state == 'done':
631 if not consumed_move.product_id.id in consumed_info:
632 consumed_info[consumed_move.product_id.id] = consumed_move.product_qty
633 else:
634 consumed_info[consumed_move.product_id.id] = consumed_info[consumed_move.product_id.id] + consumed_move.product_qty
635 reallocated_picking_id = picking_obj.copy(cr, uid, production.picking_id.id, context=context)
636 ctx = context.copy()
637 ctx['returned_picking'] = True
638 for move in picking_obj.browse(cr, uid, reallocated_picking_id, context=context).move_lines:
639 move_obj.write(cr, uid, move.id, {
640 'type': 'internal',
641 'location_id': move.location_dest_id.id,
642 'location_dest_id': move.location_id.id,
643 'product_qty': move.product_qty - consumed_info.get(move.product_id.id, 0.0)},
644 context=context)
645 move_obj.action_done(cr, uid, [move.id], context=ctx)
646 picking_obj.action_done(cr, uid, reallocated_picking_id, context=context)
647 return reallocated_picking_id
648
618649
619 def action_cancel(self, cr, uid, ids, context=None):650 def action_cancel(self, cr, uid, ids, context=None):
620 """ Cancels the production order and related stock moves.651 """ Cancels the production order and related stock moves.
@@ -628,6 +659,10 @@
628 raise osv.except_osv(659 raise osv.except_osv(
629 _('Could not cancel manufacturing order !'),660 _('Could not cancel manufacturing order !'),
630 _('You must first cancel related internal picking attached to this manufacturing order.'))661 _('You must first cancel related internal picking attached to this manufacturing order.'))
662 if production.state in ('ready', 'in_production'):
663 reallocated_picking_id = self._reallocate_picking(cr, uid, production, context=context)
664 self.write(cr, uid, production.id, {'picking_id': reallocated_picking_id}, context=context)
665
631 if production.move_created_ids:666 if production.move_created_ids:
632 move_obj.action_cancel(cr, uid, [x.id for x in production.move_created_ids])667 move_obj.action_cancel(cr, uid, [x.id for x in production.move_created_ids])
633 move_obj.action_cancel(cr, uid, [x.id for x in production.move_lines])668 move_obj.action_cancel(cr, uid, [x.id for x in production.move_lines])
634669
=== modified file 'stock/stock.py'
--- stock/stock.py 2012-10-05 07:47:57 +0000
+++ stock/stock.py 2012-12-12 08:17:19 +0000
@@ -2199,7 +2199,9 @@
2199 or move.location_id.company_id != move.location_dest_id.company_id):2199 or move.location_id.company_id != move.location_dest_id.company_id):
2200 journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation(cr, uid, move, dest_company_ctx)2200 journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation(cr, uid, move, dest_company_ctx)
2201 reference_amount, reference_currency_id = self._get_reference_accounting_values_for_valuation(cr, uid, move, src_company_ctx)2201 reference_amount, reference_currency_id = self._get_reference_accounting_values_for_valuation(cr, uid, move, src_company_ctx)
2202 account_moves += [(journal_id, self._create_account_move_line(cr, uid, move, acc_src, acc_valuation, reference_amount, reference_currency_id, context))]2202 # cancelled production: use destination instead of source
2203 acc_from = context.get('returned_picking', False) and acc_dest or acc_src
2204 account_moves += [(journal_id, self._create_account_move_line(cr, uid, move, acc_from, acc_valuation, reference_amount, reference_currency_id, context))]
22032205
2204 move_obj = self.pool.get('account.move')2206 move_obj = self.pool.get('account.move')
2205 for j_id, move_lines in account_moves:2207 for j_id, move_lines in account_moves: