Skip to content

[14.0][IMP] l10n_br_fiscal,nfe: CSRT #3778

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

Draft
wants to merge 4 commits into
base: 14.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
8 changes: 8 additions & 0 deletions l10n_br_base/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ class Partner(models.Model):

rntrc_code = fields.Char(string="RNTRC Code", size=12)

is_technical_support = fields.Boolean(string="Is technical support?")

nfe40_idCSRT = fields.Char(string="ID CSRT")

CSRT = fields.Char(string="Token CSRT")

nfe40_hashCSRT = fields.Char(string="Hash CSRT")

cei_code = fields.Char(string="CEI Code", size=12)

union_entity_code = fields.Char(string="Union Entity code")
Expand Down
13 changes: 13 additions & 0 deletions l10n_br_base/views/res_partner_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,19 @@
domain="[('country_id', '=', %(base.br)d)]"
/>
<field name="rntrc_code" />
<field name="is_technical_support" />
<field
name="nfe40_idCSRT"
attrs="{'invisible': [('is_technical_support','!=', True)]}"
/>
<field
name="CSRT"
attrs="{'invisible': [('is_technical_support','!=', True)]}"
/>
<field
name="nfe40_hashCSRT"
attrs="{'invisible': [('is_technical_support','!=', True)]}"
/>
</group>
</group>
</page>
Expand Down
11 changes: 11 additions & 0 deletions l10n_br_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import base64
import hashlib
import logging
import re
import string
Expand Down Expand Up @@ -1113,6 +1114,16 @@
)
record.document_key = chave_edoc.chave

# Compute CSRT hash
if record.nfe40_infRespTec and record.nfe40_infRespTec.CSRT:
token_csrt = record.nfe40_infRespTec.CSRT
seed = token_csrt + record.document_key
hashed = hashlib.sha1(seed.encode()).hexdigest()

Check warning on line 1121 in l10n_br_nfe/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfe/models/document.py#L1119-L1121

Added lines #L1119 - L1121 were not covered by tests

# Convert hex to base64
hashed_b64 = base64.b64encode(bytes.fromhex(hashed)).decode()
record.nfe40_infRespTec.nfe40_hashCSRT = hashed_b64

Check warning on line 1125 in l10n_br_nfe/models/document.py

View check run for this annotation

Codecov / codecov/patch

l10n_br_nfe/models/document.py#L1124-L1125

Added lines #L1124 - L1125 were not covered by tests

def _nfe_consult_receipt(self):
self.ensure_one()
processor = self._edoc_processor()
Expand Down
3 changes: 3 additions & 0 deletions l10n_br_nfe/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class ResCompany(spec_models.SpecModel):
nfe40_fone = fields.Char(related="partner_id.nfe40_fone")
nfe40_CRT = fields.Selection(related="tax_framework")

nfe40_idCSRT = fields.Char(related="partner_id.nfe40_idCSRT")
nfe40_hashCSRT = fields.Char(related="partner_id.nfe40_hashCSRT")

nfe40_enderEmit = fields.Many2one(
comodel_name="res.partner",
related="partner_id",
Expand Down