From 8346854efa9661c0ed2d1fd91f33948ff2cb59ac Mon Sep 17 00:00:00 2001 From: Haresh Chavda Date: Tue, 6 Mar 2018 10:54:07 +0530 Subject: [PATCH] [IMP] Tax calculation when click on update discount button and misc changes --- addons/account_discount/models/account_invoice.py | 6 ++++-- addons/sales_discount/models/sale.py | 7 ++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/addons/account_discount/models/account_invoice.py b/addons/account_discount/models/account_invoice.py index 58909769..276de0f2 100644 --- a/addons/account_discount/models/account_invoice.py +++ b/addons/account_discount/models/account_invoice.py @@ -47,7 +47,8 @@ class AccountInvoice(models.Model): gross_amount = self.gross_amount if self.discount_method == 'per': for line in self.invoice_line_ids: - line.write({'discount': line.discount + self.discount_per}) + line.write({'discount': self.discount_per}) + self._onchange_invoice_line_ids() else: for line in self.invoice_line_ids: discount_value_ratio = \ @@ -55,7 +56,8 @@ class AccountInvoice(models.Model): gross_amount discount_per_ratio = \ (discount_value_ratio * 100) / line.price_subtotal - line.write({'discount': line.discount + discount_per_ratio}) + line.write({'discount': discount_per_ratio}) + self._onchange_invoice_line_ids() @api.constrains('discount_per', 'discount_amount', 'invoice_line_ids') def _check_constrains(self): diff --git a/addons/sales_discount/models/sale.py b/addons/sales_discount/models/sale.py index 120be974..972d8d45 100644 --- a/addons/sales_discount/models/sale.py +++ b/addons/sales_discount/models/sale.py @@ -9,7 +9,8 @@ class SaleOrder(models.Model): _inherit = "sale.order" @api.multi - @api.depends('discount_amount', 'discount_per', 'amount_untaxed') + @api.depends('discount_amount', 'discount_per', + 'amount_untaxed', 'order_line') def _get_discount(self): total_discount = 0.0 for record in self: @@ -46,7 +47,7 @@ class SaleOrder(models.Model): gross_amount = self.gross_amount if self.discount_method == 'per': for line in self.order_line: - line.write({'discount': line.discount + self.discount_per}) + line.write({'discount': self.discount_per}) else: for line in self.order_line: discount_value_ratio = \ @@ -54,7 +55,7 @@ class SaleOrder(models.Model): line.price_subtotal) / gross_amount discount_per_ratio = \ (discount_value_ratio * 100) / line.price_subtotal - line.write({'discount': line.discount + discount_per_ratio}) + line.write({'discount': discount_per_ratio}) @api.onchange('discount_method') def onchange_discount_method(self):