Skip to content

Commit

Permalink
Merge PR #3280 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by antoniospneto
  • Loading branch information
OCA-git-bot committed Aug 27, 2024
2 parents 98b946e + 6d12a5e commit 08e0c9b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
18 changes: 18 additions & 0 deletions l10n_br_base/models/party_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ class PartyMixin(models.AbstractModel):
_name = "l10n_br_base.party.mixin"
_description = "Brazilian partner and company data mixin"

cnpj_cpf_stripped = fields.Char(
string="CNPJ/CPF Stripped",
help="CNPJ/CPF without special characters",
compute="_compute_cnpj_cpf_stripped",
store=True,
index=True,
)

cnpj_cpf = fields.Char(
string="CNPJ/CPF",
size=18,
Expand Down Expand Up @@ -61,6 +69,16 @@ class PartyMixin(models.AbstractModel):
size=32,
)

@api.depends("cnpj_cpf")
def _compute_cnpj_cpf_stripped(self):
for record in self:
if record.cnpj_cpf:
record.cnpj_cpf_stripped = "".join(
char for char in record.cnpj_cpf if char.isalnum()
)
else:
record.cnpj_cpf_stripped = False

@api.onchange("cnpj_cpf")
def _onchange_cnpj_cpf(self):
self.cnpj_cpf = cnpj_cpf.formata(str(self.cnpj_cpf))
Expand Down
5 changes: 4 additions & 1 deletion l10n_br_base/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
<field name="arch" type="xml">
<field name="name" position="after">
<field name="legal_name" />
<field name="cnpj_cpf" />
<field
name="cnpj_cpf"
filter_domain="['|', ('cnpj_cpf', 'ilike', self), ('cnpj_cpf_stripped', 'ilike', self)]"
/>
</field>
</field>
</record>
Expand Down

0 comments on commit 08e0c9b

Please sign in to comment.