-
-
Notifications
You must be signed in to change notification settings - Fork 244
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
[12.0][l10n_br_base][BACKPORT] add partner pix #2189
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
<!-- | ||
Partners Extension | ||
--> | ||
<record id="l10n_br_account_partner_form" model="ir.ui.view"> | ||
<field name="name">l10n_br_account.res.partner.form</field> | ||
<field name="model">res.partner</field> | ||
<field name="priority">99</field> | ||
<field name="inherit_id" ref="account.view_partner_property_form" /> | ||
<field name="arch" type="xml"> | ||
<group position="after" name="banks"> | ||
<div /> | ||
<group | ||
string="Brazilian Instant Payment Keys (PIX)" | ||
name="pix_keys" | ||
groups="account.group_account_invoice,account.group_account_readonly" | ||
attrs="{'invisible': [('show_l10n_br', '=', False)]}" | ||
> | ||
<field name="show_l10n_br" invisible="1" /> | ||
<field name="pix_key_ids" nolabel="1"> | ||
<tree editable="bottom"> | ||
<field name="partner_id" invisible="1" /> | ||
<field name="sequence" widget="handle" /> | ||
<field name="key_type" /> | ||
<field name="key" /> | ||
<field name="partner_bank_id" /> | ||
</tree> | ||
</field> | ||
</group> | ||
</group> | ||
</field> | ||
</record> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
<odoo> | ||
|
||
<!-- | ||
Resource: res.partner.pix | ||
Partner: AMD do Brasil | ||
--> | ||
<record id="res_partner_amd_pix_cnpj" model="res.partner.pix"> | ||
<field name="partner_id" ref="res_partner_amd" /> | ||
<field name="key_type">cnpj_cpf</field> | ||
<field name="key">62228384000151</field> | ||
</record> | ||
|
||
<record id="res_partner_amd_pix_phone" model="res.partner.pix"> | ||
<field name="partner_id" ref="res_partner_amd" /> | ||
<field name="key_type">phone</field> | ||
<field name="key">1144576060</field> | ||
</record> | ||
|
||
<record id="res_partner_amd_pix_email" model="res.partner.pix"> | ||
<field name="partner_id" ref="res_partner_amd" /> | ||
<field name="key_type">email</field> | ||
<field name="key">[email protected]</field> | ||
</record> | ||
|
||
<record id="res_partner_amd_evp" model="res.partner.pix"> | ||
<field name="partner_id" ref="res_partner_amd" /> | ||
<field name="key_type">evp</field> | ||
<field name="key">123e4567-e12b-12d1-a456-426655440000</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
import phonenumbers | ||
from email_validator import EmailSyntaxError, validate_email | ||
from erpbrasil.base.fiscal import cnpj_cpf | ||
|
||
from odoo import _, api, fields, models | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class PartnerPix(models.Model): | ||
_name = "res.partner.pix" | ||
_description = "Brazilian instant payment ecosystem (Pix)" | ||
_order = "sequence, id" | ||
_rec_name = "key" | ||
|
||
_sql_constraints = [ | ||
( | ||
"partner_pix_key_unique", | ||
"unique(key_type, key, partner_id)", | ||
"A Pix Key with this values already exists in this partner.", | ||
) | ||
] | ||
|
||
KEY_TYPES = [ | ||
("cnpj_cpf", _("CPF or CNPJ")), | ||
("phone", _("Phone Number")), | ||
("email", _("E-mail")), | ||
("evp", _("Random Key")), | ||
] | ||
|
||
partner_id = fields.Many2one( | ||
comodel_name="res.partner", | ||
string="Partner", | ||
ondelete="cascade", | ||
required=True, | ||
) | ||
sequence = fields.Integer(default=10) | ||
key_type = fields.Selection( | ||
selection=KEY_TYPES, | ||
string="Type", | ||
required=True, | ||
) | ||
key = fields.Char( | ||
help="PIX Addressing key", | ||
required=True, | ||
) | ||
|
||
partner_bank_id = fields.Many2one( | ||
comodel_name="res.partner.bank", | ||
string="Bank Account", | ||
domain="[('partner_id', '=', partner_id)]", | ||
) | ||
|
||
def _normalize_email(self, email): | ||
try: | ||
result = validate_email( | ||
email, | ||
check_deliverability=False, | ||
) | ||
except EmailSyntaxError: | ||
raise ValidationError(_(f"{email.strip()} is an invalid email")) | ||
normalized_email = result["local"].lower() + "@" + result["domain_i18n"] | ||
if len(normalized_email) > 77: | ||
raise ValidationError( | ||
_( | ||
f"The email is too long, " | ||
f"a maximum of 77 characters is allowed: \n{email.strip()}" | ||
) | ||
) | ||
return normalized_email | ||
|
||
def _normalize_phone(self, phone): | ||
try: | ||
phonenumber = phonenumbers.parse(phone, "BR") | ||
except phonenumbers.phonenumberutil.NumberParseException as e: | ||
raise ValidationError(_(f"Unable to parse {phone}: {str(e)}")) | ||
if not phonenumbers.is_possible_number(phonenumber): | ||
raise ValidationError( | ||
_(f"Impossible number {phone}: probably invalid number of digits.") | ||
) | ||
if not phonenumbers.is_valid_number(phonenumber): | ||
raise ValidationError( | ||
_(f"Invalid number {phone}: probably incorrect prefix.") | ||
) | ||
phone = phonenumbers.format_number( | ||
phonenumber, phonenumbers.PhoneNumberFormat.E164 | ||
) | ||
return phone | ||
|
||
def _normalize_cnpj_cpf(self, doc_number): | ||
doc_number = "".join(char for char in doc_number if char.isdigit()) | ||
if not 11 <= len(doc_number) <= 14: | ||
raise ValidationError( | ||
_( | ||
f"Invalid Document Number {doc_number}: " | ||
f"\nThe CPF must have 11 digits and the CNPJ 14 digits." | ||
) | ||
) | ||
is_valid = cnpj_cpf.validar(doc_number) | ||
if not is_valid: | ||
raise ValidationError(_(f"Invalid Document Number: {doc_number}")) | ||
return doc_number | ||
|
||
def _normalize_evp(self, key): | ||
# EVP: Endereço Virtual de Pagamento (chave aleatória) | ||
# ex: 123e4567-e12b-12d1-a456-426655440000 | ||
key = "".join(key.split()) | ||
if len(key) != 36: | ||
raise ValidationError( | ||
_(f"Invalid Random Key: {key}, cannot be longer than 35 characters") | ||
) | ||
blocks = key.split("-") | ||
if len(blocks) != 5: | ||
raise ValidationError( | ||
_(f"Invalid Random Key: {key}, the key must consist of five blocks.") | ||
) | ||
for block in blocks: | ||
try: | ||
int(block, 16) | ||
except ValueError: | ||
raise ValidationError( | ||
_( | ||
f"Invalid Random Key: {key} \nthe block {block} " | ||
f"is not a valid hexadecimal format." | ||
) | ||
) | ||
return key | ||
|
||
@api.model | ||
def create(self, vals): | ||
self.check_vals(vals) | ||
return super(PartnerPix, self).create(vals) | ||
|
||
def write(self, vals): | ||
self.check_vals(vals) | ||
return super(PartnerPix, self).write(vals) | ||
|
||
def check_vals(self, vals): | ||
key_type = vals.get("key_type") or self.key_type | ||
key = vals.get("key") or self.key | ||
if not key or not key_type: | ||
return | ||
if key_type == "email": | ||
key = self._normalize_email(key) | ||
elif key_type == "phone": | ||
key = self._normalize_phone(key) | ||
elif key_type == "cnpj_cpf": | ||
key = self._normalize_cnpj_cpf(key) | ||
elif key_type == "evp": | ||
key = self._normalize_evp(key) | ||
vals["key"] = key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
* Renato Lima <[email protected]> | ||
* Raphaël Valyi <[email protected]> | ||
* Luis Felipe Mileo <[email protected]> | ||
* Michell Stuttgart <[email protected]> | ||
* `Akretion <https://www.akretion.com/pt-BR>`_: | ||
|
||
* Renato Lima <[email protected]> | ||
* Raphaël Valyi <[email protected]> | ||
|
||
* `KMEE <https://www.kmee.com.br>`_: | ||
|
||
* Luis Felipe Mileo <[email protected]> | ||
* Michell Stuttgart <[email protected]> | ||
|
||
* `Engenere <https://engenere.one>`_: | ||
|
||
* Antônio S. Pereira Neto <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
"id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" | ||
"state_tax_numbers_user","State Tax Numbers for User","model_state_tax_numbers","base.group_user",1,0,0,0 | ||
"state_tax_numbers_manager","State Tax Numbers for Manager","model_state_tax_numbers","base.group_system",1,1,1,1 | ||
"res_partner_pix_user","Partner PIX for User","model_res_partner_pix","base.group_user",1,0,0,0 | ||
"res_partner_pix_manager","Partner PIX for Partner Manager","model_res_partner_pix","base.group_partner_manager",1,1,1,1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aproveitando que você esta alterando esse trecho de código se tiver tempo poderia utilizar o módulo:
https://github.com/odoo/odoo/blob/16.0/addons/mail/tools/mail_validation.py#L16-L21
É um trecho do Odoo que mantem a compatibilidade caso o módulo email_validator não esteja instalado, se vc procurar tem vários exemplos no código.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opa Mileo, eu não vi como é na v16 mas na v14 esse módulo limitava as funcionalidade do email_validator. Agora não lembro bem o motivo, mas eu tinha olhado essa opção.