Skip to content

Commit

Permalink
Merge f540e4d into 70936d6
Browse files Browse the repository at this point in the history
  • Loading branch information
luismalta committed Dec 6, 2019
2 parents 70936d6 + f540e4d commit 85f649f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
6 changes: 4 additions & 2 deletions l10n_br_base/models/res_company.py
Expand Up @@ -164,7 +164,8 @@ def _onchange_state(self):

@api.onchange("cnpj_cpf")
def _onchange_cnpj_cpf(self):
self.cnpj_cpf = cnpj_cpf.formata(self.cnpj_cpf)
if self.cnpj_cpf:
self.cnpj_cpf = cnpj_cpf.formata(self.cnpj_cpf)

@api.onchange("city_id")
def _onchange_city_id(self):
Expand All @@ -182,4 +183,5 @@ def _onchange_city_id(self):

@api.onchange("zip")
def _onchange_zip(self):
self.zip = misc.format_zipcode(self.zip, self.country_id.code)
if self.zip:
self.zip = misc.format_zipcode(self.zip, self.country_id.code)
25 changes: 14 additions & 11 deletions l10n_br_base/models/res_partner.py
Expand Up @@ -134,15 +134,17 @@ def _check_cnpj_inscr_est(self):
def _check_cnpj_cpf(self):
result = True
for record in self:
country_code = record.country_id.code or ""
if record.cnpj_cpf and country_code.upper() == "BR":
if record.is_company:
if not cnpj_cpf.validar(record.cnpj_cpf):
result = False
document = "CNPJ"
elif not cnpj_cpf.validar(record.cnpj_cpf):
result = False
document = "CPF"
if record.country_id:
country_code = record.country_id.code or ""
if country_code:
if record.cnpj_cpf and country_code.upper() == "BR":
if record.is_company:
if not cnpj_cpf.validar(record.cnpj_cpf):
result = False
document = "CNPJ"
elif not cnpj_cpf.validar(record.cnpj_cpf):
result = False
document = "CPF"
if not result:
raise ValidationError(_("{} Invalid!").format(document))

Expand Down Expand Up @@ -211,8 +213,9 @@ def get_street_fields(self):
@api.multi
def _set_street(self):
company_country = self.env.user.company_id.country_id
if company_country.code.upper() != "BR":
return super(Partner, self)._set_street()
if company_country.code:
if company_country.code.upper() != "BR":
return super(Partner, self)._set_street()

@api.onchange("cnpj_cpf")
def _onchange_cnpj_cpf(self):
Expand Down

0 comments on commit 85f649f

Please sign in to comment.