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
1=== modified file 'mrp/mrp.py'
2--- mrp/mrp.py 2012-10-05 10:44:47 +0000
3+++ mrp/mrp.py 2012-12-12 08:17:19 +0000
4@@ -615,6 +615,37 @@
5 line['production_id'] = production.id
6 workcenter_line_obj.create(cr, uid, line)
7 return len(results)
8+
9+ def _reallocate_picking(self, cr, uid, production, context=None):
10+ """ Goods remain allocated while cancelling 'ready to produce'
11+ production order. It creates new picking to release the goods
12+ back to stock.
13+ """
14+ if context is None:
15+ context = {}
16+ consumed_info = {}
17+ move_obj = self.pool.get('stock.move')
18+ picking_obj = self.pool.get('stock.picking')
19+ for consumed_move in production.move_lines2:
20+ if consumed_move.state == 'done':
21+ if not consumed_move.product_id.id in consumed_info:
22+ consumed_info[consumed_move.product_id.id] = consumed_move.product_qty
23+ else:
24+ consumed_info[consumed_move.product_id.id] = consumed_info[consumed_move.product_id.id] + consumed_move.product_qty
25+ reallocated_picking_id = picking_obj.copy(cr, uid, production.picking_id.id, context=context)
26+ ctx = context.copy()
27+ ctx['returned_picking'] = True
28+ for move in picking_obj.browse(cr, uid, reallocated_picking_id, context=context).move_lines:
29+ move_obj.write(cr, uid, move.id, {
30+ 'type': 'internal',
31+ 'location_id': move.location_dest_id.id,
32+ 'location_dest_id': move.location_id.id,
33+ 'product_qty': move.product_qty - consumed_info.get(move.product_id.id, 0.0)},
34+ context=context)
35+ move_obj.action_done(cr, uid, [move.id], context=ctx)
36+ picking_obj.action_done(cr, uid, reallocated_picking_id, context=context)
37+ return reallocated_picking_id
38+
39
40 def action_cancel(self, cr, uid, ids, context=None):
41 """ Cancels the production order and related stock moves.
42@@ -628,6 +659,10 @@
43 raise osv.except_osv(
44 _('Could not cancel manufacturing order !'),
45 _('You must first cancel related internal picking attached to this manufacturing order.'))
46+ if production.state in ('ready', 'in_production'):
47+ reallocated_picking_id = self._reallocate_picking(cr, uid, production, context=context)
48+ self.write(cr, uid, production.id, {'picking_id': reallocated_picking_id}, context=context)
49+
50 if production.move_created_ids:
51 move_obj.action_cancel(cr, uid, [x.id for x in production.move_created_ids])
52 move_obj.action_cancel(cr, uid, [x.id for x in production.move_lines])
53
54=== modified file 'stock/stock.py'
55--- stock/stock.py 2012-10-05 07:47:57 +0000
56+++ stock/stock.py 2012-12-12 08:17:19 +0000
57@@ -2199,7 +2199,9 @@
58 or move.location_id.company_id != move.location_dest_id.company_id):
59 journal_id, acc_src, acc_dest, acc_valuation = self._get_accounting_data_for_valuation(cr, uid, move, dest_company_ctx)
60 reference_amount, reference_currency_id = self._get_reference_accounting_values_for_valuation(cr, uid, move, src_company_ctx)
61- account_moves += [(journal_id, self._create_account_move_line(cr, uid, move, acc_src, acc_valuation, reference_amount, reference_currency_id, context))]
62+ # cancelled production: use destination instead of source
63+ acc_from = context.get('returned_picking', False) and acc_dest or acc_src
64+ account_moves += [(journal_id, self._create_account_move_line(cr, uid, move, acc_from, acc_valuation, reference_amount, reference_currency_id, context))]
65
66 move_obj = self.pool.get('account.move')
67 for j_id, move_lines in account_moves: