Merge lp:~unifield-team/unifield-wm/uftp-120 into lp:unifield-wm

Proposed by jftempo
Status: Merged
Merged at revision: 2144
Proposed branch: lp:~unifield-team/unifield-wm/uftp-120
Merge into: lp:unifield-wm
Diff against target: 288 lines (+92/-55)
2 files modified
msf_doc_import/wizard/wizard_delete_lines.py (+87/-50)
msf_doc_import/wizard/wizard_delete_lines_view.xml (+5/-5)
To merge this branch: bzr merge lp:~unifield-team/unifield-wm/uftp-120
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+217552@code.launchpad.net
To post a comment you must log in.
2123. By Quentin THEURET @Amaris

UFTP-120 [FIX] Delete multiple wizard: Put the good on views for IR and RfQ

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'msf_doc_import/wizard/wizard_delete_lines.py'
2--- msf_doc_import/wizard/wizard_delete_lines.py 2014-01-13 16:51:04 +0000
3+++ msf_doc_import/wizard/wizard_delete_lines.py 2014-05-02 09:09:28 +0000
4@@ -2,7 +2,7 @@
5 ##############################################################################
6 #
7 # OpenERP, Open Source Management Solution
8-# Copyright (C) 2011 TeMPO Consulting, MSF
9+# Copyright (C) 2011 TeMPO Consulting, MSF
10 #
11 # This program is free software: you can redistribute it and/or modify
12 # it under the terms of the GNU Affero General Public License as
13@@ -43,21 +43,23 @@
14 * field with the quantity for the line
15 * domain to apply on lines (e.g. : only draft stock moves on picking)
16 """
17-DOCUMENT_DATA = {'product.list': ('product.list.line', 'list_id', 'product_ids', '', ''),
18- 'return.claim': ('claim.product.line', 'claim_id_claim_product_line', 'product_line_ids_return_claim', 'qty_claim_product_line', ''),
19- 'composition.kit': ('composition.item', 'item_kit_id', 'composition_item_ids', 'item_qty', ''),
20- 'purchase.order': ('purchase.order.line', 'order_id', 'order_line', 'product_qty', ''),
21- 'tender': ('tender.line', 'tender_id', 'tender_line_ids', 'qty', ''),
22- 'sale.order': ('sale.order.line', 'order_id', 'order_line', 'product_uom_qty', ''),
23- 'supplier.catalogue': ('supplier.catalogue.line', 'catalogue_id', 'line_ids', 'min_qty', ''),
24- 'stock.picking': ('stock.move', 'picking_id', 'move_lines', 'product_qty', '(\'state\', \'=\', \'draft\')'),
25- 'stock.warehouse.automatic.supply': ('stock.warehouse.automatic.supply.line', 'supply_id', 'line_ids', 'product_qty', ''),
26- 'stock.warehouse.order.cycle': ('stock.warehouse.order.cycle.line', 'order_cycle_id', 'product_ids', 'safety_stock', ''),
27- 'threshold.value': ('threshold.value.line', 'threshold_value_id', 'line_ids', '', ''),
28- 'stock.inventory': ('stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),
29- 'initial.stock.inventory': ('initial.stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),
30- 'real.average.consumption': ('real.average.consumption.line', 'rac_id', 'line_ids', 'consumed_qty', ''),
31- 'monthly.review.consumption': ('monthly.review.consumption.line', 'mrc_id', 'line_ids', 'fmc', ''),}
32+DOCUMENT_DATA = {
33+ 'product.list': ('product.list.line', 'list_id', 'product_ids', '', ''),
34+ 'return.claim': ('claim.product.line', 'claim_id_claim_product_line', 'product_line_ids_return_claim', 'qty_claim_product_line', ''),
35+ 'composition.kit': ('composition.item', 'item_kit_id', 'composition_item_ids', 'item_qty', ''),
36+ 'purchase.order': ('purchase.order.line', 'order_id', 'order_line', 'product_qty', ''),
37+ 'tender': ('tender.line', 'tender_id', 'tender_line_ids', 'qty', ''),
38+ 'sale.order': ('sale.order.line', 'order_id', 'order_line', 'product_uom_qty', ''),
39+ 'supplier.catalogue': ('supplier.catalogue.line', 'catalogue_id', 'line_ids', 'min_qty', ''),
40+ 'stock.picking': ('stock.move', 'picking_id', 'move_lines', 'product_qty', '(\'state\', \'=\', \'draft\')'),
41+ 'stock.warehouse.automatic.supply': ('stock.warehouse.automatic.supply.line', 'supply_id', 'line_ids', 'product_qty', ''),
42+ 'stock.warehouse.order.cycle': ('stock.warehouse.order.cycle.line', 'order_cycle_id', 'product_ids', 'safety_stock', ''),
43+ 'threshold.value': ('threshold.value.line', 'threshold_value_id', 'line_ids', '', ''),
44+ 'stock.inventory': ('stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),
45+ 'initial.stock.inventory': ('initial.stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),
46+ 'real.average.consumption': ('real.average.consumption.line', 'rac_id', 'line_ids', 'consumed_qty', ''),
47+ 'monthly.review.consumption': ('monthly.review.consumption.line', 'mrc_id', 'line_ids', 'fmc', ''),
48+}
49
50
51 def brl(self, cr, uid, ids, context=None):
52@@ -74,9 +76,11 @@
53 if not obj[DOCUMENT_DATA.get(self._name)[2]]:
54 raise osv.except_osv(_('Error'), _('No line to remove'))
55
56- context.update({'active_id': ids[0],
57- 'from_delete_wizard': True,
58- 'active_model': self._name,})
59+ context.update({
60+ 'active_id': ids[0],
61+ 'from_delete_wizard': True,
62+ 'active_model': self._name,
63+ })
64
65 # Return the wizard to display lines to remove
66 return {'type': 'ir.actions.act_window',
67@@ -87,7 +91,7 @@
68 'context': context}
69
70 """
71-All the following documents will call the same button_remove_lines method
72+All the following documents will call the same button_remove_lines method
73 to remove some or all lines on documents.
74
75 Documents which inherit from document.remove.line:
76@@ -107,6 +111,7 @@
77 * Monthly consumption report
78 """
79
80+
81 class product_list(osv.osv):
82 _name = 'product.list'
83 _inherit = 'product.list'
84@@ -130,7 +135,11 @@
85 def button_remove_lines(self, cr, uid, ids, context=None):
86 for order in self.browse(cr, uid, ids, context=context):
87 if order.rfq_ok and order.tender_id:
88- raise osv.except_osv(_('Warning'), _('You cannot remove lines on a RfQ created by a tender. Leave the lines with Unit price = 0.00 if you dont\'t have answer for them.'))
89+ raise osv.except_osv(
90+ _('Warning'),
91+ _('You cannot remove lines on a RfQ created by a tender. '
92+ 'Leave the lines with Unit price = 0.00 if you dont\'t have answer for them.'),
93+ )
94
95 return brl(self, cr, uid, ids, context=context)
96
97@@ -281,6 +290,7 @@
98
99 """
100
101+
102 def delete_fields_view_get(self, cr, uid, view_id, view_type, context=None):
103 '''
104 Check if a view exist for the object (self) and the view type (view_type)
105@@ -302,11 +312,12 @@
106 view = data_obj.get_object_reference(cr, uid, 'msf_doc_import', view_name)
107 if view:
108 res = view[1]
109- except ValueError as e:
110+ except ValueError:
111 res = None
112
113 return res
114
115+
116 def noteditable_fields_view_get(res, view_type, context=None):
117 '''
118 Make the list of lines not editable
119@@ -319,6 +330,10 @@
120 fields = root.xpath('/tree')
121 for field in fields:
122 root.set('noteditable', 'True')
123+ if context.get('procurement_request'):
124+ root.set('string', 'Internal request lines')
125+ if context.get('rfq_ok'):
126+ root.set('string', 'RfQ lines')
127 res['arch'] = etree.tostring(root)
128
129 return res
130@@ -346,6 +361,12 @@
131 _inherit = 'purchase.order.line'
132
133 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
134+ if context is None:
135+ context = {}
136+
137+ if context.get('initial_doc_id', False) and context.get('initial_doc_type', False) == 'purchase.order':
138+ rfq_ok = self.pool.get('purchase.order').browse(cr, uid, context.get('initial_doc_id'), context=context).rfq_ok
139+ context['rfq_ok'] = rfq_ok
140 view_id = delete_fields_view_get(self, cr, uid, view_id, view_type, context=context)
141 res = super(purchase_order_line, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
142 return noteditable_fields_view_get(res, view_type, context)
143@@ -373,6 +394,13 @@
144 _inherit = 'sale.order.line'
145
146 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
147+ if context is None:
148+ context = {}
149+
150+ if context.get('initial_doc_id', False) and context.get('initial_doc_type', False) == 'sale.order':
151+ proc_request = self.pool.get('sale.order').browse(cr, uid, context.get('initial_doc_id'), context=context).procurement_request
152+ context['procurement_request'] = proc_request
153+
154 view_id = delete_fields_view_get(self, cr, uid, view_id, view_type, context=context)
155 res = super(sale_order_line, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
156 return noteditable_fields_view_get(res, view_type, context)
157@@ -518,19 +546,13 @@
158 res['linked_field_name'] = DOCUMENT_DATA.get(context.get('active_model'))[1]
159 res['qty_field'] = DOCUMENT_DATA.get(context.get('active_model'))[3]
160
161- if 'active_id' in context and 'active_model' in context and context.get('active_model') in DOCUMENT_DATA:
162- line_field = DOCUMENT_DATA.get(context.get('active_model'))[2]
163- lines = self.pool.get(res['initial_doc_type']).read(cr, uid, res['initial_doc_id'], [line_field], context=context)
164- res['line_ids'] = lines[line_field]
165+# if 'active_id' in context and 'active_model' in context and context.get('active_model') in DOCUMENT_DATA:
166+# line_field = DOCUMENT_DATA.get(context.get('active_model'))[2]
167+# lines = self.pool.get(res['initial_doc_type']).read(cr, uid, res['initial_doc_id'], [line_field], context=context)
168+# res['line_ids'] = lines[line_field]
169
170 return res
171
172- def remove_empty_lines(self, cr, uid, ids, context=None):
173- '''
174- Remove only empty lines
175- '''
176- return self.remove_all_lines(cr, uid, ids, context=context, remove_only_empty=True)
177-
178 def remove_selected_lines(self, cr, uid, ids, context=None):
179 '''
180 Remove only the selected lines
181@@ -547,37 +569,52 @@
182 for line in wiz.line_ids:
183 for l in line[2]:
184 line_ids.append(l)
185-
186+
187 context['noraise'] = True
188 line_obj.unlink(cr, uid, line_ids, context=context)
189
190 return {'type': 'ir.actions.act_window_close'}
191
192- def remove_all_lines(self, cr, uid, ids, context=None, remove_only_empty=False):
193- '''
194- Remove all lines of the initial document
195+ def select_empty_lines(self, cr, uid, ids, context=None):
196+ '''
197+ Add empty lines
198+ '''
199+ return self.select_all_lines(cr, uid, ids, context=context, select_only_empty=True)
200+
201+ def select_all_lines(self, cr, uid, ids, context=None, select_only_empty=False):
202+ '''
203+ Select all lines of the initial document
204 '''
205 context = context is None and {} or context
206 if isinstance(ids, (int, long)):
207 ids = [ids]
208
209 for wiz in self.browse(cr, uid, ids, context=context):
210- if remove_only_empty and not wiz.qty_field:
211- raise osv.except_osv(_('Error'), _('The remove empty lines is not available for this document'))
212+ if select_only_empty and not wiz.qty_field:
213+ raise osv.except_osv(_('Error'), _('The select empty lines is not available for this document'))
214
215 line_obj = self.pool.get(wiz.to_remove_type)
216- if remove_only_empty:
217+ if select_only_empty:
218 line_ids = line_obj.search(cr, uid, [(wiz.linked_field_name, '=', wiz.initial_doc_id), (wiz.qty_field, '=', 0.00)], context=context)
219 else:
220 line_ids = line_obj.search(cr, uid, [(wiz.linked_field_name, '=', wiz.initial_doc_id)], context=context)
221- line_obj.unlink(cr, uid, line_ids, context=context)
222-
223- return {'type': 'ir.actions.act_window_close'}
224+
225+ self.write(cr, uid, [wiz.id], {'line_ids': line_ids}, context=context)
226+
227+ return {
228+ 'type': 'ir.actions.act_window',
229+ 'res_model': self._name,
230+ 'view_type': 'form',
231+ 'view_mode': 'form',
232+ 'res_id': ids and wiz.id or False,
233+ 'context': context,
234+ 'target': 'new',
235+ }
236
237 def fields_get(self, cr, uid, fields=None, context=None):
238 '''
239 On this fields_get method, we build the line_ids field.
240- The line_ids field is defined as a text field but, for users, this
241+ The line_ids field is defined as a text field but, for users, this
242 field should be displayed as a many2many that allows us to select
243 lines of document to remove.
244 The line_ids field is changed to a many2many field according to the
245@@ -594,13 +631,13 @@
246 domain = "[('%s', '=', initial_doc_id)]" % ddata[1]
247 else:
248 domain = "[%s, ('%s', '=', initial_doc_id)]" % (ddata[4], ddata[1])
249- res.update(line_ids={'related_columns': ['wiz_id', 'line_id'],
250- 'relation': line_obj,
251- 'string': 'Lines to remove',
252- 'context': context,
253- 'third_table': '%sto_remove' % line_obj.replace('.', '_'),
254- 'selectable': True,
255- 'type': 'many2many',
256+ res.update(line_ids={'related_columns': ['wiz_id', 'line_id'],
257+ 'relation': line_obj,
258+ 'string': 'Lines to remove',
259+ 'context': context,
260+ 'third_table': '%sto_remove' % line_obj.replace('.', '_'),
261+ 'selectable': True,
262+ 'type': 'many2many',
263 'domain': "%s" % domain})
264
265 return res
266
267=== modified file 'msf_doc_import/wizard/wizard_delete_lines_view.xml'
268--- msf_doc_import/wizard/wizard_delete_lines_view.xml 2014-01-02 13:14:45 +0000
269+++ msf_doc_import/wizard/wizard_delete_lines_view.xml 2014-05-02 09:09:28 +0000
270@@ -14,13 +14,13 @@
271 <field name="linked_field_name" invisible="True" />
272 <field name="qty_field" invisible="True" />
273 <separator colspan="4" string="Lines to remove" />
274- <field name="line_ids" colspan="4" nolabel="1" context="{'from_delete_wizard': True}" mode="tree" />
275+ <button name="select_all_lines" type="object" icon="gtk-go-down" string="Select all lines" colspan="2" />
276+ <button name="select_empty_lines" type="object" icon="gtk-go-down" string="Select Qty=0 lines" attrs="{'invisible': [('qty_field', '=', False)]}" colspan="2" />
277+ <field name="line_ids" colspan="4" nolabel="1" context="{'from_delete_wizard': True, 'initial_doc_id': initial_doc_id, 'initial_doc_type': initial_doc_type}" mode="tree" />
278 <separator colspan="4" string="Actions" />
279 <group colspan="4" col="4" >
280- <button special="cancel" icon="gtk-cancel" string="Close window" />
281- <button name="remove_selected_lines" type="object" icon="gtk-execute" string="Remove selected lines" />
282- <button name="remove_all_lines" type="object" icon="gtk-execute" string="Remove all lines" confirm="Are you sure that you want to remove all lines?" />
283- <button name="remove_empty_lines" type="object" icon="gtk-execute" string="Remove Qty=0 lines" attrs="{'invisible': [('qty_field', '=', False)]}" />
284+ <button special="cancel" icon="gtk-cancel" string="Close window" colspan="2" />
285+ <button name="remove_selected_lines" type="object" icon="gtk-execute" string="Remove selected lines" colspan="2" />
286 </group>
287 </form>
288 </field>

Subscribers

People subscribed via source and target branches