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
=== modified file 'msf_doc_import/wizard/wizard_delete_lines.py'
--- msf_doc_import/wizard/wizard_delete_lines.py 2014-01-13 16:51:04 +0000
+++ msf_doc_import/wizard/wizard_delete_lines.py 2014-05-02 09:09:28 +0000
@@ -2,7 +2,7 @@
2##############################################################################2##############################################################################
3#3#
4# OpenERP, Open Source Management Solution4# OpenERP, Open Source Management Solution
5# Copyright (C) 2011 TeMPO Consulting, MSF 5# Copyright (C) 2011 TeMPO Consulting, MSF
6#6#
7# This program is free software: you can redistribute it and/or modify7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as8# it under the terms of the GNU Affero General Public License as
@@ -43,21 +43,23 @@
43 * field with the quantity for the line43 * field with the quantity for the line
44 * domain to apply on lines (e.g. : only draft stock moves on picking)44 * domain to apply on lines (e.g. : only draft stock moves on picking)
45"""45"""
46DOCUMENT_DATA = {'product.list': ('product.list.line', 'list_id', 'product_ids', '', ''),46DOCUMENT_DATA = {
47 'return.claim': ('claim.product.line', 'claim_id_claim_product_line', 'product_line_ids_return_claim', 'qty_claim_product_line', ''),47 'product.list': ('product.list.line', 'list_id', 'product_ids', '', ''),
48 'composition.kit': ('composition.item', 'item_kit_id', 'composition_item_ids', 'item_qty', ''),48 'return.claim': ('claim.product.line', 'claim_id_claim_product_line', 'product_line_ids_return_claim', 'qty_claim_product_line', ''),
49 'purchase.order': ('purchase.order.line', 'order_id', 'order_line', 'product_qty', ''),49 'composition.kit': ('composition.item', 'item_kit_id', 'composition_item_ids', 'item_qty', ''),
50 'tender': ('tender.line', 'tender_id', 'tender_line_ids', 'qty', ''),50 'purchase.order': ('purchase.order.line', 'order_id', 'order_line', 'product_qty', ''),
51 'sale.order': ('sale.order.line', 'order_id', 'order_line', 'product_uom_qty', ''),51 'tender': ('tender.line', 'tender_id', 'tender_line_ids', 'qty', ''),
52 'supplier.catalogue': ('supplier.catalogue.line', 'catalogue_id', 'line_ids', 'min_qty', ''),52 'sale.order': ('sale.order.line', 'order_id', 'order_line', 'product_uom_qty', ''),
53 'stock.picking': ('stock.move', 'picking_id', 'move_lines', 'product_qty', '(\'state\', \'=\', \'draft\')'),53 'supplier.catalogue': ('supplier.catalogue.line', 'catalogue_id', 'line_ids', 'min_qty', ''),
54 'stock.warehouse.automatic.supply': ('stock.warehouse.automatic.supply.line', 'supply_id', 'line_ids', 'product_qty', ''),54 'stock.picking': ('stock.move', 'picking_id', 'move_lines', 'product_qty', '(\'state\', \'=\', \'draft\')'),
55 'stock.warehouse.order.cycle': ('stock.warehouse.order.cycle.line', 'order_cycle_id', 'product_ids', 'safety_stock', ''),55 'stock.warehouse.automatic.supply': ('stock.warehouse.automatic.supply.line', 'supply_id', 'line_ids', 'product_qty', ''),
56 'threshold.value': ('threshold.value.line', 'threshold_value_id', 'line_ids', '', ''),56 'stock.warehouse.order.cycle': ('stock.warehouse.order.cycle.line', 'order_cycle_id', 'product_ids', 'safety_stock', ''),
57 'stock.inventory': ('stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),57 'threshold.value': ('threshold.value.line', 'threshold_value_id', 'line_ids', '', ''),
58 'initial.stock.inventory': ('initial.stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),58 'stock.inventory': ('stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),
59 'real.average.consumption': ('real.average.consumption.line', 'rac_id', 'line_ids', 'consumed_qty', ''),59 'initial.stock.inventory': ('initial.stock.inventory.line', 'inventory_id', 'inventory_line_id', 'product_qty', ''),
60 'monthly.review.consumption': ('monthly.review.consumption.line', 'mrc_id', 'line_ids', 'fmc', ''),}60 'real.average.consumption': ('real.average.consumption.line', 'rac_id', 'line_ids', 'consumed_qty', ''),
61 'monthly.review.consumption': ('monthly.review.consumption.line', 'mrc_id', 'line_ids', 'fmc', ''),
62}
6163
6264
63def brl(self, cr, uid, ids, context=None):65def brl(self, cr, uid, ids, context=None):
@@ -74,9 +76,11 @@
74 if not obj[DOCUMENT_DATA.get(self._name)[2]]:76 if not obj[DOCUMENT_DATA.get(self._name)[2]]:
75 raise osv.except_osv(_('Error'), _('No line to remove'))77 raise osv.except_osv(_('Error'), _('No line to remove'))
7678
77 context.update({'active_id': ids[0],79 context.update({
78 'from_delete_wizard': True,80 'active_id': ids[0],
79 'active_model': self._name,})81 'from_delete_wizard': True,
82 'active_model': self._name,
83 })
8084
81 # Return the wizard to display lines to remove85 # Return the wizard to display lines to remove
82 return {'type': 'ir.actions.act_window',86 return {'type': 'ir.actions.act_window',
@@ -87,7 +91,7 @@
87 'context': context}91 'context': context}
8892
89"""93"""
90All the following documents will call the same button_remove_lines method 94All the following documents will call the same button_remove_lines method
91to remove some or all lines on documents.95to remove some or all lines on documents.
9296
93Documents which inherit from document.remove.line:97Documents which inherit from document.remove.line:
@@ -107,6 +111,7 @@
107 * Monthly consumption report111 * Monthly consumption report
108"""112"""
109113
114
110class product_list(osv.osv):115class product_list(osv.osv):
111 _name = 'product.list'116 _name = 'product.list'
112 _inherit = 'product.list'117 _inherit = 'product.list'
@@ -130,7 +135,11 @@
130 def button_remove_lines(self, cr, uid, ids, context=None):135 def button_remove_lines(self, cr, uid, ids, context=None):
131 for order in self.browse(cr, uid, ids, context=context):136 for order in self.browse(cr, uid, ids, context=context):
132 if order.rfq_ok and order.tender_id:137 if order.rfq_ok and order.tender_id:
133 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.'))138 raise osv.except_osv(
139 _('Warning'),
140 _('You cannot remove lines on a RfQ created by a tender. '
141 'Leave the lines with Unit price = 0.00 if you dont\'t have answer for them.'),
142 )
134143
135 return brl(self, cr, uid, ids, context=context)144 return brl(self, cr, uid, ids, context=context)
136145
@@ -281,6 +290,7 @@
281290
282"""291"""
283292
293
284def delete_fields_view_get(self, cr, uid, view_id, view_type, context=None):294def delete_fields_view_get(self, cr, uid, view_id, view_type, context=None):
285 '''295 '''
286 Check if a view exist for the object (self) and the view type (view_type)296 Check if a view exist for the object (self) and the view type (view_type)
@@ -302,11 +312,12 @@
302 view = data_obj.get_object_reference(cr, uid, 'msf_doc_import', view_name)312 view = data_obj.get_object_reference(cr, uid, 'msf_doc_import', view_name)
303 if view:313 if view:
304 res = view[1]314 res = view[1]
305 except ValueError as e:315 except ValueError:
306 res = None316 res = None
307317
308 return res318 return res
309319
320
310def noteditable_fields_view_get(res, view_type, context=None):321def noteditable_fields_view_get(res, view_type, context=None):
311 '''322 '''
312 Make the list of lines not editable323 Make the list of lines not editable
@@ -319,6 +330,10 @@
319 fields = root.xpath('/tree')330 fields = root.xpath('/tree')
320 for field in fields:331 for field in fields:
321 root.set('noteditable', 'True')332 root.set('noteditable', 'True')
333 if context.get('procurement_request'):
334 root.set('string', 'Internal request lines')
335 if context.get('rfq_ok'):
336 root.set('string', 'RfQ lines')
322 res['arch'] = etree.tostring(root)337 res['arch'] = etree.tostring(root)
323338
324 return res339 return res
@@ -346,6 +361,12 @@
346 _inherit = 'purchase.order.line'361 _inherit = 'purchase.order.line'
347362
348 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):363 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
364 if context is None:
365 context = {}
366
367 if context.get('initial_doc_id', False) and context.get('initial_doc_type', False) == 'purchase.order':
368 rfq_ok = self.pool.get('purchase.order').browse(cr, uid, context.get('initial_doc_id'), context=context).rfq_ok
369 context['rfq_ok'] = rfq_ok
349 view_id = delete_fields_view_get(self, cr, uid, view_id, view_type, context=context)370 view_id = delete_fields_view_get(self, cr, uid, view_id, view_type, context=context)
350 res = super(purchase_order_line, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)371 res = super(purchase_order_line, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
351 return noteditable_fields_view_get(res, view_type, context)372 return noteditable_fields_view_get(res, view_type, context)
@@ -373,6 +394,13 @@
373 _inherit = 'sale.order.line'394 _inherit = 'sale.order.line'
374395
375 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):396 def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
397 if context is None:
398 context = {}
399
400 if context.get('initial_doc_id', False) and context.get('initial_doc_type', False) == 'sale.order':
401 proc_request = self.pool.get('sale.order').browse(cr, uid, context.get('initial_doc_id'), context=context).procurement_request
402 context['procurement_request'] = proc_request
403
376 view_id = delete_fields_view_get(self, cr, uid, view_id, view_type, context=context)404 view_id = delete_fields_view_get(self, cr, uid, view_id, view_type, context=context)
377 res = super(sale_order_line, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)405 res = super(sale_order_line, self).fields_view_get(cr, uid, view_id, view_type, context=context, toolbar=toolbar, submenu=submenu)
378 return noteditable_fields_view_get(res, view_type, context)406 return noteditable_fields_view_get(res, view_type, context)
@@ -518,19 +546,13 @@
518 res['linked_field_name'] = DOCUMENT_DATA.get(context.get('active_model'))[1]546 res['linked_field_name'] = DOCUMENT_DATA.get(context.get('active_model'))[1]
519 res['qty_field'] = DOCUMENT_DATA.get(context.get('active_model'))[3]547 res['qty_field'] = DOCUMENT_DATA.get(context.get('active_model'))[3]
520548
521 if 'active_id' in context and 'active_model' in context and context.get('active_model') in DOCUMENT_DATA:549# if 'active_id' in context and 'active_model' in context and context.get('active_model') in DOCUMENT_DATA:
522 line_field = DOCUMENT_DATA.get(context.get('active_model'))[2]550# line_field = DOCUMENT_DATA.get(context.get('active_model'))[2]
523 lines = self.pool.get(res['initial_doc_type']).read(cr, uid, res['initial_doc_id'], [line_field], context=context)551# lines = self.pool.get(res['initial_doc_type']).read(cr, uid, res['initial_doc_id'], [line_field], context=context)
524 res['line_ids'] = lines[line_field]552# res['line_ids'] = lines[line_field]
525553
526 return res554 return res
527555
528 def remove_empty_lines(self, cr, uid, ids, context=None):
529 '''
530 Remove only empty lines
531 '''
532 return self.remove_all_lines(cr, uid, ids, context=context, remove_only_empty=True)
533
534 def remove_selected_lines(self, cr, uid, ids, context=None):556 def remove_selected_lines(self, cr, uid, ids, context=None):
535 '''557 '''
536 Remove only the selected lines558 Remove only the selected lines
@@ -547,37 +569,52 @@
547 for line in wiz.line_ids:569 for line in wiz.line_ids:
548 for l in line[2]:570 for l in line[2]:
549 line_ids.append(l)571 line_ids.append(l)
550 572
551 context['noraise'] = True573 context['noraise'] = True
552 line_obj.unlink(cr, uid, line_ids, context=context)574 line_obj.unlink(cr, uid, line_ids, context=context)
553575
554 return {'type': 'ir.actions.act_window_close'}576 return {'type': 'ir.actions.act_window_close'}
555577
556 def remove_all_lines(self, cr, uid, ids, context=None, remove_only_empty=False):578 def select_empty_lines(self, cr, uid, ids, context=None):
557 '''579 '''
558 Remove all lines of the initial document580 Add empty lines
581 '''
582 return self.select_all_lines(cr, uid, ids, context=context, select_only_empty=True)
583
584 def select_all_lines(self, cr, uid, ids, context=None, select_only_empty=False):
585 '''
586 Select all lines of the initial document
559 '''587 '''
560 context = context is None and {} or context588 context = context is None and {} or context
561 if isinstance(ids, (int, long)):589 if isinstance(ids, (int, long)):
562 ids = [ids]590 ids = [ids]
563591
564 for wiz in self.browse(cr, uid, ids, context=context):592 for wiz in self.browse(cr, uid, ids, context=context):
565 if remove_only_empty and not wiz.qty_field:593 if select_only_empty and not wiz.qty_field:
566 raise osv.except_osv(_('Error'), _('The remove empty lines is not available for this document'))594 raise osv.except_osv(_('Error'), _('The select empty lines is not available for this document'))
567595
568 line_obj = self.pool.get(wiz.to_remove_type)596 line_obj = self.pool.get(wiz.to_remove_type)
569 if remove_only_empty:597 if select_only_empty:
570 line_ids = line_obj.search(cr, uid, [(wiz.linked_field_name, '=', wiz.initial_doc_id), (wiz.qty_field, '=', 0.00)], context=context)598 line_ids = line_obj.search(cr, uid, [(wiz.linked_field_name, '=', wiz.initial_doc_id), (wiz.qty_field, '=', 0.00)], context=context)
571 else:599 else:
572 line_ids = line_obj.search(cr, uid, [(wiz.linked_field_name, '=', wiz.initial_doc_id)], context=context)600 line_ids = line_obj.search(cr, uid, [(wiz.linked_field_name, '=', wiz.initial_doc_id)], context=context)
573 line_obj.unlink(cr, uid, line_ids, context=context)601
574602 self.write(cr, uid, [wiz.id], {'line_ids': line_ids}, context=context)
575 return {'type': 'ir.actions.act_window_close'}603
604 return {
605 'type': 'ir.actions.act_window',
606 'res_model': self._name,
607 'view_type': 'form',
608 'view_mode': 'form',
609 'res_id': ids and wiz.id or False,
610 'context': context,
611 'target': 'new',
612 }
576613
577 def fields_get(self, cr, uid, fields=None, context=None):614 def fields_get(self, cr, uid, fields=None, context=None):
578 '''615 '''
579 On this fields_get method, we build the line_ids field.616 On this fields_get method, we build the line_ids field.
580 The line_ids field is defined as a text field but, for users, this 617 The line_ids field is defined as a text field but, for users, this
581 field should be displayed as a many2many that allows us to select618 field should be displayed as a many2many that allows us to select
582 lines of document to remove.619 lines of document to remove.
583 The line_ids field is changed to a many2many field according to the620 The line_ids field is changed to a many2many field according to the
@@ -594,13 +631,13 @@
594 domain = "[('%s', '=', initial_doc_id)]" % ddata[1]631 domain = "[('%s', '=', initial_doc_id)]" % ddata[1]
595 else:632 else:
596 domain = "[%s, ('%s', '=', initial_doc_id)]" % (ddata[4], ddata[1])633 domain = "[%s, ('%s', '=', initial_doc_id)]" % (ddata[4], ddata[1])
597 res.update(line_ids={'related_columns': ['wiz_id', 'line_id'], 634 res.update(line_ids={'related_columns': ['wiz_id', 'line_id'],
598 'relation': line_obj, 635 'relation': line_obj,
599 'string': 'Lines to remove', 636 'string': 'Lines to remove',
600 'context': context, 637 'context': context,
601 'third_table': '%sto_remove' % line_obj.replace('.', '_'), 638 'third_table': '%sto_remove' % line_obj.replace('.', '_'),
602 'selectable': True, 639 'selectable': True,
603 'type': 'many2many', 640 'type': 'many2many',
604 'domain': "%s" % domain})641 'domain': "%s" % domain})
605642
606 return res643 return res
607644
=== modified file 'msf_doc_import/wizard/wizard_delete_lines_view.xml'
--- msf_doc_import/wizard/wizard_delete_lines_view.xml 2014-01-02 13:14:45 +0000
+++ msf_doc_import/wizard/wizard_delete_lines_view.xml 2014-05-02 09:09:28 +0000
@@ -14,13 +14,13 @@
14 <field name="linked_field_name" invisible="True" />14 <field name="linked_field_name" invisible="True" />
15 <field name="qty_field" invisible="True" />15 <field name="qty_field" invisible="True" />
16 <separator colspan="4" string="Lines to remove" />16 <separator colspan="4" string="Lines to remove" />
17 <field name="line_ids" colspan="4" nolabel="1" context="{'from_delete_wizard': True}" mode="tree" />17 <button name="select_all_lines" type="object" icon="gtk-go-down" string="Select all lines" colspan="2" />
18 <button name="select_empty_lines" type="object" icon="gtk-go-down" string="Select Qty=0 lines" attrs="{'invisible': [('qty_field', '=', False)]}" colspan="2" />
19 <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" />
18 <separator colspan="4" string="Actions" />20 <separator colspan="4" string="Actions" />
19 <group colspan="4" col="4" >21 <group colspan="4" col="4" >
20 <button special="cancel" icon="gtk-cancel" string="Close window" />22 <button special="cancel" icon="gtk-cancel" string="Close window" colspan="2" />
21 <button name="remove_selected_lines" type="object" icon="gtk-execute" string="Remove selected lines" />23 <button name="remove_selected_lines" type="object" icon="gtk-execute" string="Remove selected lines" colspan="2" />
22 <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?" />
23 <button name="remove_empty_lines" type="object" icon="gtk-execute" string="Remove Qty=0 lines" attrs="{'invisible': [('qty_field', '=', False)]}" />
24 </group>24 </group>
25 </form>25 </form>
26 </field>26 </field>

Subscribers

People subscribed via source and target branches