diff --git a/modules/account/tax.py b/modules/account/tax.py index 8502f8e053..d5d9b67eb3 100644 --- a/modules/account/tax.py +++ b/modules/account/tax.py @@ -1231,6 +1231,7 @@ class TaxableMixin(object): return [] @property + @fields.depends('company') def tax_date(self): "Date to use when computing the tax" pool = Pool() @@ -1241,6 +1242,7 @@ class TaxableMixin(object): def _get_tax_context(self): return {} + @fields.depends('currency') def _compute_tax_line(self, amount, base, tax): if base >= 0: type_ = 'invoice' @@ -1280,7 +1282,9 @@ class TaxableMixin(object): if abs(remainder) < self.currency.rounding: break - @fields.depends('company', methods=['_get_tax_context', '_round_taxes']) + @fields.depends('company', methods=[ + 'taxable_lines', 'tax_date', '_get_tax_context', + '_compute_tax_line', '_round_taxes']) def _get_taxes(self): pool = Pool() Tax = pool.get('account.tax') diff --git a/modules/account_invoice/invoice.py b/modules/account_invoice/invoice.py index 00673e342b..e4c3251ade 100644 --- a/modules/account_invoice/invoice.py +++ b/modules/account_invoice/invoice.py @@ -1154,6 +1154,7 @@ class Invoice( return result @property + @fields.depends('lines', 'type') def taxable_lines(self): taxable_lines = [] for line in self.lines: @@ -2718,20 +2719,21 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): return 1 @property + @fields.depends( + 'invoice', '_parent_invoice.type', 'invoice_type', + 'taxes_deductible_rate', 'taxes', 'unit_price', 'quantity', + methods=['tax_date']) def taxable_lines(self): - # In case we're called from an on_change we have to use some sensible - # defaults context = Transaction().context - if (getattr(self, 'invoice', None) - and getattr(self.invoice, 'type', None)): + if self.invoice and self.invoice.type: invoice_type = self.invoice.type else: - invoice_type = getattr(self, 'invoice_type', None) + invoice_type = self.invoice_type if invoice_type == 'in': if context.get('_deductible_rate') is not None: deductible_rate = context['_deductible_rate'] else: - deductible_rate = getattr(self, 'taxes_deductible_rate', 1) + deductible_rate = self.taxes_deductible_rate if deductible_rate is None: deductible_rate = 1 if not deductible_rate: @@ -2739,14 +2741,14 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): else: deductible_rate = 1 return [( - list(getattr(self, 'taxes', None)) or [], - ((getattr(self, 'unit_price', None) or Decimal(0)) - * deductible_rate), - getattr(self, 'quantity', None) or 0, - getattr(self, 'tax_date', None), + list(self.taxes or []), + (self.unit_price or Decimal(0)) * deductible_rate, + self.quantity or 0, + self.tax_date, )] @property + @fields.depends('taxes_date', 'invoice', '_parent_invoice.id') def tax_date(self): if getattr(self, 'taxes_date', None): return self.taxes_date @@ -2755,6 +2757,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): else: return super().tax_date + @fields.depends('invoice', '_parent_invoice.id', 'company') def _get_tax_context(self): if self.invoice: return self.invoice._get_tax_context() diff --git a/modules/account_tax_non_deductible/account.py b/modules/account_tax_non_deductible/account.py index e25f4217eb..6d6e377664 100644 --- a/modules/account_tax_non_deductible/account.py +++ b/modules/account_tax_non_deductible/account.py @@ -53,14 +53,14 @@ class InvoiceLine(metaclass=PoolMeta): return amount @property + @fields.depends('invoice', '_parent_invoice.type', 'invoice_type') def taxable_lines(self): context = Transaction().context lines = super().taxable_lines - if (getattr(self, 'invoice', None) - and getattr(self.invoice, 'type', None)): + if self.invoice and self.invoice.type: invoice_type = self.invoice.type else: - invoice_type = getattr(self, 'invoice_type', None) + invoice_type = self.invoice_type if invoice_type == 'in': if context.get('_non_deductible'): for line in lines: diff --git a/modules/purchase/purchase.py b/modules/purchase/purchase.py index e81b5437d1..80a6a57a82 100644 --- a/modules/purchase/purchase.py +++ b/modules/purchase/purchase.py @@ -511,6 +511,7 @@ class Purchase( self.total_amount = self.currency.round(self.total_amount) @property + @fields.depends('lines') def taxable_lines(self): taxable_lines = [] # In case we're called from an on_change we have to use some sensible diff --git a/modules/sale/sale.py b/modules/sale/sale.py index 41aabbff42..7f63d24bb3 100644 --- a/modules/sale/sale.py +++ b/modules/sale/sale.py @@ -640,6 +640,7 @@ class Sale( self.total_amount = self.currency.round(self.total_amount) @property + @fields.depends('lines') def taxable_lines(self): taxable_lines = [] for line in self.lines: @@ -1683,19 +1684,18 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView): return progress @property + @fields.depends('type', 'taxes', 'unit_price', 'quantity') def taxable_lines(self): - # In case we're called from an on_change - # we have to use some sensible defaults - if getattr(self, 'type', None) == 'line': - return [( - getattr(self, 'taxes', None) or [], - getattr(self, 'unit_price', None) or Decimal(0), - getattr(self, 'quantity', None) or 0, + if self.type == 'line': + return [(self.taxes or [], + self.unit_price or Decimal(0), + self.quantity or 0, None, )] else: return [] + @fields.depends('sale', '_parent_sale.id') def _get_tax_context(self): return self.sale._get_tax_context() diff --git a/modules/sale_point/sale.py b/modules/sale_point/sale.py index 8ad30fde1e..880c541762 100644 --- a/modules/sale_point/sale.py +++ b/modules/sale_point/sale.py @@ -441,10 +441,12 @@ class POSSale(Workflow, ModelSQL, ModelView, TaxableMixin, ChatMixin): return lines @property + @fields.depends('lines') def taxable_lines(self): return sum((line.taxable_lines for line in self.lines), []) @property + @fields.depends('date') def tax_date(self): return self.date or super().tax_date @@ -706,6 +708,8 @@ class POSSaleLine(ModelSQL, ModelView, TaxableMixin): return Product(self.product).customer_taxes_used @property + @fields.depends( + 'taxes', 'unit_list_price', 'quantity', methods=['tax_date']) def taxable_lines(self): return [ (self.taxes, self.unit_list_price, self.quantity, self.tax_date)] @@ -718,6 +722,7 @@ class POSSaleLine(ModelSQL, ModelView, TaxableMixin): return 'credit_note' @property + @fields.depends('sale', '_parent_sale.date') def tax_date(self): return self.sale.date or super().tax_date diff --git a/modules/sale_promotion/sale.py b/modules/sale_promotion/sale.py index c1058926ba..426131f1bf 100644 --- a/modules/sale_promotion/sale.py +++ b/modules/sale_promotion/sale.py @@ -161,16 +161,16 @@ class Line(metaclass=PoolMeta): return amount @property + @fields.depends( + 'type', 'taxes', 'original_unit_price', 'unit_price', 'quantity') def taxable_lines(self): lines = super().taxable_lines - if (getattr(self, 'type', None) == 'line' + if (self.type == 'line' and Transaction().context.get('_original_amount')): lines = [( - getattr(self, 'taxes', None) or [], - getattr(self, 'original_unit_price', None) - or getattr(self, 'unit_price', None) - or Decimal(0), - getattr(self, 'quantity', None) or 0, + self.taxes or [], + self.original_unit_price or self.unit_price or Decimal(0), + self.quantity or 0, None, )] return lines diff --git a/modules/sale_rental/sale.py b/modules/sale_rental/sale.py index 3d23305cbc..0cc9712679 100644 --- a/modules/sale_rental/sale.py +++ b/modules/sale_rental/sale.py @@ -439,6 +439,7 @@ class Rental( (t.amount for t in self._get_taxes().values()), Decimal(0)) @property + @fields.depends('lines') def taxable_lines(self): taxable_lines = [] for line in self.lines: @@ -1063,17 +1064,16 @@ class RentalLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin): return {} @property + @fields.depends('taxes', 'unit_price', 'quantity', 'duration_unit') def taxable_lines(self): - # In case we're called from an on_change - # we have to use some sensible defaults return [( - getattr(self, 'taxes', None) or [], - getattr(self, 'unit_price', None) or Decimal(0), - (getattr(self, 'quantity', None) or 0) - * (getattr(self, 'duration_unit', None) or 0), + self.taxes or [], + self.unit_price or Decimal(0), + (self.quantity or 0) * (self.duration_unit or 0), None, )] + @fields.depends('rental', '_parent_rental.id') def _get_tax_context(self): return self.rental._get_tax_context()