From 678bc958fafd5502a61ce54069b13160ad37d2d4 Mon Sep 17 00:00:00 2001 From: clesgow Date: Fri, 15 Oct 2021 09:27:13 +0000 Subject: [PATCH] [IMP] purchase: Add purchase history for PO line Sometimes it's difficult to track the price of a product, with the different discounts you can obtain. Price of products might change often and it's very practical to track the price at the moment of the order to verify that it's in line with what you paid in the past. Also hides the Forecast Report button when a new line is created (and not yet saved) as the button is disabled anyway without any feedback). New purchase history button will also hide at creation. Task-2658786 closes odoo/odoo#78438 Signed-off-by: Tiffany Chang --- addons/purchase/models/purchase.py | 12 +++++++++ addons/purchase/views/purchase_views.xml | 27 +++++++++++++++++++ .../purchase_stock/views/purchase_views.xml | 4 +-- 3 files changed, 41 insertions(+), 2 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 21f77feb870..0dc5e298ea4 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -907,6 +907,7 @@ class PurchaseOrderLine(models.Model): partner_id = fields.Many2one('res.partner', related='order_id.partner_id', string='Partner', readonly=True, store=True) currency_id = fields.Many2one(related='order_id.currency_id', store=True, string='Currency', readonly=True) date_order = fields.Datetime(related='order_id.date_order', string='Order Date', readonly=True) + date_approve = fields.Datetime(related="order_id.date_approve", string='Confirmation Date', readonly=True) product_packaging_id = fields.Many2one('product.packaging', string='Packaging', domain="[('purchase', '=', True), ('product_id', '=', product_id)]", check_company=True) product_packaging_qty = fields.Float('Packaging Quantity') @@ -1230,6 +1231,17 @@ class PurchaseOrderLine(models.Model): else: line.product_uom_qty = line.product_qty + def action_purchase_history(self): + self.ensure_one() + action = self.env["ir.actions.actions"]._for_xml_id("purchase.action_purchase_history") + action['domain'] = [('state', 'in', ['purchase', 'done']), ('product_id', '=', self.product_id.id)] + action['display_name'] = _("Purchase History for %s", self.product_id.display_name) + action['context'] = { + 'search_default_partner_id': self.partner_id.id + } + + return action + def _suggest_quantity(self): ''' Suggest a minimal quantity based on the seller diff --git a/addons/purchase/views/purchase_views.xml b/addons/purchase/views/purchase_views.xml index 0eb5ad051cd..7da7e035cee 100644 --- a/addons/purchase/views/purchase_views.xml +++ b/addons/purchase/views/purchase_views.xml @@ -250,6 +250,7 @@ +