From bb3d463e94566e58fe8dcf78d59cdac148c35b54 Mon Sep 17 00:00:00 2001 From: rafaferri Date: Wed, 21 Jun 2023 17:30:52 +0200 Subject: [PATCH] [16.0][IMP] account_global_discount: Remake amount global discount --- account_global_discount/__manifest__.py | 2 +- .../models/account_move.py | 55 ++++++++++--------- .../views/account_invoice_views.xml | 8 +-- 3 files changed, 35 insertions(+), 30 deletions(-) diff --git a/account_global_discount/__manifest__.py b/account_global_discount/__manifest__.py index b6cd7ff5ac18..a2846e68f694 100644 --- a/account_global_discount/__manifest__.py +++ b/account_global_discount/__manifest__.py @@ -3,7 +3,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Account Global Discount", - "version": "16.0.1.0.0", + "version": "16.0.1.1.0", "category": "Accounting", "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/account-invoicing", diff --git a/account_global_discount/models/account_move.py b/account_global_discount/models/account_move.py index c9257beebe95..89e926254594 100644 --- a/account_global_discount/models/account_move.py +++ b/account_global_discount/models/account_move.py @@ -89,42 +89,47 @@ def _set_global_discounts_by_tax(self): for inv_line in _self.invoice_line_ids.filtered( lambda l: l.display_type not in ["line_section", "line_note"] ): - for key in taxes_keys: - if key == tuple(inv_line.tax_ids.ids): - break - else: - taxes_keys[tuple(inv_line.tax_ids.ids)] = True + if inv_line.product_id.apply_global_discount: + for key in taxes_keys: + if key == tuple(inv_line.tax_ids.ids): + break + else: + taxes_keys[tuple(inv_line.tax_ids.ids)] = True # Reset previous global discounts self.invoice_global_discount_ids -= self.invoice_global_discount_ids model = "account.invoice.global.discount" create_method = in_draft_mode and self.env[model].new or self.env[model].create for tax_line in _self.line_ids.filtered("tax_line_id"): - key = [] - to_create = True - for key in taxes_keys: - if tax_line.tax_line_id.id in key: - to_create = taxes_keys[key] - taxes_keys[key] = False # mark for not duplicating - break # we leave in key variable the proper taxes value - if not to_create: - continue - base = tax_line.base_before_global_discounts or tax_line.tax_base_amount - for global_discount in self.global_discount_ids: - vals = self._prepare_global_discount_vals(global_discount, base, key) - create_method(vals) - base = vals["base_discounted"] - # Check all moves with defined taxes to check if there's any discount not - # created (tax amount is zero and only one tax is applied) - for line in _self.line_ids.filtered("tax_ids"): - key = tuple(line.tax_ids.ids) - if taxes_keys.get(key): - base = line.price_subtotal + if tax_line.product_id.apply_global_discount: + key = [] + to_create = True + for key in taxes_keys: + if tax_line.tax_line_id.id in key: + to_create = taxes_keys[key] + taxes_keys[key] = False # mark for not duplicating + break # we leave in key variable the proper taxes value + if not to_create: + continue + base = tax_line.base_before_global_discounts or tax_line.tax_base_amount for global_discount in self.global_discount_ids: vals = self._prepare_global_discount_vals( global_discount, base, key ) create_method(vals) base = vals["base_discounted"] + # Check all moves with defined taxes to check if there's any discount not + # created (tax amount is zero and only one tax is applied) + for line in _self.line_ids.filtered("tax_ids"): + if line.product_id.apply_global_discount: + key = tuple(line.tax_ids.ids) + if taxes_keys.get(key): + base = line.price_subtotal + for global_discount in self.global_discount_ids: + vals = self._prepare_global_discount_vals( + global_discount, base, key + ) + create_method(vals) + base = vals["base_discounted"] def _recompute_global_discount_lines(self): """Append global discounts move lines. diff --git a/account_global_discount/views/account_invoice_views.xml b/account_global_discount/views/account_invoice_views.xml index 1a435b756af3..c4124aade5a8 100644 --- a/account_global_discount/views/account_invoice_views.xml +++ b/account_global_discount/views/account_invoice_views.xml @@ -30,25 +30,25 @@