[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
This commit is contained in:
Quentin (OpenERP) 2012-05-07 13:12:22 +02:00
parent b08c501123
commit f3b695ae53
8 changed files with 29 additions and 25 deletions

View File

@ -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"),

View File

@ -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 @@
<record id="stock_picking_in_inherit_purchase" model="ir.ui.view">
<field name="name">Incoming Picking Inherited</field>
<field name="model">stock.picking</field>
<field name="model">stock.picking.in</field>
<field name="type">form</field>
<field name="inherit_id" ref="stock.view_picking_in_form"/>
<field name="arch" type="xml">
@ -60,7 +60,7 @@
<!-- Picking to Invoice -->
<record id="view_picking_in_search_picking_to_invoice" model="ir.ui.view">
<field name="name">stock.picking.in.search</field>
<field name="model">stock.picking</field>
<field name="model">stock.picking.in</field>
<field name="type">search</field>
<field name="arch" type="xml">
<search string="Picking to Invoice">

View File

@ -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'),

View File

@ -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:

View File

@ -51,12 +51,11 @@
<field name="act_to" ref="act_confirmed"/>
<field name="signal">button_confirm</field>
</record>
<record id="trans_confirmed_assigned_back" model="workflow.transition">
<field name="act_from" ref="act_assigned"/>
<field name="act_to" ref="act_confirmed"/>
<field name="condition">not test_assigned()</field>
</record>
</record>
<record id="trans_confirmed_assigned" model="workflow.transition">
<field name="act_from" ref="act_confirmed"/>
<field name="act_to" ref="act_assigned"/>

View File

@ -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)

View File

@ -9,6 +9,7 @@
<field name="target">new</field>
</record>
<!-- this view of stock.partial.picking wizard is dedicated to internal picking. The fields_view_get is ovveridden in order to change the label of the process button and the separator. -->
<record id="stock_partial_picking_form" model="ir.ui.view">
<field name="name">stock.partial.picking.form</field>
<field name="model">stock.partial.picking</field>

View File

@ -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()