picking_status: improve perf, handle picking.state == 'cancel', fix typos
This commit is contained in:
@@ -11,34 +11,40 @@ class SaleOrder(models.Model):
|
||||
warehouse_id = fields.Many2one(track_visibility='onchange')
|
||||
incoterm = fields.Many2one(track_visibility='onchange')
|
||||
picking_status = fields.Selection([
|
||||
('deliverd', 'Fully Deliverd'),
|
||||
('partialy_delivered', 'Partialy Delivered'),
|
||||
('delivered', 'Fully Delivered'),
|
||||
('partially_delivered', 'Partially Delivered'),
|
||||
('to_deliver', 'To Deliver'),
|
||||
('cancel', 'Delivery Cancelled'),
|
||||
('no', 'Nothing to Deliver')
|
||||
], string='Picking Status', compute='_get_delivered', store=True, readonly=True)
|
||||
], string='Picking Status', compute='_compute_picking_status',
|
||||
store=True, readonly=True)
|
||||
|
||||
@api.depends('state', 'picking_ids.state')
|
||||
def _get_delivered(self):
|
||||
def _compute_picking_status(self):
|
||||
"""
|
||||
Compute the picking status for the SO. Possible statuses:
|
||||
- no: if the SO is not in status 'sale' or 'done', we consider that there is nothing to
|
||||
deliver. This is also the default value if the conditions of no other status is met.
|
||||
- delivered: if all pickings are done.
|
||||
- Partialy Done : If at least one picking is done.
|
||||
- To deliver : if all pickings are in confirmed, assigned or waiting state.
|
||||
- no: if the SO is not in status 'sale' nor 'done', we consider that
|
||||
there is nothing to deliver. This is also the default value if the
|
||||
conditions of no other status is met.
|
||||
- cancel: all pickings are cancelled
|
||||
- delivered: if all pickings are done or cancel.
|
||||
- partially_delivered: If at least one picking is done.
|
||||
- to_deliver: if all pickings are in confirmed, assigned, waiting or
|
||||
cancel state.
|
||||
"""
|
||||
|
||||
for order in self:
|
||||
|
||||
if order.state not in ('sale', 'done') or not order.picking_ids:
|
||||
picking_status = 'no'
|
||||
elif all(picking.state == 'done' for picking in order.picking_ids):
|
||||
picking_status = 'deliverd'
|
||||
elif any(picking.state == 'done' for picking in order.picking_ids):
|
||||
picking_status = 'partialy_delivered'
|
||||
elif all(picking.state in ('confirmed', 'assigned', 'waiting') for picking in order.picking_ids):
|
||||
picking_status = 'to_deliver'
|
||||
else:
|
||||
picking_status = 'no'
|
||||
|
||||
picking_status = 'no'
|
||||
if order.state in ('sale', 'done') and order.picking_ids:
|
||||
pstates = [
|
||||
picking.state for picking in order.picking_ids]
|
||||
if all([state == 'cancel' for state in pstates]):
|
||||
picking_status = 'cancel'
|
||||
elif all([state in ('done', 'cancel') for state in pstates]):
|
||||
picking_status = 'delivered'
|
||||
elif any([state == 'done' for state in pstates]):
|
||||
picking_status = 'partially_delivered'
|
||||
elif all([
|
||||
state in ('confirmed', 'assigned', 'waiting', 'cancel')
|
||||
for state in pstates]):
|
||||
picking_status = 'to_deliver'
|
||||
order.picking_status = picking_status
|
||||
|
||||
Reference in New Issue
Block a user