changeset 125801867e0b in modules/commission:default
details:
https://hg.tryton.org/modules/commission?cmd=changeset;node=125801867e0b
description:
Make currency required on agent
issue8751
review319201002
diffstat:
commission.py | 39 +++++++++++++++++++++++++++++++++------
1 files changed, 33 insertions(+), 6 deletions(-)
diffs (61 lines):
diff -r 8c262e79d99b -r 125801867e0b commission.py
--- a/commission.py Mon Apr 13 17:35:36 2020 +0200
+++ b/commission.py Mon Apr 20 14:03:27 2020 +0200
@@ -37,17 +37,36 @@
company = fields.Many2One('company.company', 'Company', required=True)
plan = fields.Many2One('commission.plan', "Plan",
help="The plan used to calculate the commission.")
- currency = fields.Many2One('currency.currency', 'Currency',
- states={
- 'required': Bool(Eval('plan')),
- 'invisible': ~Eval('plan'),
- },
- depends=['plan'])
+ currency = fields.Many2One('currency.currency', "Currency", required=True)
pending_amount = fields.Function(fields.Numeric('Pending Amount',
digits=price_digits), 'get_pending_amount')
selections = fields.One2Many(
'commission.agent.selection', 'agent', "Selections")
+ @classmethod
+ def __register__(cls, module_name):
+ pool = Pool()
+ Company = pool.get('company.company')
+ sql_table = cls.__table__()
+ company = Company.__table__()
+
+ super().__register__(module_name)
+ transaction = Transaction()
+ cursor = transaction.connection.cursor()
+ table = cls.__table_handler__(module_name)
+
+ # Migration from 5.4: Ensure currency is set
+ # Don't use UPDATE FROM because SQLite does not support it
+ cursor.execute(*sql_table.update(
+ columns=[sql_table.currency],
+ values=[company.select(
+ company.currency,
+ where=company.id == sql_table.company)],
+ where=(sql_table.currency == Null)))
+
+ # Migration from 5.4: Add not null on currency
+ table.not_null_action('currency', 'add')
+
@staticmethod
def default_company():
return Transaction().context.get('company')
@@ -56,6 +75,14 @@
def default_type_():
return 'agent'
+ @classmethod
+ def default_currency(cls):
+ pool = Pool()
+ Company = pool.get('company.company')
+ company = cls.default_company()
+ if company:
+ return Company(company).currency.id
+
@fields.depends('company', 'currency')
def on_change_company(self):
if self.company and not self.currency: