From f3b695ae53a143478e8845fec11968281f7d752d Mon Sep 17 00:00:00 2001 From: "Quentin (OpenERP)" Date: Mon, 7 May 2012 13:12:22 +0200 Subject: [PATCH] [IMP] stock, sale, purchase: some code optimization and few enhancements related to split of stock.picking into several objects bzr revid: qdp-launchpad@openerp.com-20120507111222-2wnmkgiluiqwti82 --- addons/purchase/purchase.py | 2 +- addons/purchase/stock_view.xml | 6 ++--- addons/sale/sale.py | 2 +- addons/stock/stock.py | 7 +----- addons/stock/stock_workflow.xml | 3 +-- addons/stock/wizard/stock_partial_picking.py | 9 +++++-- .../wizard/stock_partial_picking_view.xml | 1 + addons/stock/wizard/stock_return_picking.py | 24 +++++++++++-------- 8 files changed, 29 insertions(+), 25 deletions(-) diff --git a/addons/purchase/purchase.py b/addons/purchase/purchase.py index 708a35d4351..ea90baae99c 100644 --- a/addons/purchase/purchase.py +++ b/addons/purchase/purchase.py @@ -174,7 +174,7 @@ class purchase_order(osv.osv): 'validator' : fields.many2one('res.users', 'Validated by', readonly=True), 'notes': fields.text('Notes'), 'invoice_ids': fields.many2many('account.invoice', 'purchase_invoice_rel', 'purchase_id', 'invoice_id', 'Invoices', help="Invoices generated for a purchase order"), - 'picking_ids': fields.one2many('stock.picking', 'purchase_id', 'Picking List', readonly=True, help="This is the list of picking list that have been generated for this purchase"), + 'picking_ids': fields.one2many('stock.picking.in', 'purchase_id', 'Picking List', readonly=True, help="This is the list of incomming shipments that have been generated for this purchase order."), 'shipped':fields.boolean('Received', readonly=True, select=True, help="It indicates that a picking has been done"), 'shipped_rate': fields.function(_shipped_rate, string='Received', type='float'), 'invoiced': fields.function(_invoiced, string='Invoiced & Paid', type='boolean', help="It indicates that an invoice has been paid"), diff --git a/addons/purchase/stock_view.xml b/addons/purchase/stock_view.xml index 11a3b1575f5..eba8aa5fc51 100644 --- a/addons/purchase/stock_view.xml +++ b/addons/purchase/stock_view.xml @@ -28,7 +28,7 @@ domain="[('purchase_id', '=', active_id)]" id="act_purchase_order_2_stock_picking" name="Receptions" - res_model="stock.picking" + res_model="stock.picking.in" src_model="purchase.order" context="{'default_purchase_id': active_id, 'contact_display': 'partner', 'default_type': 'in'}" /> @@ -47,7 +47,7 @@ Incoming Picking Inherited - stock.picking + stock.picking.in form @@ -60,7 +60,7 @@ stock.picking.in.search - stock.picking + stock.picking.in search diff --git a/addons/sale/sale.py b/addons/sale/sale.py index c2ee42b6fca..8eca600e780 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -238,7 +238,7 @@ class sale_order(osv.osv): 'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'draft': [('readonly', False)]}), 'invoice_ids': fields.many2many('account.invoice', 'sale_order_invoice_rel', 'order_id', 'invoice_id', 'Invoices', readonly=True, help="This is the list of invoices that have been generated for this sales order. The same sales order may have been invoiced in several times (by line for example)."), - 'picking_ids': fields.one2many('stock.picking', 'sale_id', 'Related Picking', readonly=True, help="This is a list of picking that has been generated for this sales order."), + 'picking_ids': fields.one2many('stock.picking.out', 'sale_id', 'Related Picking', readonly=True, help="This is a list of delivery orders that has been generated for this sales order."), 'shipped': fields.boolean('Delivered', readonly=True, help="It indicates that the sales order has been delivered. This field is updated only after the scheduler(s) have been launched."), 'picked_rate': fields.function(_picked_rate, string='Picked', type='float'), 'invoiced_rate': fields.function(_invoiced_rate, string='Invoiced', type='float'), diff --git a/addons/stock/stock.py b/addons/stock/stock.py index d878f4abb90..66737210455 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -672,15 +672,10 @@ class stock_picking(osv.osv): ] def action_process(self, cr, uid, ids, context=None): - mod_obj = self.pool.get('ir.model.data') - model_data_ids = mod_obj.search(cr, uid, [('model','=','ir.ui.view'),('name','=','stock_partial_picking_form')], context=context) - resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id'] return { 'view_type': 'form', 'view_mode': 'form', 'res_model': 'stock.partial.picking', - 'views': [(resource_id,'form')], - 'view_id': resource_id, 'type': 'ir.actions.act_window', 'target': 'new', 'context': context, @@ -738,9 +733,9 @@ class stock_picking(osv.osv): """ Changes state of picking to available if all moves are confirmed. @return: True """ - wf_service = netsvc.LocalService("workflow") for pick in self.browse(cr, uid, ids): if pick.state == 'draft': + wf_service = netsvc.LocalService("workflow") wf_service.trg_validate(uid, 'stock.picking', pick.id, 'button_confirm', cr) move_ids = [x.id for x in pick.move_lines if x.state == 'confirmed'] if not move_ids: diff --git a/addons/stock/stock_workflow.xml b/addons/stock/stock_workflow.xml index d2e905a2789..14b5babdea8 100644 --- a/addons/stock/stock_workflow.xml +++ b/addons/stock/stock_workflow.xml @@ -51,12 +51,11 @@ button_confirm - not test_assigned() - + diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py index 56e67698a9b..79f1f75910b 100644 --- a/addons/stock/wizard/stock_partial_picking.py +++ b/addons/stock/wizard/stock_partial_picking.py @@ -74,6 +74,7 @@ class stock_partial_picking(osv.osv_memory): } def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False): + #override of fields_view_get in order to change the label of the process button and the separator accordingly to the shipping type if context is None: context={} res = super(stock_partial_picking, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu) @@ -97,10 +98,14 @@ class stock_partial_picking(osv.osv_memory): if context is None: context = {} res = super(stock_partial_picking, self).default_get(cr, uid, fields, context=context) picking_ids = context.get('active_ids', []) - if not picking_ids or (not context.get('active_model') == 'stock.picking') \ - or len(picking_ids) != 1: + if not picking_ids or len(picking_ids) != 1: # Partial Picking Processing may only be done for one picking at a time return res + # The check about active_model is there in case the client mismatched the context during propagation of it + # (already seen in previous bug where context passed was containing ir.ui.menu as active_model and the menu + # ID as active_id). Though this should be fixed in clients now, this place is sensitive enough to ensure the + # consistancy of the context. + assert context.get('active_model') in ('stock.picking', 'stock.picking.in', 'stock.picking.out'), 'Bad context propagation' picking_id, = picking_ids if 'picking_id' in fields: res.update(picking_id=picking_id) diff --git a/addons/stock/wizard/stock_partial_picking_view.xml b/addons/stock/wizard/stock_partial_picking_view.xml index 54866aafb75..c57c6c400e4 100644 --- a/addons/stock/wizard/stock_partial_picking_view.xml +++ b/addons/stock/wizard/stock_partial_picking_view.xml @@ -9,6 +9,7 @@ new + stock.partial.picking.form stock.partial.picking diff --git a/addons/stock/wizard/stock_return_picking.py b/addons/stock/wizard/stock_return_picking.py index a82a7442eed..df14c976c11 100644 --- a/addons/stock/wizard/stock_return_picking.py +++ b/addons/stock/wizard/stock_return_picking.py @@ -161,7 +161,7 @@ class stock_return_picking(osv.osv_memory): else: new_type = 'internal' new_picking = pick_obj.copy(cr, uid, pick.id, { - 'name':'%s-return' % pick.name, + 'name': _('%s-return') % pick.name, 'move_lines': [], 'state':'draft', 'type': new_type, @@ -202,16 +202,20 @@ class stock_return_picking(osv.osv_memory): wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr) pick_obj.force_assign(cr, uid, [new_picking], context) # Update view id in context, lp:702939 - action_list = { - 'out': 'action_picking_tree', - 'in': 'action_picking_tree4', - 'internal': 'action_picking_tree6', + model_list = { + 'out': 'stock.picking.out', + 'in': 'stock.picking.in', + 'internal': 'stock.picking', + } + return { + 'domain': "[('id', 'in', ["+str(new_picking)+"])]", + 'name': _('Returned Picking'), + 'view_type':'form', + 'view_mode':'tree,form', + 'res_model': model_list.get(new_type, 'stock.picking'), + 'type':'ir.actions.act_window', + 'context':context, } - res = model_obj.get_object_reference(cr, uid, 'stock', action_list.get(new_type, 'action_picking_tree6')) - id = res and res[1] or False - result = act_obj.read(cr, uid, [id], context=context)[0] - result['domain'] = "[('id', 'in', ["+str(new_picking)+"])]" - return result stock_return_picking()