Merge lp:~savoirfairelinux-openerp/openerp-isp/contract_isp_package_configurator into lp:openerp-isp

Proposed by Mathieu Benoit
Status: Needs review
Proposed branch: lp:~savoirfairelinux-openerp/openerp-isp/contract_isp_package_configurator
Merge into: lp:openerp-isp
Diff against target: 1231 lines (+592/-383)
6 files modified
contract_isp_package_configurator/__openerp__.py (+3/-1)
contract_isp_package_configurator/company.py (+2/-1)
contract_isp_package_configurator/contract_isp_package_configurator_view.xml (+10/-11)
contract_isp_package_configurator/i18n/contract_isp_package_configurator.pot (+263/-0)
contract_isp_package_configurator/wizard/package_configurator.py (+188/-244)
contract_isp_package_configurator/wizard/package_configurator.xml (+126/-126)
To merge this branch: bzr merge lp:~savoirfairelinux-openerp/openerp-isp/contract_isp_package_configurator
Reviewer Review Type Date Requested Status
Joao Alfredo Gama Batista Pending
Review via email: mp+214056@code.launchpad.net

Description of the change

Clean code contract_isp_package_configurator
- pep8
- Remove dupplication code
- Add .pot

To post a comment you must log in.
27. By Mathieu Benoit

[FIX] wizard package_configurator: inverse state product and dependency, for logical workflow.

28. By Mathieu Benoit

[IMP] format package_configurator.xml

Unmerged revisions

28. By Mathieu Benoit

[IMP] format package_configurator.xml

27. By Mathieu Benoit

[FIX] wizard package_configurator: inverse state product and dependency, for logical workflow.

26. By Mathieu Benoit

[FIX] contract_isp_package_configurator: fix last clean - missing variable

25. By Mathieu Benoit

[IMP] contract_isp_package_configurator: add .pot and clean code.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contract_isp_package_configurator/__openerp__.py'
2--- contract_isp_package_configurator/__openerp__.py 2013-09-16 17:59:01 +0000
3+++ contract_isp_package_configurator/__openerp__.py 2014-04-07 19:36:16 +0000
4@@ -28,7 +28,9 @@
5 Contract ISP Package Configurator
6 =================================
7
8-This module provides a wizard to help create service packages based on product inter-dependencies. It uses the dependency tree provided by the product_dependencies module.""",
9+This module provides a wizard to help create service packages based on product\
10+ inter-dependencies. It uses the dependency tree provided by the\
11+ product_dependencies module.""",
12 'author': 'Savoirfaire-Linux Inc',
13 'website': 'www.savoirfairelinux.com',
14 'license': 'AGPL-3',
15
16=== modified file 'contract_isp_package_configurator/company.py'
17--- contract_isp_package_configurator/company.py 2013-09-16 17:59:01 +0000
18+++ contract_isp_package_configurator/company.py 2014-04-07 19:36:16 +0000
19@@ -30,5 +30,6 @@
20 'product.category',
21 'Default Product Category',
22 required=True,
23- help='''Set the default starting point for the package configuration wizard'''),
24+ help='''Set the default starting point for the package \
25+ configuration wizard'''),
26 }
27
28=== modified file 'contract_isp_package_configurator/contract_isp_package_configurator_view.xml'
29--- contract_isp_package_configurator/contract_isp_package_configurator_view.xml 2013-09-16 17:59:01 +0000
30+++ contract_isp_package_configurator/contract_isp_package_configurator_view.xml 2014-04-07 19:36:16 +0000
31@@ -13,17 +13,16 @@
32 </xpath>
33 </field>
34 </record>
35- <record id="view_company_form_package_configurator" model="ir.ui.view">
36- <field name="name">company.form.package.configurator</field>
37- <field name="model">res.company</field>
38- <field name="inherit_id" ref="contract_isp.view_company_contract_isp_form"/>
39- <field name="arch" type="xml">
40- <field name="parent_account_id" position="before">
41- <field name="default_product_category" />
42- </field>
43- </field>
44- </record>
45-
46+ <record id="view_company_form_package_configurator" model="ir.ui.view">
47+ <field name="name">company.form.package.configurator</field>
48+ <field name="model">res.company</field>
49+ <field name="inherit_id" ref="contract_isp.view_company_contract_isp_form"/>
50+ <field name="arch" type="xml">
51+ <field name="parent_account_id" position="before">
52+ <field name="default_product_category" />
53+ </field>
54+ </field>
55+ </record>
56 </data>
57 </openerp>
58
59
60=== modified file 'contract_isp_package_configurator/i18n/contract_isp_package_configurator.pot'
61--- contract_isp_package_configurator/i18n/contract_isp_package_configurator.pot 2013-09-16 17:59:01 +0000
62+++ contract_isp_package_configurator/i18n/contract_isp_package_configurator.pot 2014-04-07 19:36:16 +0000
63@@ -0,0 +1,263 @@
64+# Translation of OpenERP Server.
65+# This file contains the translation of the following modules:
66+# * contract_isp_package_configurator
67+#
68+msgid ""
69+msgstr ""
70+"Project-Id-Version: OpenERP Server 7.0\n"
71+"Report-Msgid-Bugs-To: \n"
72+"POT-Creation-Date: 2014-04-02 19:06+0000\n"
73+"PO-Revision-Date: 2014-04-02 19:06+0000\n"
74+"Last-Translator: <>\n"
75+"Language-Team: \n"
76+"MIME-Version: 1.0\n"
77+"Content-Type: text/plain; charset=UTF-8\n"
78+"Content-Transfer-Encoding: \n"
79+"Plural-Forms: \n"
80+
81+#. module: contract_isp_package_configurator
82+#: view:contract.service.configurator:0
83+#: field:contract.service.configurator,product_category_id:0
84+#: field:contract.service.configurator,root_category_id:0
85+msgid "Category"
86+msgstr ""
87+
88+#. module: contract_isp_package_configurator
89+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:42
90+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:114
91+#: selection:contract.service.configurator.dependency.line,state:0
92+#: selection:contract.service.configurator.line,state:0
93+#, python-format
94+msgid "Information"
95+msgstr ""
96+
97+#. module: contract_isp_package_configurator
98+#: field:contract.service.configurator,is_level2:0
99+msgid "Is level 2"
100+msgstr ""
101+
102+#. module: contract_isp_package_configurator
103+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:149
104+#: selection:contract.service.configurator,state:0
105+#, python-format
106+msgid "Select product"
107+msgstr ""
108+
109+#. module: contract_isp_package_configurator
110+#: field:contract.service.configurator.dependency.line,handle_dependency:0
111+#: field:contract.service.configurator.line,handle_dependency:0
112+msgid "Handle dependencies"
113+msgstr ""
114+
115+#. module: contract_isp_package_configurator
116+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:44
117+#: selection:contract.service.configurator.dependency.line,state:0
118+#: selection:contract.service.configurator.line,state:0
119+#, python-format
120+msgid "No Stock"
121+msgstr ""
122+
123+#. module: contract_isp_package_configurator
124+#: model:ir.model,name:contract_isp_package_configurator.model_contract_service_configurator_dependency_line
125+msgid "contract.service.configurator.dependency.line"
126+msgstr ""
127+
128+#. module: contract_isp_package_configurator
129+#: view:contract.service.configurator:0
130+msgid "Next"
131+msgstr ""
132+
133+#. module: contract_isp_package_configurator
134+#: help:res.company,default_product_category:0
135+msgid "Set the default starting point for the package configuration wizard"
136+msgstr ""
137+
138+#. module: contract_isp_package_configurator
139+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:148
140+#: selection:contract.service.configurator,state:0
141+#, python-format
142+msgid "Start"
143+msgstr ""
144+
145+#. module: contract_isp_package_configurator
146+#: view:contract.service.configurator:0
147+msgid "Add"
148+msgstr ""
149+
150+#. module: contract_isp_package_configurator
151+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:43
152+#: selection:contract.service.configurator.dependency.line,state:0
153+#: selection:contract.service.configurator.line,state:0
154+#, python-format
155+msgid "Select serial number"
156+msgstr ""
157+
158+#. module: contract_isp_package_configurator
159+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:150
160+#: selection:contract.service.configurator,state:0
161+#, python-format
162+msgid "Select components"
163+msgstr ""
164+
165+#. module: contract_isp_package_configurator
166+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:356
167+#, python-format
168+msgid "Product not found!"
169+msgstr ""
170+
171+#. module: contract_isp_package_configurator
172+#: view:contract.service.configurator:0
173+#: field:contract.service.configurator.dependency.line,product_id:0
174+#: field:contract.service.configurator.line,product_id:0
175+msgid "Product"
176+msgstr ""
177+
178+#. module: contract_isp_package_configurator
179+#: field:contract.service.configurator,current_product_id:0
180+msgid "Add Product"
181+msgstr ""
182+
183+#. module: contract_isp_package_configurator
184+#: field:contract.service.configurator.dependency.line,parent_id:0
185+#: field:contract.service.configurator.line,parent_id:0
186+msgid "Parent"
187+msgstr ""
188+
189+#. module: contract_isp_package_configurator
190+#: field:contract.service.configurator.dependency.line,serial:0
191+#: view:contract.service.configurator.line:0
192+#: field:contract.service.configurator.line,serial:0
193+msgid "Serial Number"
194+msgstr ""
195+
196+#. module: contract_isp_package_configurator
197+#: field:contract.service.configurator,dependency_ids:0
198+msgid "Dependencies"
199+msgstr ""
200+
201+#. module: contract_isp_package_configurator
202+#: field:res.company,default_product_category:0
203+msgid "Default Product Category"
204+msgstr ""
205+
206+#. module: contract_isp_package_configurator
207+#: field:contract.service.configurator,line_ids:0
208+msgid "Line"
209+msgstr ""
210+
211+#. module: contract_isp_package_configurator
212+#: model:ir.model,name:contract_isp_package_configurator.model_contract_service_configurator_line
213+msgid "contract.service.configurator.line"
214+msgstr ""
215+
216+#. module: contract_isp_package_configurator
217+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:414
218+#, python-format
219+msgid "Product Details"
220+msgstr ""
221+
222+#. module: contract_isp_package_configurator
223+#: view:contract.service.configurator.line:0
224+msgid "Ok"
225+msgstr ""
226+
227+#. module: contract_isp_package_configurator
228+#: field:contract.service.configurator.dependency.line,name:0
229+#: field:contract.service.configurator.line,name:0
230+msgid "Name"
231+msgstr ""
232+
233+#. module: contract_isp_package_configurator
234+#: model:ir.model,name:contract_isp_package_configurator.model_contract_service_configurator
235+msgid "contract.service.configurator"
236+msgstr ""
237+
238+#. module: contract_isp_package_configurator
239+#: model:ir.model,name:contract_isp_package_configurator.model_res_company
240+msgid "Companies"
241+msgstr ""
242+
243+#. module: contract_isp_package_configurator
244+#: field:contract.service.configurator,contract_id:0
245+msgid "Contract"
246+msgstr ""
247+
248+#. module: contract_isp_package_configurator
249+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:41
250+#: selection:contract.service.configurator.dependency.line,state:0
251+#: selection:contract.service.configurator.line,state:0
252+#, python-format
253+msgid "Added"
254+msgstr ""
255+
256+#. module: contract_isp_package_configurator
257+#: view:contract.service.configurator:0
258+#: view:contract.service.configurator.line:0
259+msgid "Products"
260+msgstr ""
261+
262+#. module: contract_isp_package_configurator
263+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:356
264+#, python-format
265+msgid "Error"
266+msgstr ""
267+
268+#. module: contract_isp_package_configurator
269+#: view:account.analytic.account:0
270+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:426
271+#: view:contract.service.configurator:0
272+#: field:contract.service.configurator.dependency.line,configurator_id:0
273+#: view:contract.service.configurator.line:0
274+#: field:contract.service.configurator.line,configurator_id:0
275+#: model:ir.actions.act_window,name:contract_isp_package_configurator.action_contract_isp_package_configurator
276+#, python-format
277+msgid "Package Configurator"
278+msgstr ""
279+
280+#. module: contract_isp_package_configurator
281+#: field:contract.service.configurator.dependency.line,stock_move_id:0
282+#: field:contract.service.configurator.line,stock_move_id:0
283+msgid "Stock Move"
284+msgstr ""
285+
286+#. module: contract_isp_package_configurator
287+#: field:contract.service.configurator,state:0
288+#: field:contract.service.configurator.dependency.line,state:0
289+#: field:contract.service.configurator.line,state:0
290+msgid "State"
291+msgstr ""
292+
293+#. module: contract_isp_package_configurator
294+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:45
295+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:151
296+#: view:contract.service.configurator:0
297+#: selection:contract.service.configurator,state:0
298+#: selection:contract.service.configurator.dependency.line,state:0
299+#: selection:contract.service.configurator.line,state:0
300+#, python-format
301+msgid "Done"
302+msgstr ""
303+
304+#. module: contract_isp_package_configurator
305+#: view:contract.service.configurator:0
306+msgid "Click on add to view the available components"
307+msgstr ""
308+
309+#. module: contract_isp_package_configurator
310+#: code:addons/contract_isp_package_configurator/wizard/package_configurator.py:450
311+#: view:contract.service.configurator:0
312+#, python-format
313+msgid "Cancel"
314+msgstr ""
315+
316+#. module: contract_isp_package_configurator
317+#: field:contract.service.configurator.dependency.line,message:0
318+#: field:contract.service.configurator.line,message:0
319+msgid "Message"
320+msgstr ""
321+
322+#. module: contract_isp_package_configurator
323+#: view:contract.service.configurator.line:0
324+msgid "We don't have this product in stock at the moment!"
325+msgstr ""
326+
327
328=== modified file 'contract_isp_package_configurator/wizard/package_configurator.py'
329--- contract_isp_package_configurator/wizard/package_configurator.py 2013-10-11 14:30:38 +0000
330+++ contract_isp_package_configurator/wizard/package_configurator.py 2014-04-07 19:36:16 +0000
331@@ -27,7 +27,6 @@
332 class contract_service_configurator_line(orm.TransientModel):
333 _name = 'contract.service.configurator.line'
334
335- #def _get_stock_production_lot_available(self, cr, uid, )
336 _columns = {
337 'name': fields.char('Name'),
338 'product_id': fields.many2one('product.product', 'Product'),
339@@ -42,7 +41,7 @@
340 'state': fields.selection((('draft', _('Added')),
341 ('message', _('Information')),
342 ('serial', _('Select serial number')),
343- ('stock', ('No Stock')),
344+ ('stock', _('No Stock')),
345 ('done', _('Done'))), 'State'),
346 }
347
348@@ -51,37 +50,43 @@
349 }
350
351 def router(self, cr, uid, ids, data=None, context=None):
352+ if isinstance(ids, list):
353+ ids = ids[0]
354+ pool_stock_move = self.pool.get('stock.move')
355+ pool_model_data = self.pool.get('ir.model.data')
356+
357 stock_move_id = None
358- if isinstance(ids, list):
359- ids = ids[0]
360 line = self.browse(cr, uid, ids, context=context)
361 if line.state == 'message':
362- if line.product_id.type == 'product' and \
363- line.product_id.qty_available > 0.0:
364+ if line.product_id.type == 'product' \
365+ and line.product_id.qty_available > 0:
366 state = 'serial'
367 else:
368 state = 'stock'
369 elif line.state in ('serial', 'stock'):
370- stock_move_obj = self.pool.get('stock.move')
371- location_id = self.pool.get('ir.model.data').get_object_reference(
372- cr, uid, 'stock', 'stock_location_stock')[1]
373- location_dest_id = line.configurator_id.contract_id.partner_id.property_stock_customer.id
374+ location_id = \
375+ pool_model_data.get_object_reference(cr, uid, 'stock',
376+ 'stock_location_stock')[1]
377+ partner = line.configurator_id.contract_id.partner_id
378+ product = line.product_id and line.product_id
379+ product_uom = product and product.uom_id
380+ location_dest_id = partner.property_stock_customer.id
381 move = {
382 'name': line.product_id and line.product_id.name or '',
383- 'product_id': line.product_id and line.product_id.id,
384- 'product_uom': line.product_id and line.product_id.uom_id and line.product_id.uom_id.id or None,
385+ 'product_id': product and product.id,
386+ 'product_uom': product_uom and product_uom.id or None,
387 'prodlot_id': line.serial and line.serial.id or None,
388 'location_id': location_id,
389 'location_dest_id': location_dest_id,
390- 'partner_id': line.configurator_id.contract_id.partner_id.id,
391+ 'partner_id': partner.id,
392 'type': 'out'
393 }
394- stock_move_id = stock_move_obj.create(
395- cr, uid, move, context=context)
396- stock_move_obj.action_confirm(
397- cr, uid, [stock_move_id], context=context)
398- stock_move_obj.action_done(
399- cr, uid, [stock_move_id], context=context)
400+ stock_move_id = pool_stock_move.create(cr, uid, move,
401+ context=context)
402+ pool_stock_move.action_confirm(cr, uid, [stock_move_id],
403+ context=context)
404+ pool_stock_move.action_done(cr, uid, [stock_move_id],
405+ context=context)
406
407 state = 'done'
408
409@@ -93,37 +98,21 @@
410 if isinstance(ids, int):
411 ids = [ids]
412
413- for line in self.browse(cr, uid, ids, context=context):
414- if line.product_id.type == 'product' and line.stock_move_id:
415- stock_move_obj = self.pool.get('stock.move')
416- move = {
417- 'name': ' '.join([_('Cancel'), line.product_id and line.product_id.name or '']),
418- 'product_id': line.product_id and line.product_id.id,
419- 'product_uom': line.product_id and line.product_id.uom_id and line.product_id.uom_id.id or None,
420- 'prodlot_id': line.serial and line.serial.id or None,
421- 'location_id': line.stock_move_id.location_dest_id.id,
422- 'location_dest_id': line.stock_move_id.location_id.id,
423- 'partner_id': line.configurator_id.contract_id.partner_id.id,
424- 'type': 'in'
425- }
426- stock_move_id = stock_move_obj.create(
427- cr, uid, move, context=context)
428- stock_move_obj.action_confirm(
429- cr, uid, [stock_move_id], context=context)
430- stock_move_obj.action_done(
431- cr, uid, [stock_move_id], context=context)
432+ cancel_dependancy(self, cr, uid, ids, context, cancel_line=False)
433
434 return super(contract_service_configurator_line, self).unlink(
435 cr, uid, ids, context=context)
436
437 def onchange_product_id(self, cr, uid, ids, product_id, context):
438 ret = {}
439- product_product_obj = self.pool.get('product.product')
440+ pool_product_product = self.pool.get('product.product')
441+ product_product_obj = pool_product_product.browse(cr, uid, product_id,
442+ context)
443
444- if product_product_obj.browse(cr, uid, product_id, context).description:
445+ if product_product_obj.description:
446 ret['warning'] = {
447 'title': _('Information'),
448- 'message': product_product_obj.browse(cr, uid, product_id, context).description
449+ 'message': product_product_obj.description
450 }
451 return ret
452
453@@ -136,46 +125,41 @@
454 class contract_service_configurator(orm.TransientModel):
455 _name = 'contract.service.configurator'
456
457- def _get_default_category(self, cr, uid, context=None):
458+ def get_default_category(self, cr, uid, context=None):
459 res_company_obj = self.pool.get("res.company")
460 company_id = res_company_obj._company_default_get(cr, uid, context)
461 res_company = res_company_obj.browse(cr, uid, company_id,
462 context=context)
463- return res_company.default_product_category and \
464- res_company.default_product_category.id
465+ cat = res_company.default_product_category
466+ return cat and cat.id
467
468- def _get_is_level2(self, cr, uid, context=None):
469+ def get_is_level2(self, cr, uid, context=None):
470 ir_model_data_obj = self.pool.get('ir.model.data')
471- res_groups_obj = self.pool.get('res.groups')
472 res_user = self.pool.get('res.users').browse(
473 cr, uid, uid, context={})
474 group_agent_n2_id = ir_model_data_obj.get_object_reference(
475 cr, uid, 'contract_isp', 'group_isp_agent2')[1]
476- group_agent_n2 = res_groups_obj.browse(
477- cr, uid, group_agent_n2_id, context={})
478
479 groups_id = [i.id for i in res_user.groups_id]
480- if group_agent_n2_id not in groups_id:
481- return False
482- else:
483- return True
484+ return group_agent_n2_id in groups_id
485
486 _columns = {
487 'contract_id': fields.many2one('account.analytic.account', 'Contract'),
488 'state': fields.selection((('draft', _('Start')),
489+ ('dependency', _('Select components')),
490 ('product', _('Select product')),
491- ('dependency', _('Select components')),
492 ('done', _('Done'))), 'State'),
493 'line_ids': fields.one2many('contract.service.configurator.line',
494 'configurator_id',
495 'Line'),
496 'current_product_id': fields.many2one('product.product',
497 'Add Product'),
498- 'dependency_ids': fields.many2many('contract.service.configurator.dependency.line',
499- 'contract_service_configurator_dependency_rel',
500- 'configurator_id',
501- 'dependency_id',
502- 'Dependencies'),
503+ 'dependency_ids': fields.many2many(
504+ 'contract.service.configurator.dependency.line',
505+ 'contract_service_configurator_dependency_rel',
506+ 'configurator_id',
507+ 'dependency_id',
508+ 'Dependencies'),
509 'root_category_id': fields.many2one('product.category', 'Category'),
510 'product_category_id': fields.many2one('product.category', 'Category'),
511 'is_level2': fields.boolean('Is level 2')
512@@ -183,16 +167,18 @@
513
514 _defaults = {
515 'state': 'draft',
516- 'product_category_id': lambda s, cr, uid, ctx: s._get_default_category(cr, uid, ctx),
517- 'root_category_id': lambda s, cr, uid, ctx: s._get_default_category(cr, uid, ctx),
518- 'is_level2': lambda s, cr, uid, ctx: s._get_is_level2(cr, uid, ctx)
519+ 'product_category_id':
520+ lambda s, cr, uid, ctx: s.get_default_category(cr, uid, ctx),
521+ 'root_category_id':
522+ lambda s, cr, uid, ctx: s.get_default_category(cr, uid, ctx),
523+ 'is_level2': lambda s, cr, uid, ctx: s.get_is_level2(cr, uid, ctx)
524 }
525
526- def onchange_product_category_id(self, cr, uid, ids,
527- product_category_id, is_level2):
528+ @staticmethod
529+ def onchange_product_category_id(cr, uid, ids, product_category_id,
530+ is_level2):
531 domain = [('categ_id', '=', product_category_id)]
532- ret = {
533- 'domain': {'current_product_id': None}}
534+ ret = {'domain': {'current_product_id': None}}
535
536 if not is_level2:
537 domain.append(('list_price', '>=', 0))
538@@ -202,9 +188,10 @@
539 return ret
540
541 def do_next(self, cr, uid, ids, context=None):
542- contract_service_configurator_line_obj = self.pool.get('contract.service.configurator.line')
543- contract_service_configurator_dependency_line_obj = self.pool.get('contract.service.configurator.dependency.line')
544- product_product_obj = self.pool.get('product.product')
545+ contract_service_configurator_line_obj = self.pool.get(
546+ 'contract.service.configurator.line')
547+ pool_conf_dep_line = self.pool.get(
548+ 'contract.service.configurator.dependency.line')
549
550 wizard = self.browse(cr, uid, ids[0], context=context)
551
552@@ -221,117 +208,116 @@
553 'name': line.product_id.name,
554 'product_id': line.product_id.id,
555 'configurator_id': wizard.id,
556- 'handle_dependency': line.product_id.dependency_ids and True or False,
557+ 'handle_dependency': line.product_id.dependency_ids,
558 'message': line.product_id.description,
559 'state': state
560 }
561- contract_service_configurator_line_obj.create(cr, uid, l, context=context)
562+ contract_service_configurator_line_obj.create(cr, uid, l,
563+ context=context)
564
565 query = [('configurator_id', '=', wizard.id)]
566- ids_to_unlink = contract_service_configurator_dependency_line_obj.search(cr,
567- uid,
568- query,
569- context=context)
570+ ids_to_unlink = pool_conf_dep_line.search(
571+ cr,
572+ uid,
573+ query,
574+ context=context)
575 if ids_to_unlink:
576- contract_service_configurator_dependency_line_obj.unlink(cr, uid,
577- ids_to_unlink,
578- context)
579+ pool_conf_dep_line.unlink(cr, uid, ids_to_unlink, context)
580
581 loop_deps = False
582 for line in wizard.line_ids:
583- if line.handle_dependency:
584- loop_deps = True
585- for dep in line.product_id.dependency_ids:
586- if dep.type == 'product':
587- if not wizard.is_level2 and dep.list_price < 0:
588- continue
589-
590- if line.product_id.description:
591- state = 'message'
592- elif line.product_id.type == 'product':
593- state = 'serial'
594- else:
595- state = 'done'
596-
597- wl = {
598- 'name': dep.product_id.name,
599- 'product_id': dep.product_id.id,
600- 'configurator_id': wizard.id,
601- 'parent_id': line.id,
602- 'message': line.product_id.description,
603- 'state': state
604- }
605- new_dep = contract_service_configurator_dependency_line_obj.create(
606- cr, uid, wl, context=context)
607-
608- if dep.auto:
609- wizard.write({'dependency_ids': [(4, new_dep)]})
610-
611- elif dep.type == 'category':
612- query = [('categ_id', '=', dep.category_id.id)]
613- product_ids = product_product_obj.search(cr, uid,
614- query,
615- context=context)
616- for product in product_product_obj.browse(cr, uid, product_ids, context=context):
617- if not wizard.is_level2 and dep.list_price < 0:
618- continue
619-
620- if line.product_id.description:
621- state = 'message'
622- elif line.product_id.type == 'product':
623- state = 'serial'
624- else:
625- state = 'done'
626-
627- wl = {
628- 'name': product.name,
629- 'product_id': product.id,
630- 'configurator_id': wizard.id,
631- 'parent_id': line.id,
632- 'message': product.description,
633- 'state': state
634- }
635- contract_service_configurator_dependency_line_obj.create(cr, uid, wl,
636- context=context)
637- line.write({'handle_dependency': False})
638- break
639+ if not line.handle_dependency:
640+ continue
641+
642+ loop_deps = True
643+ self._write_dependance(line, wizard, cr, uid, context)
644+ line.write({'handle_dependency': False})
645+ break
646
647 if loop_deps:
648 record = {
649 'state': 'dependency',
650 }
651- wizard.write(record)
652- return self.router(cr, uid, ids, {}, context=context)
653-
654 else:
655 record = {
656 'state': 'product',
657 'current_product_id': None,
658- 'dependency_ids': [(5)],
659+ 'dependency_ids': [5],
660 }
661- wizard.write(record)
662-
663- query = [('configurator_id', '=', wizard.id)]
664- ids_to_unlink = contract_service_configurator_dependency_line_obj.search(cr,
665- uid,
666- query,
667- context=context)
668- return self.router(cr, uid, ids, {}, context=context)
669+ wizard.write(record)
670+ return self.router(cr, uid, ids, {}, context=context)
671+
672+ def _write_dependance(self, line, wizard, cr, uid, context):
673+ pool_conf_dep_line = self.pool.get(
674+ 'contract.service.configurator.dependency.line')
675+ product_product_obj = self.pool.get('product.product')
676+
677+ contains_dep = False
678+ for dep in line.product_id.dependency_ids:
679+ if dep.type == 'product':
680+ if not wizard.is_level2 and dep.list_price < 0:
681+ continue
682+
683+ if line.product_id.description:
684+ state = 'message'
685+ elif line.product_id.type == 'product':
686+ state = 'serial'
687+ else:
688+ state = 'done'
689+ contains_dep = True
690+ wl = {
691+ 'name': dep.product_id.name,
692+ 'product_id': dep.product_id.id,
693+ 'configurator_id': wizard.id,
694+ 'parent_id': line.id,
695+ 'message': line.product_id.description,
696+ 'state': state
697+ }
698+ new_dep = pool_conf_dep_line.create(cr, uid, wl,
699+ context=context)
700+
701+ if dep.auto:
702+ wizard.write({'dependency_ids': [(4, new_dep)]})
703+
704+ elif dep.type == 'category':
705+ query = [('categ_id', '=', dep.category_id.id)]
706+ product_ids = product_product_obj.search(cr, uid,
707+ query,
708+ context=context)
709+ for product in product_product_obj.browse(cr, uid,
710+ product_ids,
711+ context=context):
712+ if not wizard.is_level2 and dep.list_price < 0:
713+ continue
714+
715+ if line.product_id.description:
716+ state = 'message'
717+ elif line.product_id.type == 'product':
718+ state = 'serial'
719+ else:
720+ state = 'done'
721+ contains_dep = True
722+ wl = {
723+ 'name': product.name,
724+ 'product_id': product.id,
725+ 'configurator_id': wizard.id,
726+ 'parent_id': line.id,
727+ 'message': product.description,
728+ 'state': state
729+ }
730+ pool_conf_dep_line.create(
731+ cr, uid, wl,
732+ context=context)
733+ return contains_dep
734
735 def do_add_current_product_id(self, cr, uid, ids, context=None):
736 if context is None:
737 context = {}
738- deps = 0
739 wizard = self.browse(cr, uid, ids[0], context=context)
740- contract_service_configurator_line_obj = self.pool.get(
741- 'contract.service.configurator.line')
742- contract_service_configurator_dependency_line_obj = self.pool.get(
743- 'contract.service.configurator.dependency.line')
744- product_product_obj = self.pool.get('product.product')
745- contract_service_serial_obj = self.pool.get('contract.service.serial')
746+ pool_cs_conf_line = self.pool.get('contract.service.configurator.line')
747
748 if wizard.current_product_id:
749- #if group_agent_n2_id not in res_user.groups_id and \
750+ # if group_agent_n2_id not in res_user.groups_id and \
751 # wizard.current_product_id.type == 'product' and \
752 # wizard.current_product_id.qty_available <= 0:
753 # raise orm.except_orm(_('Error!'), _('Product not available!'))
754@@ -350,72 +336,19 @@
755 'message': wizard.current_product_id.description,
756 'state': state
757 }
758- new_line = contract_service_configurator_line_obj.create(
759- cr, uid, record, context=context)
760-
761- for dep in contract_service_configurator_line_obj.browse(
762- cr, uid, new_line,
763- context=context).product_id.dependency_ids:
764-
765- if dep.type == 'product':
766- if not wizard.is_level2 and dep.product_id.list_price < 0:
767- continue
768-
769- if dep.product_id.description:
770- state = 'message'
771- elif dep.product_id.type == 'product':
772- state = 'serial'
773- else:
774- state = 'done'
775-
776- deps += 1
777- wl = {
778- 'name': dep.product_id.name,
779- 'product_id': dep.product_id.id,
780- 'configurator_id': wizard.id,
781- 'parent_id': new_line,
782- 'message': dep.product_id.description,
783- 'state': state
784- }
785- new_dep = contract_service_configurator_dependency_line_obj.create(cr, uid, wl,
786- context=context)
787-
788- if dep.auto:
789- wizard.write({'dependency_ids': [(4, new_dep)]})
790-
791- elif dep.type == 'category':
792- query = [('categ_id', '=', dep.category_id.id)]
793- product_ids = product_product_obj.search(cr, uid, query,
794- context=context)
795- for product in product_product_obj.browse(cr, uid,
796- product_ids,
797- context=context):
798- if not wizard.is_level2 and dep.product_id.list_price < 0:
799- continue
800-
801- if product.description:
802- state = 'message'
803- elif product.type == 'product':
804- state = 'serial'
805- else:
806- state = 'done'
807-
808- deps += 1
809- record = {
810- 'name': product.name,
811- 'product_id': product.id,
812- 'configurator_id': wizard.id,
813- 'parent_id': new_line,
814- 'message': product.description,
815- 'state': state
816- }
817- contract_service_configurator_dependency_line_obj.create(
818- cr, uid, record, context=context)
819+ new_line = pool_cs_conf_line.create(cr, uid, record,
820+ context=context)
821+
822+ product_obj = pool_cs_conf_line.browse(cr, uid, new_line,
823+ context=context)
824+ contains_dep = self._write_dependance(product_obj, wizard, cr, uid,
825+ context)
826
827 record = {
828 'current_product_id': None,
829- 'product_category_id': self._get_default_category(cr, uid, context),
830- 'state': deps and 'dependency' or 'product'
831+ 'product_category_id': self.get_default_category(cr, uid,
832+ context),
833+ 'state': contains_dep and 'dependency' or 'product'
834 }
835
836 wizard.write(record)
837@@ -424,11 +357,7 @@
838 raise orm.except_orm(_('Error'), _('Product not found!'))
839
840 def do_done(self, cr, uid, ids, context=None):
841- account_analytic_account_obj = self.pool.get('account.analytic.account')
842- contract_service_obj = self.pool.get('contract.service')
843- stock_move_obj = self.pool.get('stock.move')
844- contract_service_serial_obj = self.pool.get('contract.service.serial')
845- ret = self.write(cr, uid, ids, {'state': 'done'}, context=context)
846+ pool_contract_service = self.pool.get('contract.service')
847 wizard = self.browse(cr, uid, ids[0], context=context)
848 for line in wizard.line_ids:
849 l = {
850@@ -439,7 +368,7 @@
851 'analytic_line_type': line.product_id.analytic_line_type,
852 'require_activation': line.product_id.require_activation
853 }
854- contract_service_obj.create(cr, uid, l, context=context)
855+ pool_contract_service.create(cr, uid, l, context=context)
856
857 if line.product_id.type == 'product' and line.stock_move_id:
858 line.write({'stock_move_id': None})
859@@ -458,44 +387,26 @@
860 if isinstance(ids, int):
861 ids = [ids]
862
863- for line in self.browse(cr, uid, ids[0], context=context).line_ids:
864- if line.product_id.type == 'product' and line.stock_move_id:
865- stock_move_obj = self.pool.get('stock.move')
866- move = {
867- 'name': ' '.join([_('Cancel'), line.product_id and line.product_id.name or '']),
868- 'product_id': line.product_id and line.product_id.id,
869- 'product_uom': line.product_id and line.product_id.uom_id and line.product_id.uom_id.id or None,
870- 'prodlot_id': line.serial and line.serial.id or None,
871- 'location_id': line.stock_move_id.location_dest_id.id,
872- 'location_dest_id': line.stock_move_id.location_id.id,
873- 'partner_id': line.configurator_id.contract_id.partner_id.id,
874- 'type': 'in'
875- }
876- stock_move_id = stock_move_obj.create(
877- cr, uid, move, context=context)
878- stock_move_obj.action_confirm(
879- cr, uid, [stock_move_id], context=context)
880- stock_move_obj.action_done(
881- cr, uid, [stock_move_id], context=context)
882+ cancel_dependancy(self, cr, uid, ids, context, cancel_line=True)
883
884 return True
885
886 def router(self, cr, uid, ids, data=None, context=None):
887+ pool_stock_prod_lot = self.pool.get('stock.production.lot')
888 if isinstance(ids, list):
889 ids = ids[0]
890 wizard = self.browse(cr, uid, ids, context=context)
891 for line in wizard.line_ids:
892 if line.state in ('message', 'serial', 'stock'):
893 if line.state == 'serial':
894- stock_production_lot_obj = self.pool.get('stock.production.lot')
895- product_product_obj = self.pool.get('product.product')
896
897 query = [
898 ('product_id', '=', line.product_id.id),
899 ('stock_available', '>', 0)
900 ]
901
902- serial_ids = stock_production_lot_obj.search(cr, uid, query, context=context)
903+ serial_ids = pool_stock_prod_lot.search(cr, uid, query,
904+ context=context)
905
906 if not serial_ids:
907 line.write({'state': 'stock'})
908@@ -523,3 +434,36 @@
909 'nodestroy': True,
910 'context': context
911 }
912+
913+
914+def cancel_dependancy(obj_orm, cr, uid, ids, context, cancel_line=True):
915+ pool_stock_move = obj_orm.pool.get('stock.move')
916+ if cancel_line:
917+ lines = obj_orm.browse(cr, uid, ids[0], context=context).line_ids
918+ else:
919+ lines = obj_orm.browse(cr, uid, ids, context=context)
920+
921+ for line in lines:
922+ if line.product_id.type == 'product' and line.stock_move_id:
923+ product = line.product_id and line.product_id
924+ product_name = product.name or ''
925+ product_uom = product.uom_id and line.product_id.uom_id
926+ name = "%s %s" % (_('Cancel'), product_name)
927+
928+ partner = line.configurator_id.contract_id.partner_id.id
929+ move = {
930+ 'name': name,
931+ 'product_id': product.id,
932+ 'product_uom': product_uom,
933+ 'prodlot_id': line.serial and line.serial.id or None,
934+ 'location_id': line.stock_move_id.location_dest_id.id,
935+ 'location_dest_id': line.stock_move_id.location_id.id,
936+ 'partner_id': partner,
937+ 'type': 'in'
938+ }
939+ stock_move_id = pool_stock_move.create(cr, uid, move,
940+ context=context)
941+ pool_stock_move.action_confirm(cr, uid, [stock_move_id],
942+ context=context)
943+ pool_stock_move.action_done(cr, uid, [stock_move_id],
944+ context=context)
945\ No newline at end of file
946
947=== modified file 'contract_isp_package_configurator/wizard/package_configurator.xml'
948--- contract_isp_package_configurator/wizard/package_configurator.xml 2013-10-10 19:22:10 +0000
949+++ contract_isp_package_configurator/wizard/package_configurator.xml 2014-04-07 19:36:16 +0000
950@@ -4,145 +4,145 @@
951 <record id="view_contract_service_configurator_line_tree" model="ir.ui.view">
952 <field name="name">Package Configurator Line</field>
953 <field name="model">contract.service.configurator.line</field>
954- <field name="type">tree</field>
955+ <field name="type">tree</field>
956 <field name="arch" type="xml">
957 <tree string="Package Configurator" version="7.0">
958- <field name="product_id" />
959- </tree>
960- </field>
961- </record>
962+ <field name="product_id" />
963+ </tree>
964+ </field>
965+ </record>
966
967 <record id="view_contract_service_configurator" model="ir.ui.view">
968 <field name="name">Package Configurator</field>
969 <field name="model">contract.service.configurator</field>
970 <field name="arch" type="xml">
971 <form string="Package Configurator" version="7.0">
972- <header>
973- <field name="state" class="oe_right" widget="statusbar" />
974- </header>
975- <field name="root_category_id" invisible="1" />
976- <field name="is_level2" invisible="1" />
977- <field name="contract_id" invisible="1" />
978- <group string="Category" attrs="{'invisible': [('state', '=', 'dependency')]}">
979- <field
980- nolabel="1"
981- name="product_category_id"
982- options="{'no_open': True}"
983- domain="[('type', '=', 'normal'), ('id', 'child_of', [root_category_id])]"
984- on_change="onchange_product_category_id(product_category_id, is_level2)" />
985- </group>
986- <group string="Products" attrs="{'invisible': [('state', '=', 'dependency')]}">
987- <group colspan="4">
988- <div width="100%%">
989- <field
990- name="current_product_id"
991- width="70%%"
992- class="oe_inline"
993- options="{'no_open': True}"
994- domain = "[('categ_id', '=', product_category_id)]"
995- placeholder="Product" />
996- <button
997- name="do_add_current_product_id"
998- string="Add"
999- type="object"
1000- states="draft,product"
1001- width="15%%"
1002- class="oe_inline oe_highlight" />
1003- </div>
1004- </group>
1005- <group>
1006- <field name="line_ids" nolabel="1" mode="tree">
1007- <tree create="0">
1008- <field name="product_id" />
1009- <field name="serial" />
1010- </tree>
1011- </field>
1012- </group>
1013- </group>
1014- <group attrs="{'invisible': [('state', '&lt;&gt;', 'dependency')]}">
1015- <div colspan="4">
1016- <p>Click on add to view the available components</p>
1017- </div>
1018- <field
1019- name="dependency_ids"
1020- nolabel="1"
1021- mode="tree"
1022- widget="many2many"
1023- domain="[('configurator_id', '=', active_id)]">
1024- <tree>
1025- <field name="product_id" on_change="onchange_product_id(product_id, context)"/>
1026- </tree>
1027- </field>
1028- </group>
1029+ <header>
1030+ <field name="state" class="oe_right" widget="statusbar" />
1031+ </header>
1032+ <field name="root_category_id" invisible="1" />
1033+ <field name="is_level2" invisible="1" />
1034+ <field name="contract_id" invisible="1" />
1035+ <group string="Category" attrs="{'invisible': [('state', '=', 'dependency')]}">
1036+ <field
1037+ nolabel="1"
1038+ name="product_category_id"
1039+ options="{'no_open': True}"
1040+ domain="[('type', '=', 'normal'), ('id', 'child_of', [root_category_id])]"
1041+ on_change="onchange_product_category_id(product_category_id, is_level2)" />
1042+ </group>
1043+ <group string="Products" attrs="{'invisible': [('state', '=', 'dependency')]}">
1044+ <group colspan="4">
1045+ <div width="100%%">
1046+ <field
1047+ name="current_product_id"
1048+ width="70%%"
1049+ class="oe_inline"
1050+ options="{'no_open': True}"
1051+ domain = "[('categ_id', '=', product_category_id)]"
1052+ placeholder="Product" />
1053+ <button
1054+ name="do_add_current_product_id"
1055+ string="Add"
1056+ type="object"
1057+ states="draft,product"
1058+ width="15%%"
1059+ class="oe_inline oe_highlight" />
1060+ </div>
1061+ </group>
1062+ <group>
1063+ <field name="line_ids" nolabel="1" mode="tree">
1064+ <tree create="0">
1065+ <field name="product_id" />
1066+ <field name="serial" />
1067+ </tree>
1068+ </field>
1069+ </group>
1070+ </group>
1071+ <group attrs="{'invisible': [('state', '&lt;&gt;', 'dependency')]}">
1072+ <div colspan="4">
1073+ <p>Click on add to view the available components</p>
1074+ </div>
1075+ <field
1076+ name="dependency_ids"
1077+ nolabel="1"
1078+ mode="tree"
1079+ widget="many2many"
1080+ domain="[('configurator_id', '=', active_id)]">
1081+ <tree>
1082+ <field name="product_id" on_change="onchange_product_id(product_id, context)"/>
1083+ </tree>
1084+ </field>
1085+ </group>
1086
1087- <footer>
1088- <button
1089- name="do_next"
1090- string="Next"
1091- type="object"
1092- class="oe_highlight"
1093- states="dependency"
1094- />
1095- <button
1096- name="do_done"
1097- string="Done"
1098- type="object"
1099- class="oe_highlight"
1100- states="product,done"
1101- />
1102- <button
1103- string="Cancel"
1104- class="oe_link"
1105- type="object"
1106- name="do_cancel" />
1107- </footer>
1108- </form>
1109- </field>
1110- </record>
1111+ <footer>
1112+ <button
1113+ name="do_next"
1114+ string="Next"
1115+ type="object"
1116+ class="oe_highlight"
1117+ states="dependency"
1118+ />
1119+ <button
1120+ name="do_done"
1121+ string="Done"
1122+ type="object"
1123+ class="oe_highlight"
1124+ states="product,done"
1125+ />
1126+ <button
1127+ string="Cancel"
1128+ class="oe_link"
1129+ type="object"
1130+ name="do_cancel" />
1131+ </footer>
1132+ </form>
1133+ </field>
1134+ </record>
1135
1136 <record id="view_contract_service_configurator_line" model="ir.ui.view">
1137 <field name="name">Product Details</field>
1138 <field name="model">contract.service.configurator.line</field>
1139 <field name="arch" type="xml">
1140 <form string="Package Configurator" version="7.0">
1141- <header>
1142- <field
1143- name="state"
1144- class="oe_right"
1145- widget="statusbar"
1146- attrs="{'invisible': [('state', '=', 'message')]}"/>
1147- </header>
1148- <group string="Products" colspan="4" attrs="{'invisible': [('state', 'in', ('message', 'stock'))]}">
1149- <field name="product_id" readonly="1" />
1150- <field
1151- name="serial"
1152- class="oe_inline"
1153- domain="[('product_id', '=', product_id), '&amp;', ('stock_available', '&gt;', 0)]"
1154- options="{'no_open': True}"
1155- placeholder="Serial Number"
1156- attrs="{'invisible': [('state', '=', 'draft')]}"/>
1157- </group>
1158- <group colspan="4" attrs="{'invisible': [('state', 'in', ('serial', 'stock'))]}">
1159- <field
1160- name="message"
1161- nolabel="1"
1162- readonly="1"/>
1163- </group>
1164- <group colspan="4" attrs="{'invisible': [('state', 'in', ('message', 'serial', 'done'))]}">
1165- <p>We don't have this product in stock at the moment!</p>
1166- </group>
1167- <footer>
1168- <button
1169- name="router"
1170- string="Ok"
1171- type="object"
1172- states="message,serial,stock"
1173- class="oe_highlight"
1174- />
1175- </footer>
1176- </form>
1177- </field>
1178- </record>
1179+ <header>
1180+ <field
1181+ name="state"
1182+ class="oe_right"
1183+ widget="statusbar"
1184+ attrs="{'invisible': [('state', '=', 'message')]}"/>
1185+ </header>
1186+ <group string="Products" colspan="4" attrs="{'invisible': [('state', 'in', ('message', 'stock'))]}">
1187+ <field name="product_id" readonly="1" />
1188+ <field
1189+ name="serial"
1190+ class="oe_inline"
1191+ domain="[('product_id', '=', product_id), '&amp;', ('stock_available', '&gt;', 0)]"
1192+ options="{'no_open': True}"
1193+ placeholder="Serial Number"
1194+ attrs="{'invisible': [('state', '=', 'draft')]}"/>
1195+ </group>
1196+ <group colspan="4" attrs="{'invisible': [('state', 'in', ('serial', 'stock'))]}">
1197+ <field
1198+ name="message"
1199+ nolabel="1"
1200+ readonly="1"/>
1201+ </group>
1202+ <group colspan="4" attrs="{'invisible': [('state', 'in', ('message', 'serial', 'done'))]}">
1203+ <p>We don't have this product in stock at the moment!</p>
1204+ </group>
1205+ <footer>
1206+ <button
1207+ name="router"
1208+ string="Ok"
1209+ type="object"
1210+ states="message,serial,stock"
1211+ class="oe_highlight"
1212+ />
1213+ </footer>
1214+ </form>
1215+ </field>
1216+ </record>
1217
1218 <record id="action_contract_isp_package_configurator" model="ir.actions.act_window">
1219 <field name="name">Package Configurator</field>
1220@@ -150,9 +150,9 @@
1221 <field name="res_model">contract.service.configurator</field>
1222 <field name="view_type">form</field>
1223 <field name="view_mode">form</field>
1224- <field name="view_id" ref="contract_isp_package_configurator.view_contract_service_configurator" />
1225+ <field name="view_id" ref="contract_isp_package_configurator.view_contract_service_configurator" />
1226 <field name="target">new</field>
1227- <field name="context">{'default_contract_id': active_id}</field>
1228+ <field name="context">{'default_contract_id': active_id}</field>
1229 </record>
1230
1231 </data>

Subscribers

People subscribed via source and target branches