diff --git a/l10n_br_fiscal/models/res_partner.py b/l10n_br_fiscal/models/res_partner.py index b173a2944573..b252c826a584 100644 --- a/l10n_br_fiscal/models/res_partner.py +++ b/l10n_br_fiscal/models/res_partner.py @@ -2,7 +2,7 @@ # Copyright (C) 2020 - TODAY Luis Felipe Mileo - KMEE # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html -from odoo import api, fields, models +from odoo import _, api, fields, models from ..constants.fiscal import ( FINAL_CUSTOMER, @@ -136,3 +136,9 @@ def _commercial_fields(self): "inscr_est", "inscr_mun", ] + + @api.constrains("is_anonymous_consumer") + def _check_anonymous_consumer(self): + for p in self: + if p.is_anonymous_consumer and p.cnpj_cpf: + raise ValueError(_("Anonymous consumer cannot have a CNPJ/CPF number.")) diff --git a/l10n_br_pos_nfce/models/pos_config.py b/l10n_br_pos_nfce/models/pos_config.py index dfbdeef3288a..30099e341d4a 100644 --- a/l10n_br_pos_nfce/models/pos_config.py +++ b/l10n_br_pos_nfce/models/pos_config.py @@ -27,19 +27,13 @@ class PosConfig(models.Model): nfce_document_serie_sequence_number_next = fields.Integer( string="Document Serie Number", - default=lambda self: self._default_next_number(), + related="nfce_document_serie_id.internal_sequence_id.number_next_actual", ) nfce_city_ibge_code = fields.Char( related="company_id.city_id.ibge_code", ) - def _default_next_number(self): - if not self.nfce_document_serie_id: - return 1 - - return self.nfce_document_serie_id.internal_sequence_id.number_next_actual - def update_nfce_serie_number(self, serie_number): if self.nfce_document_serie_sequence_number_next < serie_number: self.nfce_document_serie_sequence_number_next = serie_number