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 []
@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')
+14 -11
View File
@@ -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()
@@ -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:
+1
View File
@@ -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
+7 -7
View File
@@ -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()
+5
View File
@@ -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
+6 -6
View File
@@ -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
+6 -6
View File
@@ -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()