Merge lp:~camptocamp/openobject-addons/7.0-bug-1168398-tta+afe into lp:openobject-addons/7.0

Proposed by Alexandre Fayolle - camptocamp
Status: Needs review
Proposed branch: lp:~camptocamp/openobject-addons/7.0-bug-1168398-tta+afe
Merge into: lp:openobject-addons/7.0
Diff against target: 107 lines (+79/-2)
3 files modified
mrp/__openerp__.py (+1/-0)
mrp/mrp.py (+11/-2)
mrp/test/order_process_prodlot_split.yml (+67/-0)
To merge this branch: bzr merge lp:~camptocamp/openobject-addons/7.0-bug-1168398-tta+afe
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+174153@code.launchpad.net
To post a comment you must log in.
9048. By Alexandre Fayolle - camptocamp on 2013-07-11

[IMP] fix typo in test, delete trailing whitespace, add an assertion

9049. By Alexandre Fayolle - camptocamp on 2013-07-11

[MRG] merge back the fix on 7.0 head, and hopefully get green on runbot

Revision history for this message
Joshua Jan(SHINEIT) (joshuajan) wrote :

Hi All,

Thanks for Contribution. I have make some test about this change. I found a problem.
if I Create a MO to make 2 Piece Product-A.
Product-A`s BOM
-- Product-A-M QTY:1

1.I click "split in Serial Numbers" and assign 1 serial number "A-M-001" to Product-A-M, so I get two line in "Products to Consume":
|Product-A-M | 1 | |
|Product-A-M | 1 | A-M-001|

2.I consume and produce 1 Product-A. The line without serial number will be consume. Because there are same qty in "Products to Consume" then system will sort by id.

I suggest change the sort code from
moves = sorted(raw_product, key=lambda k: (k.product_qty))
to
moves = sorted(raw_product, key=lambda k: (k.prodlot_id), reverse=True)
is better.

Best regards
Joshua

Unmerged revisions

9049. By Alexandre Fayolle - camptocamp on 2013-07-11

[MRG] merge back the fix on 7.0 head, and hopefully get green on runbot

9048. By Alexandre Fayolle - camptocamp on 2013-07-11

[IMP] fix typo in test, delete trailing whitespace, add an assertion

9047. By Alexandre Fayolle - camptocamp on 2013-07-11

[TEST] added test for bug lp:1168398

9046. By SnippetBucket.com on 2013-04-22

[FIX] bug:1168398/Incorrect behaviour when producing MO with component split in serial numbers.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'mrp/__openerp__.py'
2--- mrp/__openerp__.py 2013-01-31 18:41:41 +0000
3+++ mrp/__openerp__.py 2013-07-11 11:49:30 +0000
4@@ -80,6 +80,7 @@
5 # 'test/order_demo.yml',
6 # 'test/order_process.yml',
7 # 'test/cancel_order.yml',
8+ 'test/order_process_prodlot_split.yml',
9 ],
10 'installable': True,
11 'application': True,
12
13=== modified file 'mrp/mrp.py'
14--- mrp/mrp.py 2012-12-20 11:47:30 +0000
15+++ mrp/mrp.py 2013-07-11 11:49:30 +0000
16@@ -738,8 +738,17 @@
17 if qty <= 0.0:
18 # we already have more qtys consumed than we need
19 continue
20-
21- raw_product[0].action_consume(qty, raw_product[0].location_id.id, context=context)
22+ splitqty = qty
23+ moves = sorted(raw_product, key=lambda k: (k.product_qty))
24+ for move in moves:
25+ if splitqty <= 0:
26+ break
27+ elif move.product_qty >= qty:
28+ move.action_consume(qty, move.location_id.id, context=context)
29+ splitqty = 0
30+ else:
31+ move.action_consume(splitqty, move.location_id.id, context=context)
32+ splitqty = splitqty - move.product_qty
33
34 if production_mode == 'consume_produce':
35 # To produce remaining qty of final product
36
37=== added file 'mrp/test/order_process_prodlot_split.yml'
38--- mrp/test/order_process_prodlot_split.yml 1970-01-01 00:00:00 +0000
39+++ mrp/test/order_process_prodlot_split.yml 2013-07-11 11:49:30 +0000
40@@ -0,0 +1,67 @@
41+-
42+ I create a MO for 1 PCSC349
43+-
44+ !record {model: mrp.production, id: test_mo_pcsc349}:
45+ product_id: product.product_product_4
46+ product_qty: 1
47+ product_uom: product.product_uom_unit
48+ location_src_id: stock.stock_location_stock
49+ location_dest_id: stock.stock_location_stock
50+ bom_id: mrp_bom_24
51+-
52+ I confirm the MO
53+-
54+ !workflow {model: mrp.production, action: button_confirm, ref: test_mo_pcsc349}
55+-
56+ I split the RAM SR3 in 2 production lots
57+-
58+ !python {model: stock.move.split}: |
59+ order = self.pool.get('mrp.production').browse(cr, uid, ref('test_mo_pcsc349'), context=context)
60+ ram_lines = [line for line in order.move_lines if line.product_id.default_code == 'RAM-SR3']
61+ assert len(ram_lines) == 1, 'no RAM-SR3 lines found'
62+ ctxt = context.copy()
63+ ctxt['active_id'] = ram_lines[0].id
64+ ctxt['active_ids'] = [ram_lines[0].id]
65+ ctxt['active_model'] = 'stock.move'
66+ values = self.default_get(cr, uid,
67+ ['product_id', 'product_uom', 'qty', 'use_exist', 'location_id'],
68+ ctxt)
69+ wizard_id = self.create(cr, uid, values, context=ctxt)
70+ prodlot_obj = self.pool.get('stock.production.lot')
71+ split_line_obj = self.pool.get('stock.move.split.lines')
72+ split_line_obj.create(cr, uid, {'wizard_id': wizard_id,
73+ 'name': 'ram_sn_1',
74+ 'quantity': 1,}, context=ctxt)
75+ split_line_obj.create(cr, uid, {'wizard_id': wizard_id,
76+ 'name': 'ram_sn_2',
77+ 'quantity': 1,}, context=ctxt)
78+ self.split_lot(cr, uid, [wizard_id], context=ctxt)
79+ order.refresh()
80+ ram_lines = [line for line in order.move_lines if line.product_id.default_code == 'RAM-SR3']
81+ assert len(ram_lines) == 2, 'RAM-SR3 line not split'
82+
83+
84+-
85+ I click on the "Produce" button of the Manufacturing Order and in the wizard select "Consume and Produce" mode
86+-
87+ !python {model: mrp.product.produce}: |
88+ ctxt = context.copy()
89+ order = self.pool.get('mrp.production').browse(cr, uid, ref('test_mo_pcsc349'), context=context)
90+ ctxt['active_id'] = order.id
91+ ctxt['active_model'] = 'mrp.production'
92+ wizard_id = self.create(cr, uid,
93+ {'product_qty': 1,
94+ 'mode': 'consume_produce'}, ctxt)
95+ self.do_produce(cr, uid, [wizard_id], ctxt)
96+-
97+ I expect
98+ all the Products in the "Products to consume" lists to be consumed
99+ and moved to the "consumed products" list,
100+ and the manufacturing order to be in state "Done"
101+-
102+ !python {model: mrp.production}: |
103+ order = self.browse(cr, uid, ref('test_mo_pcsc349'), context=context)
104+ assert order.state == 'done', "wrong state for the production order (%r, expected: 'done')" % order.state
105+ assert len(order.move_lines) == 0, "%d leftover move lines in 'products to consume'" % len(order.move_lines)
106+ ram_lines = [line for line in order.move_lines2 if line.product_id.default_code == 'RAM-SR3']
107+ assert len(ram_lines) == 2, 'not all RAM-SR3 were consumed'