changeset 88554e9e2b27 in modules/account_invoice:5.8
details:
https://hg.tryton.org/modules/account_invoice?cmd=changeset;node=88554e9e2b27
description:
Enforce currency, invoice_type and party values between invoice and
lines
The currency of an invoice line must always be the same as the invoice.
For the invoice_type and party they must be the same only if set.
issue9854
review324581002
(grafted from 2d60611c1e2f8d964a9905db0f6ef3a028764d8a)
diffstat:
invoice.py | 39 ++++++++++++++++++++++++++++++---------
1 files changed, 30 insertions(+), 9 deletions(-)
diffs (73 lines):
diff -r 11356d52d259 -r 88554e9e2b27 invoice.py
--- a/invoice.py Fri Dec 11 15:44:02 2020 +0100
+++ b/invoice.py Wed Dec 16 21:24:07 2020 +0100
@@ -110,7 +110,12 @@
required=True, states=_states, depends=_depends + ['party'],
domain=[('party', '=', Eval('party'))])
currency = fields.Many2One('currency.currency', 'Currency', required=True,
- states=_states, depends=_depends)
+ states={
+ 'readonly': (
+ _states['readonly']
+ | (Eval('lines', [0]) & Eval('currency'))),
+ },
+ depends=_depends)
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
currency_date = fields.Function(fields.Date('Currency Date'),
@@ -150,11 +155,23 @@
lines = fields.One2Many('account.invoice.line', 'invoice', 'Lines',
domain=[
('company', '=', Eval('company', -1)),
+ ('currency', '=', Eval('currency', -1)),
+ ['OR',
+ ('invoice_type', '=', Eval('type')),
+ ('invoice_type', '=', None),
+ ],
+ ['OR',
+ ('party', '=', Eval('party', -1)),
+ ('party', '=', None),
+ ],
],
states={
- 'readonly': (Eval('state') != 'draft') | ~Eval('company'),
+ 'readonly': (
+ (Eval('state') != 'draft')
+ | ~Eval('company')
+ | ~Eval('currency')),
},
- depends=['state', 'company'])
+ depends=['state', 'company', 'currency', 'type', 'party'])
taxes = fields.One2Many('account.invoice.tax', 'invoice', 'Tax Lines',
states=_states, depends=_depends)
comment = fields.Text('Comment', states=_states, depends=_depends)
@@ -1633,12 +1650,9 @@
depends=['invoice'] + _depends)
party_lang = fields.Function(fields.Char('Party Language'),
'on_change_with_party_lang')
- currency = fields.Many2One('currency.currency', 'Currency',
- states={
- 'required': ~Eval('invoice'),
- 'readonly': _states['readonly'],
- },
- depends=['invoice'] + _depends)
+ currency = fields.Many2One(
+ 'currency.currency', "Currency", required=True,
+ states=_states, depends=_depends)
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
company = fields.Many2One('company.company', 'Company', required=True,
@@ -1831,6 +1845,13 @@
Invoice = pool.get('account.invoice')
return Invoice.fields_get(['type'])['type']['selection'] + [(None, '')]
+ @fields.depends(
+ 'invoice', '_parent_invoice.currency', '_parent_invoice.company')
+ def on_change_invoice(self):
+ if self.invoice:
+ self.currency = self.invoice.currency
+ self.company = self.invoice.company
+
@staticmethod
def default_currency():
Company = Pool().get('company.company')