Skip to content

Commit 09f0511

Browse files
manifestar
1 parent 33b0722 commit 09f0511

File tree

6 files changed

+111
-20
lines changed

6 files changed

+111
-20
lines changed

l10n_br_fiscal_dfe/models/dfe_monitor.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -297,11 +297,12 @@ def _create_dfe_from_resNFe(self, root, nsu):
297297
mde = self.env["l10n_br_nfe.recipient_manifestation_event"].create(
298298
{
299299
"key": nfe_key,
300-
"event_type": "rascunho",
301-
"event_type_selection": "confirmado",
300+
"event_type": "ciente",
301+
"event_type_selection": "ciente",
302302
"company_id": self.env.company.id,
303303
"dfe_access_key_id": access_key.id,
304304
"mde_document_type": "mde_nfe",
305+
"status": "transmitido",
305306
}
306307
)
307308
mde.action_confirm_selection()

l10n_br_nfe/constants/mde.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Copyright (C) 2023 KMEE Informática LTDA
22
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
33

4-
SIT_MANIF_PENDENTE = ("rascunho", "Rascunho")
4+
SIT_MANIF_CIENTE = ("ciente", "Ciente da Operação")
55
SIT_MANIF_CONFIRMADO = ("confirmado", "Confirmada operação")
6+
SIT_MANIF_DESCONHECIDO = ("desconhecido", "Desconhecimento")
7+
SIT_MANIF_NAO_REALIZADO = ("nao_realizado", "Não realizado")
68

79
SITUACAO_MANIFESTACAO = [
8-
SIT_MANIF_PENDENTE,
10+
SIT_MANIF_CIENTE,
911
SIT_MANIF_CONFIRMADO,
12+
SIT_MANIF_DESCONHECIDO,
13+
SIT_MANIF_NAO_REALIZADO,
1014
]

l10n_br_nfe/models/nfe_recipient_manifestation_event.py

+27-8
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
from odoo.exceptions import ValidationError
1212

1313
from ..constants.mde import (
14+
SIT_MANIF_CIENTE,
1415
SIT_MANIF_CONFIRMADO,
16+
SIT_MANIF_DESCONHECIDO,
17+
SIT_MANIF_NAO_REALIZADO,
1518
SITUACAO_MANIFESTACAO,
1619
)
1720

@@ -39,6 +42,19 @@ class NfeRecipientManifestationEvent(models.Model):
3942
index=True,
4043
)
4144

45+
event_type_selection = fields.Selection(
46+
selection=SITUACAO_MANIFESTACAO,
47+
default="ciente",
48+
required=True,
49+
)
50+
51+
status = fields.Selection(
52+
selection=[
53+
("rascunho", "Rascunho"),
54+
("transmitido", "Transmitido"),
55+
],
56+
)
57+
4258
environment = fields.Selection(related="company_id.dfe_environment")
4359

4460
dfe_access_key_id = fields.Many2one(
@@ -53,14 +69,6 @@ class NfeRecipientManifestationEvent(models.Model):
5369
string="MDe Document Type",
5470
)
5571

56-
event_type_selection = fields.Selection(
57-
selection=[
58-
("confirmado", "Confirmada operação"),
59-
],
60-
default="confirmado",
61-
required=True,
62-
)
63-
6472
def name_get(self):
6573
return [(rec.id, f"{rec.key}") for rec in self]
6674

@@ -116,11 +124,22 @@ def action_send_event(self, operation, valid_codes, new_state):
116124

117125
def action_confirm_selection(self):
118126
event_mapping = {
127+
SIT_MANIF_CIENTE[0]: ("ciencia_da_operacao", ["135"], SIT_MANIF_CIENTE[0]),
119128
SIT_MANIF_CONFIRMADO[0]: (
120129
"confirmacao_da_operacao",
121130
["135"],
122131
SIT_MANIF_CONFIRMADO[0],
123132
),
133+
SIT_MANIF_DESCONHECIDO[0]: (
134+
"desconhecimento_da_operacao",
135+
["135"],
136+
SIT_MANIF_DESCONHECIDO[0],
137+
),
138+
SIT_MANIF_NAO_REALIZADO[0]: (
139+
"operacao_nao_realizada",
140+
["135"],
141+
SIT_MANIF_NAO_REALIZADO[0],
142+
),
124143
}
125144

126145
for record in self:

l10n_br_nfe/tests/test_nfe_recipient_manifestation_event.py

+66-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@
1717

1818
response_confirmacao_operacao_rejeicao = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>494</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>494</cStat><xMotivo>Rejeição: Chave de Acesso inexistente</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210200</tpEvento><xEvento>Confirmacao de Operacao registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501
1919

20+
response_ciencia_operacao = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><xMotivo>Teste Ciência da Operação.</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210210</tpEvento><xEvento>Ciencia da Operacao registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501
21+
22+
response_desconhecimento_operacao = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><xMotivo>Teste Desconhecimento da Operação.</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210220</tpEvento><xEvento>Desconhecimento da Operacao registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501
23+
24+
response_operacao_nao_realizada = """<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soap:Body><nfeResultMsg xmlns="http://www.portalfiscal.inf.br/nfe/wsdl/NFeRecepcaoEvento4"><retEnvEvento xmlns="http://www.portalfiscal.inf.br/nfe" versao="1.00"><idLote /><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><retEvento versao="1.00"><infEvento><tpAmb>2</tpAmb><verAplic>SVRS202305251555</verAplic><cStat>135</cStat><xMotivo>Teste Operação não Realizada.</xMotivo><chNFe>31201010588201000105550010038421171838422178</chNFe><tpEvento>210240</tpEvento><xEvento>Operacao nao Realizada registrada</xEvento><nSeqEvento>1</nSeqEvento><CNPJDest>81583054000129</CNPJDest><dhRegEvento>2023-07-10T10:00:00-03:00</dhRegEvento></infEvento></retEvento></retEnvEvento></nfeResultMsg></soap:Body></soap:Envelope>""" # noqa: E501
25+
2026

2127
class FakeRetorno:
2228
def __init__(self, text, status_code=200):
@@ -58,6 +64,36 @@ def mocked_post_confirmacao_invalid_status_error(*args, **kwargs):
5864
)
5965

6066

67+
def mocked_post_ciencia(*args, **kwargs):
68+
return analisar_retorno_raw(
69+
"nfeRecepcaoEvento",
70+
object(),
71+
b"<fake_post/>",
72+
FakeRetorno(response_ciencia_operacao),
73+
retEnvEvento,
74+
)
75+
76+
77+
def mocked_post_desconhecimento(*args, **kwargs):
78+
return analisar_retorno_raw(
79+
"nfeRecepcaoEvento",
80+
object(),
81+
b"<fake_post/>",
82+
FakeRetorno(response_desconhecimento_operacao),
83+
retEnvEvento,
84+
)
85+
86+
87+
def mocked_post_nao_realizada(*args, **kwargs):
88+
return analisar_retorno_raw(
89+
"nfeRecepcaoEvento",
90+
object(),
91+
b"<fake_post/>",
92+
FakeRetorno(response_operacao_nao_realizada),
93+
retEnvEvento,
94+
)
95+
96+
6197
class TestMDe(TransactionCase):
6298
@classmethod
6399
def setUpClass(cls):
@@ -95,15 +131,42 @@ def test_events_success(self):
95131
with mock.patch.object(
96132
DocumentoElectronicoAdapter,
97133
"_post",
98-
side_effect=mocked_post_confirmacao,
134+
side_effect=mocked_post_ciencia,
99135
):
100-
self.mde_id.event_type_selection = "confirmado"
136+
self.mde_id.event_type_selection = "ciente"
101137
self.mde_id.action_confirm_selection()
102-
self.assertEqual(self.mde_id.event_type, "confirmado")
138+
self.assertEqual(self.mde_id.event_type, "ciente")
103139
self.assertEqual(
104140
self.mde_id.display_name, "31201010588201000105550010038421171838422178"
105141
)
106142

143+
with mock.patch.object(
144+
DocumentoElectronicoAdapter,
145+
"_post",
146+
side_effect=mocked_post_confirmacao,
147+
):
148+
self.mde_id.event_type_selection = "confirmado"
149+
self.mde_id.action_confirm_selection()
150+
self.assertEqual(self.mde_id.event_type, "confirmado")
151+
152+
with mock.patch.object(
153+
DocumentoElectronicoAdapter,
154+
"_post",
155+
side_effect=mocked_post_desconhecimento,
156+
):
157+
self.mde_id.event_type_selection = "desconhecido"
158+
self.mde_id.action_confirm_selection()
159+
self.assertEqual(self.mde_id.event_type, "desconhecido")
160+
161+
with mock.patch.object(
162+
DocumentoElectronicoAdapter,
163+
"_post",
164+
side_effect=mocked_post_nao_realizada,
165+
):
166+
self.mde_id.event_type_selection = "nao_realizado"
167+
self.mde_id.action_confirm_selection()
168+
self.assertEqual(self.mde_id.event_type, "nao_realizado")
169+
107170
def test_event_error(self):
108171
with mock.patch.object(
109172
DocumentoElectronicoAdapter,

l10n_br_nfe/views/nfe_recipient_manifestation_event/nfe_recipient_manifestation_event_view.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
<header>
1414
<button
1515
name="action_confirm_selection"
16-
string="Confirmar"
16+
string="Transmitir"
1717
type="object"
1818
/>
1919
<field
20-
name="event_type"
20+
name="status"
2121
statusbar_visible="rascunho,confirmado"
2222
readonly="1"
2323
statusbar_colors='{"rascunho": "gray", "confirmado": "blue"}'

l10n_br_nfe/wizards/nfe_recipient_manifestation_event_wizard.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33

44
class NfeRecipientManifestationEventWizard(models.TransientModel):
55
_name = "nfe_recipient_manifestation_event.wizard"
6-
_description = "Wizard para Criar MDe"
6+
_description = "Wizard to manifest"
77

88
event_type_selection = fields.Selection(
99
selection=[
10+
("ciente", "Ciente da Operação"),
1011
("confirmado", "Confirmada operação"),
12+
("desconhecido", "Desconhecimento"),
13+
("nao_realizado", "Não realizado"),
1114
],
12-
default="confirmado",
15+
default="ciente",
1316
required=True,
1417
)
1518

@@ -22,11 +25,12 @@ def action_create_nfe_recipient_manifestation_event(self):
2225
mde = self.env["l10n_br_nfe.recipient_manifestation_event"].create(
2326
{
2427
"key": dfe_access_key.key,
25-
"event_type": "confirmado",
28+
"event_type": self.event_type_selection,
2629
"event_type_selection": self.event_type_selection,
2730
"company_id": self.env.company.id,
2831
"dfe_access_key_id": dfe_access_key.id,
2932
"mde_document_type": "mde_nfe",
33+
"status": "transmitido",
3034
}
3135
)
3236

0 commit comments

Comments
 (0)