Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][REF][l10n_br_base] inscr_ie -> l10n_br_ie_code #3569

Draft
wants to merge 3 commits into
base: 16.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion l10n_br_base/models/party_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ class PartyMixin(models.AbstractModel):
unaccent=False,
)

inscr_est = fields.Char(
l10n_br_ie_code = fields.Char(
string="State Tax Number",
size=17,
unaccent=False,
)

# compat with legacy code:
inscr_est = fields.Char(related="l10n_br_ie_code", readonly=False)

rg = fields.Char(
string="RG",
unaccent=False,
Expand Down
14 changes: 7 additions & 7 deletions l10n_br_base/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _get_company_address_field_names(self):
return partner_fields + [
"legal_name",
"cnpj_cpf",
"inscr_est",
"l10n_br_ie_code",
"inscr_mun",
"district",
"city_id",
Expand Down Expand Up @@ -54,10 +54,10 @@ def _inverse_cnpj_cpf(self):
for company in self:
company.partner_id.cnpj_cpf = company.cnpj_cpf

def _inverse_inscr_est(self):
def _inverse_l10n_br_ie_code(self):
"""Write the l10n_br specific functional fields."""
for company in self:
company.partner_id.inscr_est = company.inscr_est
company.partner_id.l10n_br_ie_code = company.l10n_br_ie_code

def _inverse_state(self):
"""Write the l10n_br specific functional fields."""
Expand Down Expand Up @@ -120,9 +120,9 @@ def _inverse_suframa(self):
inverse="_inverse_cnpj_cpf",
)

inscr_est = fields.Char(
l10n_br_ie_code = fields.Char(
compute="_compute_address",
inverse="_inverse_inscr_est",
inverse="_inverse_l10n_br_ie_code",
)

state_tax_number_ids = fields.One2many(
Expand Down Expand Up @@ -167,7 +167,7 @@ def write(self, values):
@api.onchange("state_id")
def _onchange_state_id(self):
res = super()._onchange_state_id()
self.inscr_est = False
self.partner_id.inscr_est = False
self.l10n_br_ie_code = False
self.partner_id.l10n_br_ie_code = False
self.partner_id.state_id = self.state_id
return res
19 changes: 11 additions & 8 deletions l10n_br_base/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def _inverse_street_data(self):
help="Indicate if is a Brazilian partner",
)

@api.constrains("cnpj_cpf", "inscr_est")
def _check_cnpj_inscr_est(self):
@api.constrains("cnpj_cpf", "l10n_br_ie_code")
def _check_cnpj_l10n_br_ie_code(self):
for record in self:
domain = []

Expand Down Expand Up @@ -93,8 +93,8 @@ def _check_cnpj_inscr_est(self):
if allow_cnpj_multi_ie == "True":
for partner in record.env["res.partner"].search(domain):
if (
partner.inscr_est == record.inscr_est
and record.inscr_est
partner.l10n_br_ie_code == record.l10n_br_ie_code
and record.l10n_br_ie_code
):
raise ValidationError(
_(
Expand Down Expand Up @@ -134,7 +134,7 @@ def _check_cnpj_cpf(self):
record.country_id,
)

@api.constrains("inscr_est", "state_id", "is_company")
@api.constrains("l10n_br_ie_code", "state_id", "is_company")
def _check_ie(self):
"""Checks if company register number in field insc_est is valid,
this method call others methods because this validation is State wise
Expand All @@ -144,7 +144,10 @@ def _check_ie(self):
for record in self:
if record.is_company:
check_ie(
record.env, record.inscr_est, record.state_id, record.country_id
record.env,
record.l10n_br_ie_code,
record.state_id,
record.country_id,
)

@api.constrains("state_tax_number_ids")
Expand Down Expand Up @@ -202,15 +205,15 @@ def _compute_show_l10n_br(self):

def create_company(self):
self.ensure_one()
inscr_est = self.inscr_est
inscr_est = self.l10n_br_ie_code
inscr_mun = self.inscr_mun
res = super().create_company()
if res:
parent = self.parent_id
if parent.country_id.code == "BR":
parent.legal_name = parent.name
parent.cnpj_cpf = parent.vat
parent.inscr_est = inscr_est
parent.l10n_br_ie_code = inscr_est
parent.inscr_mun = inscr_mun
return res

Expand Down
2 changes: 1 addition & 1 deletion l10n_br_base/views/res_company_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
attrs="{'invisible': [('country_id', '!=', %(base.br)d)]}"
/>
<field
name="inscr_est"
name="l10n_br_ie_code"
placeholder="State Tax Number..."
attrs="{'invisible': [('country_id', '!=', %(base.br)d)]}"
/>
Expand Down
10 changes: 5 additions & 5 deletions l10n_br_base/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<field name="display_name" position="after">
<field name="legal_name" />
<field name="cnpj_cpf" />
<field name="inscr_est" />
<field name="l10n_br_ie_code" />
</field>
</field>
</record>
Expand Down Expand Up @@ -91,17 +91,17 @@
nolabel="1"
attrs="{'invisible': [('is_company','=', True)]}"
/>
<div name="inscr_est">
<div name="l10n_br_ie_code">
<label
for="inscr_est"
name="inscr_est"
for="l10n_br_ie_code"
name="l10n_br_ie_code"
string="IE"
attrs="{'invisible': [('is_company','=', False), ('parent_id', '!=', False)]}"
/>
</div>
<field
colspan="4"
name="inscr_est"
name="l10n_br_ie_code"
nolabel="1"
attrs="{'invisible': [('is_company','=', False), ('parent_id', '!=', False)]}"
/>
Expand Down
4 changes: 2 additions & 2 deletions l10n_br_fiscal/models/document_move_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class DocumentMoveMixin(models.AbstractModel):

partner_inscr_est = fields.Char(
string="State Tax Number",
related="partner_id.inscr_est",
related="partner_id.l10n_br_ie_code",
)

partner_ind_ie_dest = fields.Selection(
Expand Down Expand Up @@ -142,7 +142,7 @@ class DocumentMoveMixin(models.AbstractModel):

company_inscr_est = fields.Char(
string="Company State Tax Number",
related="company_id.inscr_est",
related="company_id.l10n_br_ie_code",
)

company_inscr_est_st = fields.Char(
Expand Down
6 changes: 3 additions & 3 deletions l10n_br_fiscal/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _default_fiscal_profile_id(self, is_company=False):
tracking=True,
)

inscr_est = fields.Char(
l10n_br_ie_code = fields.Char(
tracking=True,
)

Expand Down Expand Up @@ -117,7 +117,7 @@ def _onchange_fiscal_profile_id(self):
def _onchange_ind_ie_dest(self):
for p in self:
if p.ind_ie_dest == NFE_IND_IE_DEST_9:
p.inscr_est = False
p.l10n_br_ie_code = False
p.state_tax_number_ids = False

@api.model
Expand All @@ -128,6 +128,6 @@ def _commercial_fields(self):
"ind_ie_dest",
"fiscal_profile_id",
"ind_final",
"inscr_est",
"l10n_br_ie_code",
"inscr_mun",
]
4 changes: 2 additions & 2 deletions l10n_br_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def _set_nfe40_IEST(self):
stn_id = self.company_id.state_tax_number_ids.filtered(
lambda stn: stn.state_id == dest_state_id
)
iest = stn_id.inscr_est
iest = stn_id.l10n_br_ie_code
iest = re.sub("[^0-9]+", "", iest)
self.company_inscr_est_st = iest

Expand Down Expand Up @@ -1537,7 +1537,7 @@ def action_danfe_nfce_report(self):

def _prepare_nfce_danfe_values(self):
return {
"company_ie": self.company_id.inscr_est,
"company_ie": self.company_id.l10n_br_ie_code,
"company_cnpj": self.company_id.cnpj_cpf,
"company_legal_name": self.company_id.legal_name,
"company_street": self.company_id.street,
Expand Down
2 changes: 1 addition & 1 deletion l10n_br_nfe/models/document_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _compute_nfe_data(self):
rec.nfe40_CPF = rec.cnpj_cpf
else:
rec.nfe40_CNPJ = rec.cnpj_cpf
rec.nfe40_IE = rec.inscr_est
rec.nfe40_IE = rec.l10n_br_ie_code
rec.nfe40_mod = rec.document_type_id.code
rec.nfe40_serie = document.document_serie
rec.nfe40_nNF = document.document_number
Expand Down
8 changes: 4 additions & 4 deletions l10n_br_nfe/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def _compute_nfe40_enderDest(self):
for rec in self:
rec.nfe40_enderDest = rec.id

@api.depends("company_type", "inscr_est", "cnpj_cpf", "country_id")
@api.depends("company_type", "l10n_br_ie_code", "cnpj_cpf", "country_id")
def _compute_nfe_data(self):
"""Set schema data which are not just related fields"""
for rec in self:
Expand Down Expand Up @@ -236,8 +236,8 @@ def _compute_nfe_data(self):
rec.nfe40_CNPJ = ""
rec.nfe40_CPF = ""

if rec.inscr_est:
rec.nfe40_IE = punctuation_rm(rec.inscr_est)
if rec.l10n_br_ie_code:
rec.nfe40_IE = punctuation_rm(rec.l10n_br_ie_code)
else:
rec.nfe40_IE = None

Expand Down Expand Up @@ -276,7 +276,7 @@ def _inverse_nfe40_CPF(self):
def _inverse_nfe40_IE(self):
for rec in self:
if rec.nfe40_IE:
rec.inscr_est = str(rec.nfe40_IE)
rec.l10n_br_ie_code = str(rec.nfe40_IE)

def _inverse_nfe40_CEP(self):
for rec in self:
Expand Down
6 changes: 6 additions & 0 deletions l10n_br_nfe/tests/test_nfe_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,11 @@ def serialize_xml(self, nfe_data):
nfe.send_file_id.store_fname,
)
_logger.info(f"XML file saved at {output}")
import base64

print("*********", xml_path, nfe.xml_error_message)
with open("nfe.xml", "wb") as f:
f.write(base64.b64decode(nfe.send_file_id.datas))
print(output)
diff = main.diff_files(output, xml_path)
return diff
Loading