Merge lp:~camptocamp/stock-logistic-flows/6.1-add-mrp_open_lot_attributes-lep into lp:stock-logistic-flows/6.1

Proposed by Leonardo Pistone
Status: Merged
Approved by: Yannick Vaucher @ Camptocamp
Approved revision: 35
Merged at revision: 28
Proposed branch: lp:~camptocamp/stock-logistic-flows/6.1-add-mrp_open_lot_attributes-lep
Merge into: lp:stock-logistic-flows/6.1
Diff against target: 396 lines (+365/-0)
6 files modified
mrp_open_lot_attributes/__init__.py (+22/-0)
mrp_open_lot_attributes/__openerp__.py (+40/-0)
mrp_open_lot_attributes/i18n/fr_FR.po (+71/-0)
mrp_open_lot_attributes/i18n/mrp_open_lot_attributes.pot (+70/-0)
mrp_open_lot_attributes/mrp_view.xml (+22/-0)
mrp_open_lot_attributes/stock.py (+140/-0)
To merge this branch: bzr merge lp:~camptocamp/stock-logistic-flows/6.1-add-mrp_open_lot_attributes-lep
Reviewer Review Type Date Requested Status
Yannick Vaucher @ Camptocamp code review, no tests Approve
camptocamp-business-robot (community) no test, code review Needs Fixing
Sandy Carter (http://www.savoirfairelinux.com) code review, no test Approve
Review via email: mp+196749@code.launchpad.net

Description of the change

This new module allows to edit the Custom Attributes in the production lot from the Manufacturing Order.

To post a comment you must log in.
31. By Leonardo Pistone

[add] button to open production lot detail also in the finished products to produce

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

l.213 spelling mistake Dinamically -> Dynamically
__openerp__.py is a dictionary, use pep8 style: 4 space indentation and move 'name' to its own line
l.126-137 Would be nicer if these were imported from openerp: openerp.osv, openerp.tools.translate

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

1. fixed

2. Asked the community list

3. 6.1 style, I think

Thanks!

32. By Leonardo Pistone

[fix] typo

Revision history for this message
Sandy Carter (http://www.savoirfairelinux.com) (sandy-carter) wrote :

LGTM, as I said in another MP, 2 and 3 are not a reason to block the MP.

review: Approve (code review, no test)
Revision history for this message
camptocamp-business-robot (camptocamp-business-robot) wrote :

Please use:
from openerp.osv import orm, fields

and instanciate the classes with:
class x_y_z(orm.Model):
class a_b_c(orm.TransientModel):

The other form is deprecated.

In osv.py:
"
# deprecated - for backward compatibility.
osv = Model
osv_memory = TransientModel
osv_abstract = AbstractModel # ;-)
"

I'm not found of the extends fields_view_get approach but in this case it is probably less code to maintain than redefining views or doing a function field to be used by attrs so it is OK for me.

Opinion:
Adding sub function in open_lot will make it more readable and easier to override.

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

Thanks for your review.

Do you think that is deprecated also for old-fashioned 6.1?

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

@Leonardo

Yes it is already deprecated in old-fashioned 6.1 :)

http://bazaar.launchpad.net/~openerp/openobject-server/6.1/view/head:/openerp/osv/osv.py#L224

33. By Leonardo Pistone

[imp] new-style models

Revision history for this message
Leonardo Pistone (lepistone) wrote :

Thanks Yannick, Nicolas, Sandy,

all should be cool and modern now.

34. By Leonardo Pistone

[add] i18n

35. By Leonardo Pistone

[ref] pep8

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

Thanks for the changes

LGTM

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_open_lot_attributes'
2=== added file 'mrp_open_lot_attributes/__init__.py'
3--- mrp_open_lot_attributes/__init__.py 1970-01-01 00:00:00 +0000
4+++ mrp_open_lot_attributes/__init__.py 2013-12-17 10:19:04 +0000
5@@ -0,0 +1,22 @@
6+# -*- coding: utf-8 -*-
7+###############################################################################
8+# #
9+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
10+# Copyright 2013 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
28
29=== added file 'mrp_open_lot_attributes/__openerp__.py'
30--- mrp_open_lot_attributes/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ mrp_open_lot_attributes/__openerp__.py 2013-12-17 10:19:04 +0000
32@@ -0,0 +1,40 @@
33+# -*- coding: utf-8 -*-
34+###############################################################################
35+# #
36+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
37+# Copyright 2013 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+{'name': 'MRP Open Lot Attributes',
55+ 'version': '0.1',
56+ 'category': 'Generic Modules/Others',
57+ 'license': 'AGPL-3',
58+ 'description': """
59+This module adds buttons to edit the Production Lot information, including
60+custom attributes, from the Finished Products tab in the Manufacturing Order.
61+
62+""",
63+ 'complexity': 'easy',
64+ 'author': 'Camptocamp',
65+ 'website': 'http://www.camptocamp.com/',
66+ 'depends': ['mrp', 'production_lot_custom_attributes'],
67+ 'init_xml': [],
68+ 'update_xml': ['mrp_view.xml'],
69+ 'demo_xml': [],
70+ 'installable': True,
71+ 'active': False,
72+ }
73
74=== added directory 'mrp_open_lot_attributes/i18n'
75=== added file 'mrp_open_lot_attributes/i18n/fr_FR.po'
76--- mrp_open_lot_attributes/i18n/fr_FR.po 1970-01-01 00:00:00 +0000
77+++ mrp_open_lot_attributes/i18n/fr_FR.po 2013-12-17 10:19:04 +0000
78@@ -0,0 +1,71 @@
79+# Translation of OpenERP Server.
80+# This file contains the translation of the following modules:
81+# * mrp_open_lot_attributes
82+#
83+msgid ""
84+msgstr ""
85+"Project-Id-Version: OpenERP Server 6.1\n"
86+"Report-Msgid-Bugs-To: \n"
87+"POT-Creation-Date: 2013-12-16 15:40+0000\n"
88+"PO-Revision-Date: 2013-12-16 15:40+0000\n"
89+"Last-Translator: <>\n"
90+"Language-Team: \n"
91+"MIME-Version: 1.0\n"
92+"Content-Type: text/plain; charset=UTF-8\n"
93+"Content-Transfer-Encoding: \n"
94+"Plural-Forms: \n"
95+
96+#. module: mrp_open_lot_attributes
97+#: model:ir.model,name:mrp_open_lot_attributes.model_stock_production_lot
98+msgid "Production lot"
99+msgstr "Lot de production"
100+
101+#. module: mrp_open_lot_attributes
102+#: view:mrp.production:0
103+msgid "Open Lot"
104+msgstr "Open Lot"
105+
106+#. module: mrp_open_lot_attributes
107+#: model:ir.model,name:mrp_open_lot_attributes.model_stock_move
108+msgid "Stock Move"
109+msgstr "Mouvement de stock"
110+
111+#. module: mrp_open_lot_attributes
112+#: constraint:stock.move:0
113+msgid "You try to assign a lot which is not from the same product"
114+msgstr "Vous essayez d'affecter un lot qui n'est pas pour ce produit."
115+
116+#. module: mrp_open_lot_attributes
117+#: constraint:stock.move:0
118+msgid "You can not move products from or to a location of the type view."
119+msgstr "You can not move products from or to a location of the type view."
120+
121+#. module: mrp_open_lot_attributes
122+#: constraint:stock.move:0
123+msgid "You must assign a production lot for this product"
124+msgstr "Vous devez affecter un lot de fabrication pour ce produit."
125+
126+#. module: mrp_open_lot_attributes
127+#: code:addons/mrp_open_lot_attributes/stock.py:63
128+#: code:addons/mrp_open_lot_attributes/stock.py:80
129+#, python-format
130+msgid "Production Lots"
131+msgstr "Production Lots"
132+
133+#. module: mrp_open_lot_attributes
134+#: code:addons/mrp_open_lot_attributes/stock.py:135
135+#, python-format
136+msgid "Save and Close"
137+msgstr "Save and Close"
138+
139+#. module: mrp_open_lot_attributes
140+#: code:addons/mrp_open_lot_attributes/stock.py:127
141+#, python-format
142+msgid "Cancel"
143+msgstr "Cancel"
144+
145+#. module: mrp_open_lot_attributes
146+#: sql_constraint:stock.production.lot:0
147+msgid "The combination of serial number and internal reference must be unique !"
148+msgstr "La combinaison du numéro de série et de la référence interne doit être unique !"
149+
150
151=== added file 'mrp_open_lot_attributes/i18n/mrp_open_lot_attributes.pot'
152--- mrp_open_lot_attributes/i18n/mrp_open_lot_attributes.pot 1970-01-01 00:00:00 +0000
153+++ mrp_open_lot_attributes/i18n/mrp_open_lot_attributes.pot 2013-12-17 10:19:04 +0000
154@@ -0,0 +1,70 @@
155+# Translation of OpenERP Server.
156+# This file contains the translation of the following modules:
157+# * mrp_open_lot_attributes
158+#
159+msgid ""
160+msgstr ""
161+"Project-Id-Version: OpenERP Server 6.1\n"
162+"Report-Msgid-Bugs-To: \n"
163+"POT-Creation-Date: 2013-12-16 14:56+0000\n"
164+"PO-Revision-Date: 2013-12-16 14:56+0000\n"
165+"Last-Translator: <>\n"
166+"Language-Team: \n"
167+"MIME-Version: 1.0\n"
168+"Content-Type: text/plain; charset=UTF-8\n"
169+"Content-Transfer-Encoding: \n"
170+"Plural-Forms: \n"
171+
172+#. module: mrp_open_lot_attributes
173+#: model:ir.model,name:mrp_open_lot_attributes.model_stock_production_lot
174+msgid "Production lot"
175+msgstr ""
176+
177+#. module: mrp_open_lot_attributes
178+#: view:mrp.production:0
179+msgid "Open Lot"
180+msgstr ""
181+
182+#. module: mrp_open_lot_attributes
183+#: model:ir.model,name:mrp_open_lot_attributes.model_stock_move
184+msgid "Stock Move"
185+msgstr ""
186+
187+#. module: mrp_open_lot_attributes
188+#: constraint:stock.move:0
189+msgid "You try to assign a lot which is not from the same product"
190+msgstr ""
191+
192+#. module: mrp_open_lot_attributes
193+#: constraint:stock.move:0
194+msgid "You can not move products from or to a location of the type view."
195+msgstr ""
196+
197+#. module: mrp_open_lot_attributes
198+#: constraint:stock.move:0
199+msgid "You must assign a production lot for this product"
200+msgstr ""
201+
202+#. module: mrp_open_lot_attributes
203+#: code:addons/mrp_open_lot_attributes/stock.py:63
204+#: code:addons/mrp_open_lot_attributes/stock.py:80
205+#, python-format
206+msgid "Production Lots"
207+msgstr ""
208+
209+#. module: mrp_open_lot_attributes
210+#: code:addons/mrp_open_lot_attributes/stock.py:135
211+#, python-format
212+msgid "Save and Close"
213+msgstr ""
214+
215+#. module: mrp_open_lot_attributes
216+#: code:addons/mrp_open_lot_attributes/stock.py:127
217+#, python-format
218+msgid "Cancel"
219+msgstr ""
220+
221+#. module: mrp_open_lot_attributes
222+#: sql_constraint:stock.production.lot:0
223+msgid "The combination of serial number and internal reference must be unique !"
224+msgstr ""
225
226=== added file 'mrp_open_lot_attributes/mrp_view.xml'
227--- mrp_open_lot_attributes/mrp_view.xml 1970-01-01 00:00:00 +0000
228+++ mrp_open_lot_attributes/mrp_view.xml 2013-12-17 10:19:04 +0000
229@@ -0,0 +1,22 @@
230+<?xml version="1.0" encoding="utf-8"?>
231+<openerp>
232+ <data>
233+
234+ <record id="mrp_production_form_lot_attribute_view" model="ir.ui.view">
235+ <field name="name">mrp.production.lot.attribute.form</field>
236+ <field name="model">mrp.production</field>
237+ <field name="inherit_id" ref="mrp.mrp_production_form_view"/>
238+ <field name="type">form</field>
239+ <field name="arch" type="xml">
240+ <xpath expr="/form/notebook/page[@string='Finished Products']/field[@name='move_created_ids']/tree/button[@string='Scrap Products']" position="after">
241+ <field name="prodlot_id"/>
242+ <button name="open_lot" string="Open Lot" type="object" icon="gtk-justify-fill"/>
243+ </xpath>
244+ <xpath expr="/form/notebook/page[@string='Finished Products']/field[@name='move_created_ids2']/tree/button[@string='Scrap Products']" position="after">
245+ <button name="open_lot" string="Open Lot" type="object" icon="gtk-justify-fill"/>
246+ </xpath>
247+ </field>
248+ </record>
249+
250+ </data>
251+</openerp>
252
253=== added file 'mrp_open_lot_attributes/stock.py'
254--- mrp_open_lot_attributes/stock.py 1970-01-01 00:00:00 +0000
255+++ mrp_open_lot_attributes/stock.py 2013-12-17 10:19:04 +0000
256@@ -0,0 +1,140 @@
257+# -*- coding: utf-8 -*-
258+###############################################################################
259+# #
260+# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> #
261+# Copyright 2013 Camptocamp SA #
262+# #
263+# This program is free software: you can redistribute it and/or modify #
264+# it under the terms of the GNU Affero General Public License as #
265+# published by the Free Software Foundation, either version 3 of the #
266+# License, or (at your option) any later version. #
267+# #
268+# This program is distributed in the hope that it will be useful, #
269+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
270+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
271+# GNU Affero General Public License for more details. #
272+# #
273+# You should have received a copy of the GNU Affero General Public License #
274+# along with this program. If not, see <http://www.gnu.org/licenses/>. #
275+# #
276+###############################################################################
277+
278+from openerp.osv import orm
279+from tools.translate import _
280+from lxml import etree
281+
282+
283+class stock_move(orm.Model):
284+ _inherit = 'stock.move'
285+
286+ def open_lot(self, cr, uid, ids, context=None):
287+ """Open Production Lot in a form, with attributes if any
288+
289+ If the production lot has custom attributes, these are shown in a
290+ dynamic view
291+
292+ """
293+
294+ if context is None:
295+ context = {}
296+ for move in self.browse(cr, uid, ids, context=context):
297+ # existing lot
298+ if move.prodlot_id:
299+ ctx = {'add_save_close': True}
300+ domain = []
301+
302+ if move.prodlot_id.attribute_set_id:
303+ ctx['open_lot_by_attribute_set'] = True,
304+ ctx['attribute_group_ids'] = [
305+ group.id
306+ for group in
307+ move.prodlot_id.attribute_set_id.attribute_group_ids
308+ ]
309+
310+ domain = (
311+ "[('attribute_set_id', '=', %s)]"
312+ % move.prodlot_id.attribute_set_id.id
313+ )
314+
315+ return {
316+ 'context': ctx,
317+ 'domain': domain,
318+ 'res_id': move.prodlot_id.id,
319+ 'name': _('Production Lots'),
320+ 'view_type': 'form',
321+ 'view_mode': 'form',
322+ 'res_model': 'stock.production.lot',
323+ 'type': 'ir.actions.act_window',
324+ 'target': 'new',
325+ }
326+
327+ # new lot
328+ else:
329+ ctx = {
330+ 'add_save_close': True,
331+ 'default_product_id': move.product_id.id,
332+ }
333+
334+ return {
335+ 'context': ctx,
336+ 'name': _('Production Lots'),
337+ 'view_type': 'form',
338+ 'view_mode': 'form',
339+ 'res_model': 'stock.production.lot',
340+ 'type': 'ir.actions.act_window',
341+ 'target': 'new',
342+ }
343+
344+
345+class stock_production_lot(orm.Model):
346+ _inherit = 'stock.production.lot'
347+
348+ def save_lot(self, cr, uid, ids, context=None):
349+ """If the lot is new, assign it to the original move"""
350+
351+ assert len(ids) == 1
352+ if context['active_model'] == 'stock.move':
353+ move_pool = self.pool.get('stock.move')
354+ move = move_pool.browse(
355+ cr, uid, context['active_id'], context=context
356+ )
357+ if not move.prodlot_id:
358+ move_pool.write(cr, uid, [move.id], {
359+ 'prodlot_id': ids[0],
360+ })
361+ return {'type': 'ir.actions.act_window_close'}
362+
363+ def fields_view_get(self, cr, uid, view_id=None, view_type='form',
364+ context=None, toolbar=False, submenu=False):
365+ """Dynamically adds Save and close, Cancel buttons to the form view
366+
367+ """
368+
369+ if context is None:
370+ context = {}
371+
372+ result = super(stock_production_lot, self).fields_view_get(
373+ cr, uid, view_id, view_type, context, toolbar=toolbar,
374+ submenu=submenu
375+ )
376+ if view_type == 'form' and context.get('add_save_close'):
377+ eview = etree.fromstring(result['arch'])
378+ etree.SubElement(
379+ eview,
380+ 'button',
381+ icon="gtk-cancel",
382+ special="cancel",
383+ string=_('Cancel'),
384+ colspan="2",
385+ )
386+ etree.SubElement(
387+ eview,
388+ 'button',
389+ icon="gtk-ok",
390+ name="save_lot",
391+ string=_('Save and Close'),
392+ type="object",
393+ colspan="2",
394+ )
395+ result['arch'] = etree.tostring(eview, pretty_print=True)
396+ return result

Subscribers

People subscribed via source and target branches