Make date readonly when the number is already set

Is should not be possible to modify the invoice_date when a number is set,
otherwise it should be possible to make an invoice which is not consecutive
because we only check it when creating the number.
This commit is contained in:
Sergi Almacellas Abellana 2016-12-20 15:30:28 +01:00
parent d9cf25e165
commit c92fc53cba

View file

@ -2,6 +2,7 @@
# the full copyright notices and license terms.
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Bool, Eval
__all__ = ['Invoice']
@ -24,6 +25,15 @@ class Invoice:
'permitted, because of invoice number and date '
'correlation.',
})
if 'number' not in cls.invoice_date.depends:
new_readonly = Bool(Eval('number'))
readonly = cls.invoice_date.states.get('readonly')
if readonly:
new_readonly |= readonly
cls.invoice_date.states.update({
'readonly': new_readonly,
})
cls.invoice_date.depends.append('number')
@classmethod
def validate(cls, invoices):