From ff195561216d4e98ff1b7aaf4a5bab49d4e448e5 Mon Sep 17 00:00:00 2001 From: Jigar Vaghela Date: Fri, 1 Mar 2019 13:13:27 +0000 Subject: [PATCH] [IMP] sale: change the pricelist in the quotation its update prices of product. purpose of this commit is when the pricelist is chnaged and some products alredy added to the sale order, display a button "recompute price" that throws a confirmation model asking for recompute the price of the so line task: 1947320 Closes: #31535 Co-authored-by: Mitali Patel --- addons/sale/models/sale.py | 30 ++++++++++++++++++++- addons/sale/views/sale_views.xml | 12 ++++++++- addons/sale_management/models/sale_order.py | 7 +++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index c49c864e772..a93875f08d9 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -162,7 +162,7 @@ class SaleOrder(models.Model): pricelist_id = fields.Many2one( 'product.pricelist', string='Pricelist', check_company=True, # Unrequired company required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, - domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", + domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=1, help="If you change the pricelist, only newly added lines will be affected.") currency_id = fields.Many2one("res.currency", related='pricelist_id.currency_id', string="Currency", readonly=True, required=True) analytic_account_id = fields.Many2one( @@ -225,6 +225,9 @@ class SaleOrder(models.Model): string='Transactions', copy=False, readonly=True) authorized_transaction_ids = fields.Many2many('payment.transaction', compute='_compute_authorized_transaction_ids', string='Authorized Transactions', copy=False, readonly=True) + show_update_pricelist = fields.Boolean(string='Has Pricelist Changed', + help="Technical Field, True if the pricelist was changed;\n" + " this will then display a recomputation button") _sql_constraints = [ ('date_order_conditional_required', "CHECK( (state IN ('sale', 'done') AND date_order IS NOT NULL) OR state NOT IN ('sale', 'done') )", "A confirmed sales order requires a confirmation date."), @@ -402,6 +405,31 @@ class SaleOrder(models.Model): } } + @api.onchange('pricelist_id') + def _onchange_pricelist_id(self): + if self.order_line and self.pricelist_id and self._origin.pricelist_id and self._origin.pricelist_id != self.pricelist_id: + self.show_update_pricelist = True + else: + self.show_update_pricelist = False + + def update_prices(self): + self.ensure_one() + lines_to_update = [] + for line in self.order_line.filtered(lambda line: not line.display_type): + product = line.product_id.with_context( + partner=self.partner_id, + quantity=line.product_uom_qty, + date=self.date_order, + pricelist=self.pricelist_id.id, + uom=line.product_uom.id + ) + price_unit = self.env['account.tax']._fix_tax_included_price_company( + line._get_display_price(product), line.product_id.taxes_id, line.tax_id, line.company_id) + lines_to_update.append((1, line.id, {'price_unit': price_unit})) + self.update({'order_line': lines_to_update}) + self.show_update_pricelist = False + self.message_post(body=_("Product prices have been recomputed according to pricelist %s ") % self.pricelist_id.display_name) + @api.model def create(self, vals): if vals.get('name', _('New')) == _('New'): diff --git a/addons/sale/views/sale_views.xml b/addons/sale/views/sale_views.xml index 611a1f2c2a5..05208ef31d2 100644 --- a/addons/sale/views/sale_views.xml +++ b/addons/sale/views/sale_views.xml @@ -320,7 +320,17 @@