From 35ff2835b8cec209eec673333197462c4628ead5 Mon Sep 17 00:00:00 2001 From: clementmbr Date: Fri, 10 Sep 2021 11:07:40 +0200 Subject: [PATCH] purchase_stock_usability: Add picking_status for PO ...like in sale_stock_usability : https://github.com/akretion/odoo-usability/blob/14.0/sale_stock_usability/models/sale_order.py#L14 --- purchase_stock_usability/__manifest__.py | 1 + purchase_stock_usability/models/purchase.py | 38 +++++++++++++++++++ .../views/purchase_order_views.xml | 27 +++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 purchase_stock_usability/views/purchase_order_views.xml diff --git a/purchase_stock_usability/__manifest__.py b/purchase_stock_usability/__manifest__.py index 066d0f0..e7276ab 100644 --- a/purchase_stock_usability/__manifest__.py +++ b/purchase_stock_usability/__manifest__.py @@ -23,6 +23,7 @@ Please contact Alexis de Lattre from Akretion for 'purchase_usability', ], 'data': [ + 'views/purchase_order_views.xml', 'views/stock_picking.xml', ], 'installable': True, diff --git a/purchase_stock_usability/models/purchase.py b/purchase_stock_usability/models/purchase.py index 655fa95..8f71ddd 100644 --- a/purchase_stock_usability/models/purchase.py +++ b/purchase_stock_usability/models/purchase.py @@ -10,6 +10,44 @@ class PurchaseOrder(models.Model): picking_type_id = fields.Many2one(tracking=True) incoterm_id = fields.Many2one(tracking=True) + picking_status = fields.Selection([ + ('received', 'Fully Received'), + ('partially_received', 'Partially Received'), + ('to_receive', 'To Receive'), + ('cancel', 'Receipt Cancelled'), + ('no', 'Nothing to Receive') + ], string='Picking Status', compute='_compute_picking_status', + store=True) + + @api.depends('state', 'picking_ids.state') + def _compute_picking_status(self): + """ + Compute the picking status for the PO. Possible statuses: + - no: if the PO is not in status 'purchase' nor 'done', we consider that + there is nothing to receive. This is also the default value if the + conditions of no other status is met. + - cancel: all pickings are cancelled + - received: if all pickings are done or cancel. + - partially_received: If at least one picking is done. + - to_receive: if all pickings are in confirmed, assigned, waiting or + cancel state. + """ + for order in self: + picking_status = 'no' + if order.state in ('purchase', '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 = 'received' + elif any([state == 'done' for state in pstates]): + picking_status = 'partially_received' + elif all([ + state in ('confirmed', 'assigned', 'waiting', 'cancel') + for state in pstates]): + picking_status = 'to_receive' + order.picking_status = picking_status # inherit compute method of the field delivery_partner_id # defined in purchase_usability diff --git a/purchase_stock_usability/views/purchase_order_views.xml b/purchase_stock_usability/views/purchase_order_views.xml new file mode 100644 index 0000000..3707130 --- /dev/null +++ b/purchase_stock_usability/views/purchase_order_views.xml @@ -0,0 +1,27 @@ + + + + purchase.order.view.tree (in purchase_stock_usability) + purchase.order + + + + + + + + + + purchase.order.select (in purchase_stock_usability) + purchase.order + + + + + + + + + + +