Merge lp:~camptocamp/openerp-manufacturing/6.1-add-mrp_split_units-lep into lp:openerp-manufacturing/6.1

Proposed by Leonardo Pistone
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 10
Merged at revision: 8
Proposed branch: lp:~camptocamp/openerp-manufacturing/6.1-add-mrp_split_units-lep
Merge into: lp:openerp-manufacturing/6.1
Diff against target: 204 lines (+183/-0)
4 files modified
mrp_split_units/__init__.py (+22/-0)
mrp_split_units/__openerp__.py (+46/-0)
mrp_split_units/mrp_view.xml (+21/-0)
mrp_split_units/stock.py (+94/-0)
To merge this branch: bzr merge lp:~camptocamp/openerp-manufacturing/6.1-add-mrp_split_units-lep
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no tests Approve
Romain Deheele - Camptocamp (community) code review, no test Approve
Review via email: mp+200544@code.launchpad.net

Description of the change

New module mrp_split_units. Thanks!

To post a comment you must log in.
Revision history for this message
Leonardo Pistone (lepistone) wrote :

flake8 says OK. Thanks for reviewing!

Revision history for this message
Romain Deheele - Camptocamp (romaindeheele) wrote :

Hi,

LGTM,

Romain

review: Approve (code review, no test)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

l95 and l98 you can use relative xpath expr like

<xpath expr="//field[@name='move_created_ids']/tree/button[@string='Scrap Products']" position="after">

That way adding a html level or moving the field won't affect your changes.

Otherwise looks good to me.

review: Needs Fixing (code review, no tests)
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Yannick,

I changed as you suggest.

Thanks

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks for the changes.

Sorry, it seems I missed those in python code the first time:

l138 could you use orm.Model instead of osv.osv

l174 missing context propagation

review: Needs Fixing (code review, no tests)
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks Yannick, fixed

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Thanks

LGTM

review: Approve (code review, no tests)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

in mrp_split_units/__openerp__.py please use data keyword instead of deprecated
init_xml
update_xml
demo_xml

review: Needs Fixing (code review, no tests)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

Yes, I know I'm a turncoat sorry for that

Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

6.1 here not needed

review: Approve (code review, no tests)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'mrp_split_units'
2=== added file 'mrp_split_units/__init__.py'
3--- mrp_split_units/__init__.py 1970-01-01 00:00:00 +0000
4+++ mrp_split_units/__init__.py 2014-01-15 09:07:47 +0000
5@@ -0,0 +1,22 @@
6+# -*- coding: utf-8 -*-
7+###############################################################################
8+# #
9+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
10+# Copyright 2014 Camptocamp SA #
11+# #
12+# This program is free software: you can redistribute it and/or modify #
13+# it under the terms of the GNU Affero General Public License as #
14+# published by the Free Software Foundation, either version 3 of the #
15+# License, or (at your option) any later version. #
16+# #
17+# This program is distributed in the hope that it will be useful, #
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
20+# GNU Affero General Public License for more details. #
21+# #
22+# You should have received a copy of the GNU Affero General Public License #
23+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
24+# #
25+###############################################################################
26+
27+from . import stock # noqa
28
29=== added file 'mrp_split_units/__openerp__.py'
30--- mrp_split_units/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ mrp_split_units/__openerp__.py 2014-01-15 09:07:47 +0000
32@@ -0,0 +1,46 @@
33+# -*- coding: utf-8 -*-
34+###############################################################################
35+# #
36+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
37+# Copyright 2014 Camptocamp SA #
38+# #
39+# This program is free software: you can redistribute it and/or modify #
40+# it under the terms of the GNU Affero General Public License as #
41+# published by the Free Software Foundation, either version 3 of the #
42+# License, or (at your option) any later version. #
43+# #
44+# This program is distributed in the hope that it will be useful, #
45+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
46+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
47+# GNU Affero General Public License for more details. #
48+# #
49+# You should have received a copy of the GNU Affero General Public License #
50+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
51+# #
52+###############################################################################
53+
54+{
55+ 'name': 'MRP Split Units',
56+ 'version': '0.1',
57+ 'category': 'Generic Modules/Others',
58+ 'license': 'AGPL-3',
59+ 'description': """
60+MRP Split one line into many lines with quantity one each
61+in a production order.
62+
63+This module adds a button in each line of the Products to Finish and Finished
64+Products to automatically split one line with integer quantity into many lines,
65+each with quantity 1. After the split, the module performs a
66+"poor man's refresh" (i.e. manually reloads the page) as a workaround for the
67+bug lp:1083253.
68+""",
69+ 'complexity': 'easy',
70+ 'author': 'Camptocamp',
71+ 'website': 'http://www.camptocamp.com/',
72+ 'depends': ['mrp'],
73+ 'init_xml': [],
74+ 'update_xml': ['mrp_view.xml'],
75+ 'demo_xml': [],
76+ 'installable': True,
77+ 'active': False,
78+}
79
80=== added directory 'mrp_split_units/i18n'
81=== added file 'mrp_split_units/mrp_view.xml'
82--- mrp_split_units/mrp_view.xml 1970-01-01 00:00:00 +0000
83+++ mrp_split_units/mrp_view.xml 2014-01-15 09:07:47 +0000
84@@ -0,0 +1,21 @@
85+<?xml version="1.0" encoding="utf-8"?>
86+<openerp>
87+ <data>
88+
89+ <record id="mrp_production_form_lot_attribute_view" model="ir.ui.view">
90+ <field name="name">mrp.production.lot.attribute.form</field>
91+ <field name="model">mrp.production</field>
92+ <field name="inherit_id" ref="mrp.mrp_production_form_view"/>
93+ <field name="type">form</field>
94+ <field name="arch" type="xml">
95+ <xpath expr="//field[@name='move_created_ids']/tree/button[@string='Scrap Products']" position="after">
96+ <button name="split_units_to_finish" string="Split Units" type="object" icon="gtk-jump-to"/>
97+ </xpath>
98+ <xpath expr="//field[@name='move_created_ids2']/tree/button[@string='Scrap Products']" position="after">
99+ <button name="split_units_finished" string="Split Units" type="object" icon="gtk-jump-to"/>
100+ </xpath>
101+ </field>
102+ </record>
103+
104+ </data>
105+</openerp>
106
107=== added file 'mrp_split_units/stock.py'
108--- mrp_split_units/stock.py 1970-01-01 00:00:00 +0000
109+++ mrp_split_units/stock.py 2014-01-15 09:07:47 +0000
110@@ -0,0 +1,94 @@
111+# -*- coding: utf-8 -*-
112+"""Add to the stock move the methods to split MO lines."""
113+###############################################################################
114+# #
115+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
116+# Copyright 2014 Camptocamp SA #
117+# #
118+# This program is free software: you can redistribute it and/or modify #
119+# it under the terms of the GNU Affero General Public License as #
120+# published by the Free Software Foundation, either version 3 of the #
121+# License, or (at your option) any later version. #
122+# #
123+# This program is distributed in the hope that it will be useful, #
124+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
125+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
126+# GNU Affero General Public License for more details. #
127+# #
128+# You should have received a copy of the GNU Affero General Public License #
129+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
130+# #
131+###############################################################################
132+
133+from osv import orm
134+from tools.translate import _
135+import decimal_precision as dp
136+
137+
138+class stock_move(orm.Model):
139+
140+ """Stock move. Add methods to split moves in manufacturing orders."""
141+
142+ _inherit = 'stock.move'
143+
144+ def split_units(self, cr, uid, ids, context=None):
145+ """Split the current move creating moves with quantity one.
146+
147+ Return an action to reload the current record as a poor man's refresh.
148+
149+ """
150+
151+ def almost_integer(cr, qty, int_qty):
152+ return (
153+ qty - int_qty < 10 ** -dp.get_precision('Product UoM')(cr)[1]
154+ )
155+
156+ for move in self.browse(cr, uid, ids, context=context):
157+ int_qty = int(move.product_qty)
158+
159+ if not almost_integer(cr, move.product_qty, int_qty):
160+ raise orm.except_osv(
161+ _('Error'),
162+ _('Quantity needs to be integer.')
163+ )
164+
165+ if int_qty <= 1:
166+ raise orm.except_osv(
167+ _('Error'),
168+ _('Quantity needs to be more than 1.')
169+ )
170+
171+ self.write(cr, uid, move.id, {
172+ 'product_qty': 1.0,
173+ 'product_uos_qty': 1.0,
174+ }, context=context)
175+
176+ default_val = {
177+ 'product_qty': 1.0,
178+ 'product_uos_qty': 1.0,
179+ 'state': move.state,
180+ 'prodlot_id': False,
181+ }
182+
183+ #create the new moves
184+ for i in xrange(int_qty - 1):
185+ self.copy(cr, uid, move.id, default_val, context=context)
186+
187+ # poor man's refresh
188+ return {
189+ 'view_type': 'form',
190+ 'view_mode': 'form',
191+ 'res_model': 'mrp.production',
192+ 'type': 'ir.actions.act_window',
193+ 'target': 'current',
194+ 'context': context,
195+ 'res_id': move.production_id.id,
196+ }
197+
198+ def split_units_finished(self, cr, uid, ids, context=None):
199+ """Split a line in the Finished Products. Return an action."""
200+ return self.split_units(cr, uid, ids, context=context)
201+
202+ def split_units_to_finish(self, cr, uid, ids, context=None):
203+ """Split a line in the Products to Finish. Return an action."""
204+ return self.split_units(cr, uid, ids, context=context)

Subscribers

People subscribed via source and target branches