Merge lp:~camptocamp/openerp-product-attributes/7.0-adding-stock_production_lot_custom_attributes-lep into lp:~product-core-editors/openerp-product-attributes/7.0
- 7.0-adding-stock_production_lot_custom_attributes-lep
- Merge into 7.0
Proposed by
Leonardo Pistone
Status: | Merged |
---|---|
Merged at revision: | 230 |
Proposed branch: | lp:~camptocamp/openerp-product-attributes/7.0-adding-stock_production_lot_custom_attributes-lep |
Merge into: | lp:~product-core-editors/openerp-product-attributes/7.0 |
Diff against target: |
549 lines (+502/-0) 9 files modified
production_lot_custom_attributes/__init__.py (+25/-0) production_lot_custom_attributes/__openerp__.py (+56/-0) production_lot_custom_attributes/custom_attributes_view.xml (+58/-0) production_lot_custom_attributes/lot.py (+133/-0) production_lot_custom_attributes/lot_view.xml (+49/-0) production_lot_custom_attributes/test/lot_attribute_test.yml (+48/-0) production_lot_custom_attributes/wizard/__init__.py (+25/-0) production_lot_custom_attributes/wizard/open_lot_by_attribute_set.py (+67/-0) production_lot_custom_attributes/wizard/open_lot_by_attribute_set.xml (+41/-0) |
To merge this branch: | bzr merge lp:~camptocamp/openerp-product-attributes/7.0-adding-stock_production_lot_custom_attributes-lep |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Joël Grand-Guillaume @ camptocamp | code review, no tests | Approve | |
Yannick Vaucher @ Camptocamp | code review, no tests | Needs Fixing | |
Guewen Baconnier @ Camptocamp | code review | Approve | |
Review via email: mp+195950@code.launchpad.net |
Commit message
Description of the change
This is to add custom magento-style attributes on serial numbers (stock.
To post a comment you must log in.
Revision history for this message
Nicolas Bessi - Camptocamp (nbessi-c2c-deactivatedaccount) wrote : | # |
Revision history for this message
Leonardo Pistone (lepistone) wrote : | # |
Thanks for the review Nicolas.
The bug seems to not exist in 7.0, removed the workaround.
Refactored the code to get read of the read()'s and improved the readability
Added doctrings and comments.
L
lp:~camptocamp/openerp-product-attributes/7.0-adding-stock_production_lot_custom_attributes-lep
updated
- 230. By Leonardo Pistone
-
[fix] typo lenght -> length, yaml test now passes
Revision history for this message
Guewen Baconnier @ Camptocamp (gbaconnier-c2c) wrote : | # |
Great module!
LGTM
review:
Approve
(code review)
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote : | # |
production_
Otherwise LGTM
Thanks!
review:
Needs Fixing
(code review, no tests)
lp:~camptocamp/openerp-product-attributes/7.0-adding-stock_production_lot_custom_attributes-lep
updated
- 231. By Leonardo Pistone
-
[imp] manifest: data
Revision history for this message
Leonardo Pistone (lepistone) wrote : | # |
Fixed, thanks
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote : | # |
Hi,
Thanks for the contribs and including a little test case in there, very much appreciated ! LGTM
Regards,
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 'production_lot_custom_attributes' |
2 | === added file 'production_lot_custom_attributes/__init__.py' |
3 | --- production_lot_custom_attributes/__init__.py 1970-01-01 00:00:00 +0000 |
4 | +++ production_lot_custom_attributes/__init__.py 2014-01-16 10:33:08 +0000 |
5 | @@ -0,0 +1,25 @@ |
6 | +# -*- coding: utf-8 -*- |
7 | +############################################################################### |
8 | +# # |
9 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
10 | +# Copyright 2013 Camptocamp SA # |
11 | +# # |
12 | +# Inspired by the module product_custom_attributes # |
13 | +# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # |
14 | +# # |
15 | +# This program is free software: you can redistribute it and/or modify # |
16 | +# it under the terms of the GNU Affero General Public License as # |
17 | +# published by the Free Software Foundation, either version 3 of the # |
18 | +# License, or (at your option) any later version. # |
19 | +# # |
20 | +# This program is distributed in the hope that it will be useful, # |
21 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
22 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
23 | +# GNU Affero General Public License for more details. # |
24 | +# # |
25 | +# You should have received a copy of the GNU Affero General Public License # |
26 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
27 | +# # |
28 | +############################################################################### |
29 | +from . import lot |
30 | +from . import wizard |
31 | |
32 | === added file 'production_lot_custom_attributes/__openerp__.py' |
33 | --- production_lot_custom_attributes/__openerp__.py 1970-01-01 00:00:00 +0000 |
34 | +++ production_lot_custom_attributes/__openerp__.py 2014-01-16 10:33:08 +0000 |
35 | @@ -0,0 +1,56 @@ |
36 | +# -*- coding: utf-8 -*- |
37 | +############################################################################### |
38 | +# # |
39 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
40 | +# Copyright 2013 Camptocamp SA # |
41 | +# # |
42 | +# Inspired by the module product_custom_attributes # |
43 | +# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # |
44 | +# # |
45 | +# This program is free software: you can redistribute it and/or modify # |
46 | +# it under the terms of the GNU Affero General Public License as # |
47 | +# published by the Free Software Foundation, either version 3 of the # |
48 | +# License, or (at your option) any later version. # |
49 | +# # |
50 | +# This program is distributed in the hope that it will be useful, # |
51 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
52 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
53 | +# GNU Affero General Public License for more details. # |
54 | +# # |
55 | +# You should have received a copy of the GNU Affero General Public License # |
56 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
57 | +# # |
58 | +############################################################################### |
59 | + |
60 | +{'name': 'production_lot_custom_attributes', |
61 | + 'version': '0.1', |
62 | + 'category': 'Generic Modules/Others', |
63 | + 'license': 'AGPL-3', |
64 | + 'description': """ |
65 | +Production lot custom attributes |
66 | +================================ |
67 | + |
68 | +This module adds the possibility to easily create custom fields on stock |
69 | +production lots. Each lot can be linked to an attribute set. |
70 | +Each attribute has custom fields (for example, you don't need the same field |
71 | +for a fridge and a camera). |
72 | +In particular it's used by the Magento Magentoerpconnect module to match the |
73 | +EAV flexibility of Magento. |
74 | +This module is inspired by the module product_custom_attributes by |
75 | +Benoît GUILLOT, Akretion |
76 | + |
77 | + """, |
78 | + 'complexity': 'normal', |
79 | + 'author': 'Camptocamp', |
80 | + 'website': 'http://www.camptocamp.com/', |
81 | + 'depends': ['stock', 'base_custom_attributes'], |
82 | + 'data': ['lot_view.xml', |
83 | + 'custom_attributes_view.xml', |
84 | + 'wizard/open_lot_by_attribute_set.xml' |
85 | + ], |
86 | + 'test': [ |
87 | + 'test/lot_attribute_test.yml', |
88 | + ], |
89 | + 'installable': True, |
90 | + 'active': False, |
91 | + } |
92 | |
93 | === added file 'production_lot_custom_attributes/custom_attributes_view.xml' |
94 | --- production_lot_custom_attributes/custom_attributes_view.xml 1970-01-01 00:00:00 +0000 |
95 | +++ production_lot_custom_attributes/custom_attributes_view.xml 2014-01-16 10:33:08 +0000 |
96 | @@ -0,0 +1,58 @@ |
97 | +<?xml version="1.0" encoding="utf-8"?> |
98 | +<openerp> |
99 | + <data> |
100 | + |
101 | + <menuitem |
102 | + id="menu_lot_attribute_in_warehouse_config" |
103 | + name="Serial Number Attributes" |
104 | + parent="stock.menu_warehouse_config" |
105 | + sequence="20"/> |
106 | + |
107 | + <record id="lot_attribute_set_form_action" model="ir.actions.act_window"> |
108 | + <field name="name">Lot Attribute Sets</field> |
109 | + <field name="res_model">attribute.set</field> |
110 | + <field name="view_type">form</field> |
111 | + <field name="view_mode">tree,form</field> |
112 | + <field name="search_view_id" ref="base_custom_attributes.view_attribute_set_search"/> |
113 | + <field name="context">{"force_model": 'stock.production.lot'}</field> |
114 | + <field name="help"></field> |
115 | + </record> |
116 | + |
117 | + <record id="lot_attribute_group_form_action" model="ir.actions.act_window"> |
118 | + <field name="name">Attribute Groups</field> |
119 | + <field name="res_model">attribute.group</field> |
120 | + <field name="view_type">form</field> |
121 | + <field name="view_mode">tree,form</field> |
122 | + <field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/> |
123 | + <field name="context">{"force_model": 'stock.production.lot'}</field> |
124 | + <field name="help"></field> |
125 | + </record> |
126 | + |
127 | + <record id="lot_attribute_attribute_form_action" model="ir.actions.act_window"> |
128 | + <field name="name">Lot Attributes</field> |
129 | + <field name="res_model">attribute.attribute</field> |
130 | + <field name="view_type">form</field> |
131 | + <field name="view_mode">tree,form</field> |
132 | + <field name="search_view_id" ref="base_custom_attributes.view_attribute_attribute_search"/> |
133 | + <field name="context">{"force_model": 'stock.production.lot'}</field> |
134 | + <field name="help"></field> |
135 | + </record> |
136 | + |
137 | + <menuitem |
138 | + action="lot_attribute_set_form_action" |
139 | + id="menu_lot_attribute_set_action" |
140 | + parent="menu_lot_attribute_in_warehouse_config" |
141 | + sequence="1"/> |
142 | + <menuitem |
143 | + action="lot_attribute_group_form_action" |
144 | + id="menu_lot_attribute_group_action" |
145 | + parent="menu_lot_attribute_in_warehouse_config" |
146 | + sequence="2"/> |
147 | + <menuitem |
148 | + action="lot_attribute_attribute_form_action" |
149 | + id="menu_lot_attribute_attribute_action" |
150 | + parent="menu_lot_attribute_in_warehouse_config" |
151 | + sequence="4"/> |
152 | + |
153 | + </data> |
154 | +</openerp> |
155 | |
156 | === added file 'production_lot_custom_attributes/lot.py' |
157 | --- production_lot_custom_attributes/lot.py 1970-01-01 00:00:00 +0000 |
158 | +++ production_lot_custom_attributes/lot.py 2014-01-16 10:33:08 +0000 |
159 | @@ -0,0 +1,133 @@ |
160 | +# -*- coding: utf-8 -*- |
161 | +############################################################################### |
162 | +# # |
163 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
164 | +# Copyright 2013 Camptocamp SA # |
165 | +# # |
166 | +# Inspired by the module product_custom_attributes # |
167 | +# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # |
168 | +# # |
169 | +# This program is free software: you can redistribute it and/or modify # |
170 | +# it under the terms of the GNU Affero General Public License as # |
171 | +# published by the Free Software Foundation, either version 3 of the # |
172 | +# License, or (at your option) any later version. # |
173 | +# # |
174 | +# This program is distributed in the hope that it will be useful, # |
175 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
176 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
177 | +# GNU Affero General Public License for more details. # |
178 | +# # |
179 | +# You should have received a copy of the GNU Affero General Public License # |
180 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
181 | +# # |
182 | +############################################################################### |
183 | + |
184 | +from openerp.osv.orm import Model |
185 | +from openerp.osv import fields |
186 | +from tools.translate import _ |
187 | +from lxml import etree |
188 | + |
189 | + |
190 | +class stock_production_lot(Model): |
191 | + _inherit = "stock.production.lot" |
192 | + |
193 | + _columns = { |
194 | + 'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'), |
195 | + 'attribute_group_ids': fields.related( |
196 | + 'attribute_set_id', |
197 | + 'attribute_group_ids', |
198 | + type='many2many', |
199 | + relation='attribute.group' |
200 | + ) |
201 | + } |
202 | + |
203 | + def open_attributes(self, cr, uid, ids, context=None): |
204 | + """Open the attributes of an object |
205 | + |
206 | + This method is called when the user presses the Open Attributes button |
207 | + in the form view of the object. It opens a dinamically-built form view. |
208 | + |
209 | + :param ids: this is normally a singleton. If a longer list is passed, |
210 | + we consider only the first item. |
211 | + |
212 | + """ |
213 | + |
214 | + if context is None: |
215 | + context = {} |
216 | + |
217 | + model_data_pool = self.pool.get('ir.model.data') |
218 | + |
219 | + for lot in self.browse(cr, uid, ids, context=context): |
220 | + view_id = model_data_pool.get_object_reference( |
221 | + cr, uid, |
222 | + 'production_lot_custom_attributes', |
223 | + 'lot_attributes_form_view')[1] |
224 | + ctx = { |
225 | + 'open_attributes': True, |
226 | + 'attribute_group_ids': [ |
227 | + group.id for group in lot.attribute_group_ids |
228 | + ] |
229 | + } |
230 | + |
231 | + return { |
232 | + 'name': 'Lot Attributes', |
233 | + 'view_type': 'form', |
234 | + 'view_mode': 'form', |
235 | + 'view_id': [view_id], |
236 | + 'res_model': self._name, |
237 | + 'context': ctx, |
238 | + 'type': 'ir.actions.act_window', |
239 | + 'nodestroy': True, |
240 | + 'target': 'new', |
241 | + 'res_id': lot.id, |
242 | + } |
243 | + |
244 | + def save_and_close_lot_attributes(self, cr, uid, ids, context=None): |
245 | + return {'type': 'ir.actions.act_window_close'} |
246 | + |
247 | + def fields_view_get(self, cr, uid, view_id=None, view_type='form', |
248 | + context=None, toolbar=False, submenu=False): |
249 | + if context is None: |
250 | + context = {} |
251 | + attr_pool = self.pool.get('attribute.attribute') |
252 | + result = super(stock_production_lot, self).fields_view_get( |
253 | + cr, uid, view_id, view_type, context, toolbar=toolbar, |
254 | + submenu=submenu |
255 | + ) |
256 | + if view_type == 'form' and context.get('attribute_group_ids'): |
257 | + eview = etree.fromstring(result['arch']) |
258 | + #hide button under the name |
259 | + button = eview.xpath("//button[@name='open_attributes']") |
260 | + if button: |
261 | + button = button[0] |
262 | + button.getparent().remove(button) |
263 | + attributes_notebook, toupdate_fields = ( |
264 | + attr_pool._build_attributes_notebook( |
265 | + cr, uid, context['attribute_group_ids'], context=context |
266 | + ) |
267 | + ) |
268 | + result['fields'].update( |
269 | + self.fields_get(cr, uid, toupdate_fields, context) |
270 | + ) |
271 | + if context.get('open_attributes'): |
272 | + # i.e. the user pressed the open attributes button on the |
273 | + # form view. We put the attributes in a separate form view |
274 | + placeholder = eview.xpath( |
275 | + "//separator[@string='attributes_placeholder']" |
276 | + )[0] |
277 | + placeholder.getparent().replace( |
278 | + placeholder, attributes_notebook |
279 | + ) |
280 | + elif context.get('open_lot_by_attribute_set'): |
281 | + # in this case, we know the attribute set beforehand, and we |
282 | + # add the attributes to the current view |
283 | + main_page = etree.Element( |
284 | + 'page', string=_('Custom Attributes') |
285 | + ) |
286 | + main_page.append(attributes_notebook) |
287 | + info_page = eview.xpath( |
288 | + "//page[@string='%s']" % (_('Stock Moves'),) |
289 | + )[0] |
290 | + info_page.addnext(main_page) |
291 | + result['arch'] = etree.tostring(eview, pretty_print=True) |
292 | + return result |
293 | |
294 | === added file 'production_lot_custom_attributes/lot_view.xml' |
295 | --- production_lot_custom_attributes/lot_view.xml 1970-01-01 00:00:00 +0000 |
296 | +++ production_lot_custom_attributes/lot_view.xml 2014-01-16 10:33:08 +0000 |
297 | @@ -0,0 +1,49 @@ |
298 | +<?xml version="1.0" encoding="utf-8"?> |
299 | +<!-- |
300 | + production_lot_custom_attributes for OpenERP |
301 | + Copyright (C) 2011-2013 Akretion (http://www.akretion.com/) |
302 | + @author: Benoît GUILLOT <benoit.guillot@akretion.com> |
303 | + The licence is in the file __openerp__.py |
304 | +--> |
305 | + |
306 | +<openerp> |
307 | + <data> |
308 | + |
309 | + <record model="ir.ui.view" id="lot_form_view_set_button"> |
310 | + <field name="name">attributes.lot.normal.form</field> |
311 | + <field name="model">stock.production.lot</field> |
312 | + <field name="inherit_id" ref="stock.view_production_lot_form"/> |
313 | + <field name="arch" type="xml"> |
314 | + <notebook position="inside"> |
315 | + <page string="Attributes"> |
316 | + <group name="attribute_fields"> |
317 | + <field name="attribute_set_id" /> |
318 | + <button name="open_attributes" string="Open Attributes" type="object" icon="gtk-ok" attrs="{'invisible':[('attribute_set_id', '=', False)]}"/> |
319 | + </group> |
320 | + </page> |
321 | + </notebook> |
322 | + </field> |
323 | + </record> |
324 | + |
325 | + <record model="ir.ui.view" id="lot_attributes_form_view"> |
326 | + <field name="name">lot.attributes.normal.wizard</field> |
327 | + <field name="model">stock.production.lot</field> |
328 | + <field name="priority">20</field> |
329 | + <field name="arch" type="xml"> |
330 | + <form string="Lot" version="7.0"> |
331 | + <group name="name_set"> |
332 | + <field name="name"/> |
333 | + <field name="attribute_set_id" /> |
334 | + </group> |
335 | + <separator string="attributes_placeholder" colspan="4"/> |
336 | + <footer> |
337 | + <button name="save_and_close_lot_attributes" string="Save and Close" type="object" class="oe_highlight"/> |
338 | + or |
339 | + <button special="cancel" string="Cancel" class="oe_link"/> |
340 | + </footer> |
341 | + </form> |
342 | + </field> |
343 | + </record> |
344 | + |
345 | + </data> |
346 | +</openerp> |
347 | |
348 | === added directory 'production_lot_custom_attributes/test' |
349 | === added file 'production_lot_custom_attributes/test/lot_attribute_test.yml' |
350 | --- production_lot_custom_attributes/test/lot_attribute_test.yml 1970-01-01 00:00:00 +0000 |
351 | +++ production_lot_custom_attributes/test/lot_attribute_test.yml 2014-01-16 10:33:08 +0000 |
352 | @@ -0,0 +1,48 @@ |
353 | +- |
354 | + In order to test Production Lot Custom Fields |
355 | +- |
356 | + First I create an Attribute Set |
357 | +- |
358 | + !record {model: attribute.set, id: lot_attribute_set_A}: |
359 | + name: Serial Number Attribute Set A |
360 | + model_id: stock.model_stock_production_lot |
361 | + attribute_group_ids: |
362 | + - name: Components |
363 | + model_id: stock.model_stock_production_lot |
364 | + sequence: 1 |
365 | + attribute_ids: |
366 | + - name: x_ram_amount |
367 | + model_id: stock.model_stock_production_lot |
368 | + field_description: Amount of RAM |
369 | + attribute_type: float |
370 | + - name: x_has_display |
371 | + model_id: stock.model_stock_production_lot |
372 | + field_description: Has Display |
373 | + attribute_type: boolean |
374 | + - name: Characteristics |
375 | + model_id: stock.model_stock_production_lot |
376 | + sequence: 2 |
377 | + attribute_ids: |
378 | + - name: x_color |
379 | + model_id: stock.model_stock_production_lot |
380 | + field_description: Color |
381 | + attribute_type: char |
382 | + - name: x_length |
383 | + model_id: stock.model_stock_production_lot |
384 | + field_description: Length |
385 | + attribute_type: float |
386 | +- |
387 | + Then I create a Serial Number and set some Attributes |
388 | +- |
389 | + !record {model: stock.production.lot, id: lot_A}: |
390 | + product_id: product.product_product_7 |
391 | + name: 0005 |
392 | + attribute_set_id: lot_attribute_set_A |
393 | + x_color: green |
394 | + x_length: 12.5 |
395 | +- |
396 | + Now I check that my attributes are there |
397 | +- |
398 | + !assert {model: stock.production.lot, id: lot_A, string: Lot Attributes do not work}: |
399 | + - x_color == 'green' |
400 | + - x_length == 12.5 |
401 | |
402 | === added directory 'production_lot_custom_attributes/wizard' |
403 | === added file 'production_lot_custom_attributes/wizard/__init__.py' |
404 | --- production_lot_custom_attributes/wizard/__init__.py 1970-01-01 00:00:00 +0000 |
405 | +++ production_lot_custom_attributes/wizard/__init__.py 2014-01-16 10:33:08 +0000 |
406 | @@ -0,0 +1,25 @@ |
407 | +# -*- coding: utf-8 -*- |
408 | +############################################################################### |
409 | +# # |
410 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
411 | +# Copyright 2013 Camptocamp SA # |
412 | +# # |
413 | +# Inspired by the module product_custom_attributes # |
414 | +# by Benoît GUILLOT <benoit.guillot@akretion.com>, Akretion # |
415 | +# # |
416 | +# This program is free software: you can redistribute it and/or modify # |
417 | +# it under the terms of the GNU Affero General Public License as # |
418 | +# published by the Free Software Foundation, either version 3 of the # |
419 | +# License, or (at your option) any later version. # |
420 | +# # |
421 | +# This program is distributed in the hope that it will be useful, # |
422 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
423 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
424 | +# GNU Affero General Public License for more details. # |
425 | +# # |
426 | +# You should have received a copy of the GNU Affero General Public License # |
427 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
428 | +# # |
429 | +############################################################################### |
430 | + |
431 | +from . import open_lot_by_attribute_set |
432 | |
433 | === added file 'production_lot_custom_attributes/wizard/open_lot_by_attribute_set.py' |
434 | --- production_lot_custom_attributes/wizard/open_lot_by_attribute_set.py 1970-01-01 00:00:00 +0000 |
435 | +++ production_lot_custom_attributes/wizard/open_lot_by_attribute_set.py 2014-01-16 10:33:08 +0000 |
436 | @@ -0,0 +1,67 @@ |
437 | +# -*- coding: utf-8 -*- |
438 | +############################################################################### |
439 | +# # |
440 | +# Author: Leonardo Pistone <leonardo.pistone@camptocamp.com> # |
441 | +# Copyright 2013 Camptocamp SA # |
442 | +# # |
443 | +# This program is free software: you can redistribute it and/or modify # |
444 | +# it under the terms of the GNU Affero General Public License as # |
445 | +# published by the Free Software Foundation, either version 3 of the # |
446 | +# License, or (at your option) any later version. # |
447 | +# # |
448 | +# This program is distributed in the hope that it will be useful, # |
449 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of # |
450 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # |
451 | +# GNU Affero General Public License for more details. # |
452 | +# # |
453 | +# You should have received a copy of the GNU Affero General Public License # |
454 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. # |
455 | +# # |
456 | +############################################################################### |
457 | + |
458 | +from openerp.osv.orm import TransientModel |
459 | +from osv import fields |
460 | + |
461 | + |
462 | +class open_lot_by_attribute_set(TransientModel): |
463 | + _name = 'open.lot.by.attribute.set' |
464 | + _description = 'Wizard to open lots by attributes set' |
465 | + |
466 | + _columns = { |
467 | + 'attribute_set_id': fields.many2one('attribute.set', 'Attribute Set'), |
468 | + } |
469 | + |
470 | + def open_lot_by_attribute(self, cr, uid, ids, context=None): |
471 | + """Opens a lot by attributes |
472 | + |
473 | + Returns a custom action built modifying the original one. |
474 | + """ |
475 | + |
476 | + mod_obj = self.pool.get('ir.model.data') |
477 | + act_obj = self.pool.get('ir.actions.act_window') |
478 | + |
479 | + if context is None: |
480 | + context = {} |
481 | + |
482 | + # we expect one wizard instance at a time |
483 | + for wiz in self.browse(cr, uid, ids, context=context): |
484 | + action_id = mod_obj.get_object_reference( |
485 | + cr, uid, 'stock', 'action_production_lot_form')[1] |
486 | + action = act_obj.read(cr, uid, [action_id], context=context)[0] |
487 | + |
488 | + ctx = ( |
489 | + "{'open_lot_by_attribute_set': True, " |
490 | + "'attribute_group_ids': %s}" |
491 | + % [ |
492 | + group.id |
493 | + for group in wiz.attribute_set_id.attribute_group_ids |
494 | + ] |
495 | + ) |
496 | + |
497 | + action['context'] = ctx |
498 | + action['domain'] = ( |
499 | + "[('attribute_set_id', '=', %s)]" |
500 | + % wiz.attribute_set_id.id |
501 | + ) |
502 | + action['name'] = wiz.attribute_set_id.name |
503 | + return action |
504 | |
505 | === added file 'production_lot_custom_attributes/wizard/open_lot_by_attribute_set.xml' |
506 | --- production_lot_custom_attributes/wizard/open_lot_by_attribute_set.xml 1970-01-01 00:00:00 +0000 |
507 | +++ production_lot_custom_attributes/wizard/open_lot_by_attribute_set.xml 2014-01-16 10:33:08 +0000 |
508 | @@ -0,0 +1,41 @@ |
509 | +<?xml version="1.0" encoding="utf-8"?> |
510 | +<!-- |
511 | + lot_custom_attributes for OpenERP |
512 | + Copyright (C) 2011-2013 Akretion (http://www.akretion.com/) |
513 | + @author: Benoît GUILLOT <benoit.guillot@akretion.com> |
514 | + The licence is in the file __openerp__.py |
515 | +--> |
516 | + |
517 | +<openerp> |
518 | + <data> |
519 | + |
520 | + <record id="open_lot_by_attribute_set_view" model="ir.ui.view"> |
521 | + <field name="name">open.lot.by.attribute.set.view</field> |
522 | + <field name="model">open.lot.by.attribute.set</field> |
523 | + <field name="arch" type="xml"> |
524 | + <form string="Open lot by attributes set" version="7.0"> |
525 | + <group> |
526 | + <field name="attribute_set_id" /> |
527 | + </group> |
528 | + <footer> |
529 | + <button name="open_lot_by_attribute" string="Open lot By attribute" type="object" class="oe_highlight"/> |
530 | + or |
531 | + <button special="cancel" string="Cancel" class="oe_link"/> |
532 | + </footer> |
533 | + </form> |
534 | + </field> |
535 | + </record> |
536 | + |
537 | + <record id="open_lot_by_attribute_set" model="ir.actions.act_window"> |
538 | + <field name="name">Open lot By Attribute Set</field> |
539 | + <field name="res_model">open.lot.by.attribute.set</field> |
540 | + <field name="view_type">form</field> |
541 | + <field name="target">new</field> |
542 | + <field name="view_id" ref="open_lot_by_attribute_set_view"/> |
543 | + <field name="help"></field> |
544 | + </record> |
545 | + |
546 | + <menuitem action="open_lot_by_attribute_set" id="open_lot_wizard" parent="stock.menu_traceability"/> |
547 | + |
548 | + </data> |
549 | +</openerp> |
Thank for the patch.
Can you please check that bug is still valid in 7.0: /code.launchpad .net/~openerp- dev/openerp- web/6.1- opw-579462- cpa
https:/
Please do not use read when not required it remove readability.
Please add some doc string it is hard to get into code.