Add SQL constraint to ensure only one tax line without period
TaxLine.update_cash_basis relies on having only one line without period per grouping key so it is safer to make it a SQL constraint.
This commit is contained in:
1 parent
ef5d8d53ac
commit
c8464cd945
2 files changed
+24
-1
No files matched your search
@@ -4,9 +4,11 @@ from collections import defaultdict
|
||||
from itertools import groupby
|
||||
|
||||
from sql import Literal, Null
|
||||
from sql.operators import Equal
|
||||
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelSQL, ModelView, Workflow, dualmethod, fields
|
||||
from trytond.model import (
|
||||
Exclude, ModelSQL, ModelView, Workflow, dualmethod, fields)
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.pyson import Eval
|
||||
from trytond.tools import sortable_values
|
||||
@@ -133,6 +135,24 @@ class TaxLine(metaclass=PoolMeta):
|
||||
'invisible': ~Eval('on_cash_basis', False),
|
||||
})
|
||||
|
||||
@classmethod
|
||||
def __setup__(cls):
|
||||
super().__setup__()
|
||||
|
||||
t = cls.__table__()
|
||||
cls._sql_constraints = [
|
||||
('tax_type_move_line_cash_basis_no_period',
|
||||
Exclude(
|
||||
t,
|
||||
(t.tax, Equal),
|
||||
(t.type, Equal),
|
||||
(t.move_line, Equal),
|
||||
where=(t.on_cash_basis == Literal(True))
|
||||
& (t.period == Null)),
|
||||
'account_tax_cash.'
|
||||
'msg_tax_type_move_line_cash_basis_no_period_unique'),
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def default_on_cash_basis(cls):
|
||||
return False
|
||||
|
||||
@@ -6,5 +6,8 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<record model="ir.message" id="msg_close_period_line_payment">
|
||||
<field name="text">To close period "%(period)s" you must link all payable/receivable lines to invoices.</field>
|
||||
</record>
|
||||
<record model="ir.message" id="msg_tax_type_move_line_cash_basis_no_period_unique">
|
||||
<field name="text">Only one tax line on cash basis can be without period per move line.</field>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
Reference in new issue
Block a user