Add depends on methods of TaxableMixin

This commit is contained in:
Cédric Krier
2026-01-17 12:54:09 +01:00
parent df02ade40e
commit 70701c14e4
8 changed files with 47 additions and 34 deletions
+5 -1
View File
@@ -1231,6 +1231,7 @@ class TaxableMixin(object):
return [] return []
@property @property
@fields.depends('company')
def tax_date(self): def tax_date(self):
"Date to use when computing the tax" "Date to use when computing the tax"
pool = Pool() pool = Pool()
@@ -1241,6 +1242,7 @@ class TaxableMixin(object):
def _get_tax_context(self): def _get_tax_context(self):
return {} return {}
@fields.depends('currency')
def _compute_tax_line(self, amount, base, tax): def _compute_tax_line(self, amount, base, tax):
if base >= 0: if base >= 0:
type_ = 'invoice' type_ = 'invoice'
@@ -1280,7 +1282,9 @@ class TaxableMixin(object):
if abs(remainder) < self.currency.rounding: if abs(remainder) < self.currency.rounding:
break 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): def _get_taxes(self):
pool = Pool() pool = Pool()
Tax = pool.get('account.tax') Tax = pool.get('account.tax')
+14 -11
View File
@@ -1154,6 +1154,7 @@ class Invoice(
return result return result
@property @property
@fields.depends('lines', 'type')
def taxable_lines(self): def taxable_lines(self):
taxable_lines = [] taxable_lines = []
for line in self.lines: for line in self.lines:
@@ -2718,20 +2719,21 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
return 1 return 1
@property @property
@fields.depends(
'invoice', '_parent_invoice.type', 'invoice_type',
'taxes_deductible_rate', 'taxes', 'unit_price', 'quantity',
methods=['tax_date'])
def taxable_lines(self): def taxable_lines(self):
# In case we're called from an on_change we have to use some sensible
# defaults
context = Transaction().context context = Transaction().context
if (getattr(self, 'invoice', None) if self.invoice and self.invoice.type:
and getattr(self.invoice, 'type', None)):
invoice_type = self.invoice.type invoice_type = self.invoice.type
else: else:
invoice_type = getattr(self, 'invoice_type', None) invoice_type = self.invoice_type
if invoice_type == 'in': if invoice_type == 'in':
if context.get('_deductible_rate') is not None: if context.get('_deductible_rate') is not None:
deductible_rate = context['_deductible_rate'] deductible_rate = context['_deductible_rate']
else: else:
deductible_rate = getattr(self, 'taxes_deductible_rate', 1) deductible_rate = self.taxes_deductible_rate
if deductible_rate is None: if deductible_rate is None:
deductible_rate = 1 deductible_rate = 1
if not deductible_rate: if not deductible_rate:
@@ -2739,14 +2741,14 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
else: else:
deductible_rate = 1 deductible_rate = 1
return [( return [(
list(getattr(self, 'taxes', None)) or [], list(self.taxes or []),
((getattr(self, 'unit_price', None) or Decimal(0)) (self.unit_price or Decimal(0)) * deductible_rate,
* deductible_rate), self.quantity or 0,
getattr(self, 'quantity', None) or 0, self.tax_date,
getattr(self, 'tax_date', None),
)] )]
@property @property
@fields.depends('taxes_date', 'invoice', '_parent_invoice.id')
def tax_date(self): def tax_date(self):
if getattr(self, 'taxes_date', None): if getattr(self, 'taxes_date', None):
return self.taxes_date return self.taxes_date
@@ -2755,6 +2757,7 @@ class InvoiceLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
else: else:
return super().tax_date return super().tax_date
@fields.depends('invoice', '_parent_invoice.id', 'company')
def _get_tax_context(self): def _get_tax_context(self):
if self.invoice: if self.invoice:
return self.invoice._get_tax_context() return self.invoice._get_tax_context()
@@ -53,14 +53,14 @@ class InvoiceLine(metaclass=PoolMeta):
return amount return amount
@property @property
@fields.depends('invoice', '_parent_invoice.type', 'invoice_type')
def taxable_lines(self): def taxable_lines(self):
context = Transaction().context context = Transaction().context
lines = super().taxable_lines lines = super().taxable_lines
if (getattr(self, 'invoice', None) if self.invoice and self.invoice.type:
and getattr(self.invoice, 'type', None)):
invoice_type = self.invoice.type invoice_type = self.invoice.type
else: else:
invoice_type = getattr(self, 'invoice_type', None) invoice_type = self.invoice_type
if invoice_type == 'in': if invoice_type == 'in':
if context.get('_non_deductible'): if context.get('_non_deductible'):
for line in lines: for line in lines:
+1
View File
@@ -511,6 +511,7 @@ class Purchase(
self.total_amount = self.currency.round(self.total_amount) self.total_amount = self.currency.round(self.total_amount)
@property @property
@fields.depends('lines')
def taxable_lines(self): def taxable_lines(self):
taxable_lines = [] taxable_lines = []
# In case we're called from an on_change we have to use some sensible # In case we're called from an on_change we have to use some sensible
+7 -7
View File
@@ -640,6 +640,7 @@ class Sale(
self.total_amount = self.currency.round(self.total_amount) self.total_amount = self.currency.round(self.total_amount)
@property @property
@fields.depends('lines')
def taxable_lines(self): def taxable_lines(self):
taxable_lines = [] taxable_lines = []
for line in self.lines: for line in self.lines:
@@ -1683,19 +1684,18 @@ class SaleLine(TaxableMixin, sequence_ordered(), ModelSQL, ModelView):
return progress return progress
@property @property
@fields.depends('type', 'taxes', 'unit_price', 'quantity')
def taxable_lines(self): def taxable_lines(self):
# In case we're called from an on_change if self.type == 'line':
# we have to use some sensible defaults return [(self.taxes or [],
if getattr(self, 'type', None) == 'line': self.unit_price or Decimal(0),
return [( self.quantity or 0,
getattr(self, 'taxes', None) or [],
getattr(self, 'unit_price', None) or Decimal(0),
getattr(self, 'quantity', None) or 0,
None, None,
)] )]
else: else:
return [] return []
@fields.depends('sale', '_parent_sale.id')
def _get_tax_context(self): def _get_tax_context(self):
return self.sale._get_tax_context() return self.sale._get_tax_context()
+5
View File
@@ -441,10 +441,12 @@ class POSSale(Workflow, ModelSQL, ModelView, TaxableMixin, ChatMixin):
return lines return lines
@property @property
@fields.depends('lines')
def taxable_lines(self): def taxable_lines(self):
return sum((line.taxable_lines for line in self.lines), []) return sum((line.taxable_lines for line in self.lines), [])
@property @property
@fields.depends('date')
def tax_date(self): def tax_date(self):
return self.date or super().tax_date return self.date or super().tax_date
@@ -706,6 +708,8 @@ class POSSaleLine(ModelSQL, ModelView, TaxableMixin):
return Product(self.product).customer_taxes_used return Product(self.product).customer_taxes_used
@property @property
@fields.depends(
'taxes', 'unit_list_price', 'quantity', methods=['tax_date'])
def taxable_lines(self): def taxable_lines(self):
return [ return [
(self.taxes, self.unit_list_price, self.quantity, self.tax_date)] (self.taxes, self.unit_list_price, self.quantity, self.tax_date)]
@@ -718,6 +722,7 @@ class POSSaleLine(ModelSQL, ModelView, TaxableMixin):
return 'credit_note' return 'credit_note'
@property @property
@fields.depends('sale', '_parent_sale.date')
def tax_date(self): def tax_date(self):
return self.sale.date or super().tax_date return self.sale.date or super().tax_date
+6 -6
View File
@@ -161,16 +161,16 @@ class Line(metaclass=PoolMeta):
return amount return amount
@property @property
@fields.depends(
'type', 'taxes', 'original_unit_price', 'unit_price', 'quantity')
def taxable_lines(self): def taxable_lines(self):
lines = super().taxable_lines lines = super().taxable_lines
if (getattr(self, 'type', None) == 'line' if (self.type == 'line'
and Transaction().context.get('_original_amount')): and Transaction().context.get('_original_amount')):
lines = [( lines = [(
getattr(self, 'taxes', None) or [], self.taxes or [],
getattr(self, 'original_unit_price', None) self.original_unit_price or self.unit_price or Decimal(0),
or getattr(self, 'unit_price', None) self.quantity or 0,
or Decimal(0),
getattr(self, 'quantity', None) or 0,
None, None,
)] )]
return lines return lines
+6 -6
View File
@@ -439,6 +439,7 @@ class Rental(
(t.amount for t in self._get_taxes().values()), Decimal(0)) (t.amount for t in self._get_taxes().values()), Decimal(0))
@property @property
@fields.depends('lines')
def taxable_lines(self): def taxable_lines(self):
taxable_lines = [] taxable_lines = []
for line in self.lines: for line in self.lines:
@@ -1063,17 +1064,16 @@ class RentalLine(sequence_ordered(), ModelSQL, ModelView, TaxableMixin):
return {} return {}
@property @property
@fields.depends('taxes', 'unit_price', 'quantity', 'duration_unit')
def taxable_lines(self): def taxable_lines(self):
# In case we're called from an on_change
# we have to use some sensible defaults
return [( return [(
getattr(self, 'taxes', None) or [], self.taxes or [],
getattr(self, 'unit_price', None) or Decimal(0), self.unit_price or Decimal(0),
(getattr(self, 'quantity', None) or 0) (self.quantity or 0) * (self.duration_unit or 0),
* (getattr(self, 'duration_unit', None) or 0),
None, None,
)] )]
@fields.depends('rental', '_parent_rental.id')
def _get_tax_context(self): def _get_tax_context(self):
return self.rental._get_tax_context() return self.rental._get_tax_context()