From b33e5406eeafaca84c007fd8d167a099b63a36ad Mon Sep 17 00:00:00 2001 From: Rolando Duarte Date: Wed, 10 Dec 2025 05:55:43 +0000 Subject: [PATCH] [REF] account: refactor base lines extraction for taxes computation Refactored the logic to extract base lines for tax computation in `AccountMove`. Introduced the `_get_base_amls` method to centralize the retrieval of base lines, improving code clarity and maintainability. This change enhances heritability, allowing future modules to override the base lines selection logic in a single place. No functional change is expected, but the code is now easier to extend and maintain, especially for localizations or custom modules that need to alter base line selection for tax calculations. --- addons/account/models/account_move.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py index 3667f6da81e7ea..0444c4a20a4604 100644 --- a/addons/account/models/account_move.py +++ b/addons/account/models/account_move.py @@ -1591,6 +1591,20 @@ def _prepare_tax_line_for_taxes_computation(self, tax_line): sign=self.direction_sign, ) + def _get_base_amls(self): + """ Get the base lines to be used for the taxes computation. + + :return: A recordset of account.move.line. + """ + self.ensure_one() + is_invoice = self.is_invoice(include_receipts=True) + + if self.id or not is_invoice: + base_amls = self.line_ids.filtered(lambda line: line.display_type == 'product') + else: + base_amls = self.invoice_line_ids.filtered(lambda line: line.display_type == 'product') + return base_amls + def _get_rounded_base_and_tax_lines(self, round_from_tax_lines=True): """ Small helper to extract the base and tax lines for the taxes computation from the current move. The move could be stored or not and could have some features generating extra journal items acting as @@ -1602,12 +1616,8 @@ def _get_rounded_base_and_tax_lines(self, round_from_tax_lines=True): """ self.ensure_one() AccountTax = self.env['account.tax'] - is_invoice = self.is_invoice(include_receipts=True) - if self.id or not is_invoice: - base_amls = self.line_ids.filtered(lambda line: line.display_type == 'product') - else: - base_amls = self.invoice_line_ids.filtered(lambda line: line.display_type == 'product') + base_amls = self._get_base_amls() base_lines = [self._prepare_product_base_line_for_taxes_computation(line) for line in base_amls] tax_lines = []