Prepare NCF manager for production on Tryton 8.0
Publicar paquete PyPI / publish (push) Successful in 1m17s
Publicar paquete PyPI / publish (push) Successful in 1m17s
This commit is contained in:
+25
-1
@@ -1,8 +1,10 @@
|
||||
# This file is part of ncf_manager module for Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.exceptions import UserError
|
||||
from trytond.i18n import gettext
|
||||
from trytond.model import ModelView, ModelSQL, fields
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Eval, Id
|
||||
from trytond.pyson import Eval
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
|
||||
@@ -146,3 +148,25 @@ class NCFManagerSequences(ModelSQL, ModelView):
|
||||
if not self.ncf_type_string:
|
||||
return ''
|
||||
return self.ncf_type_string.split('-')[0]
|
||||
|
||||
@classmethod
|
||||
def validate_fields(cls, records, field_names):
|
||||
super().validate_fields(records, field_names)
|
||||
if field_names & {'pos', 'ncf_sequences', 'ncf_type'}:
|
||||
for record in records:
|
||||
record._validate_fiscal_sequence()
|
||||
|
||||
def _validate_fiscal_sequence(self):
|
||||
sequence = self.ncf_sequences
|
||||
if not sequence:
|
||||
return
|
||||
if sequence.company != self.pos.company:
|
||||
raise UserError(gettext(
|
||||
'ncf_manager.msg_ncf_sequence_company_mismatch'))
|
||||
expected_prefix = ('E' if self.ncf_type in {
|
||||
'31', '32', '33', '34', '41', '43', '44', '45', '46', '47'
|
||||
} else 'B') + self.ncf_type.zfill(2)
|
||||
if self.ncf_type != '99' and sequence.prefix != expected_prefix:
|
||||
raise UserError(gettext(
|
||||
'ncf_manager.msg_ncf_sequence_prefix_mismatch',
|
||||
prefix=expected_prefix))
|
||||
|
||||
Reference in New Issue
Block a user