diff --git a/sale_stock_usability/sale_stock.py b/sale_stock_usability/sale_stock.py index 112253a..a33ac23 100644 --- a/sale_stock_usability/sale_stock.py +++ b/sale_stock_usability/sale_stock.py @@ -2,7 +2,7 @@ # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields +from odoo import models, fields, api class SaleOrder(models.Model): @@ -10,3 +10,35 @@ 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'), + ('to deliver', 'To Deliver'), + ('no', 'Nothing to Deliver') + ], string='Picking Status', compute='_get_delivered', store=True, readonly=True) + + @api.depends('state', 'picking_ids.state') + def _get_delivered(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. + """ + + 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' + + order.picking_status = picking_status diff --git a/sale_stock_usability/sale_stock_view.xml b/sale_stock_usability/sale_stock_view.xml index a1822d9..5e52db7 100644 --- a/sale_stock_usability/sale_stock_view.xml +++ b/sale_stock_usability/sale_stock_view.xml @@ -30,4 +30,39 @@ + + sale_stock_usability.order.form + sale.order + + + + + + + + + + sale_stock_usability.order.tree + sale.order + + + + + + + + + + sale_stock_usability.order.search + sale.order + + + + + + + + +