Skip to content

Commit

Permalink
[REF] extract l10n_br_fiscal_edi <- l10n_br_fiscal
Browse files Browse the repository at this point in the history
[REF] extract l10n_br_fiscal_edi from l10n_br_fiscal 2/2
  • Loading branch information
rvalyi committed Aug 9, 2024
1 parent 6c30c9d commit 5e9eb17
Show file tree
Hide file tree
Showing 40 changed files with 307 additions and 257 deletions.
14 changes: 4 additions & 10 deletions l10n_br_fiscal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,13 @@
"views/subsequent_operation_view.xml",
"views/subsequent_document_view.xml",
"views/uom_uom.xml",
"views/invalidate_number_view.xml",
# "views/invalidate_number_view.xml",
"views/city_taxation_code.xml",
"views/operation_dashboard_view.xml",
"views/document_event_view.xml",
# "views/document_event_view.xml",
# Reports
"views/document_event_report.xml",
"views/document_event_template.xml",
# Wizards
"wizards/document_cancel_wizard.xml",
"wizards/document_correction_wizard.xml",
"wizards/document_status_wizard.xml",
"wizards/invalidate_number_wizard.xml",
"wizards/document_import_wizard_mixin.xml",
# "views/document_event_report.xml",
# "views/document_event_template.xml",
# Actions
"views/l10n_br_fiscal_action.xml",
# Menus
Expand Down
7 changes: 4 additions & 3 deletions l10n_br_fiscal/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
from . import document_move_mixin
from . import document_fiscal_line_mixin_methods
from . import document_fiscal_line_mixin
from . import document_event
from . import document_eletronic
from . import invalidate_number

# from . import document_event
# from . import document_eletronic
# from . import invalidate_number
from . import comment
from . import ibpt
from . import cfop
Expand Down
48 changes: 28 additions & 20 deletions l10n_br_fiscal/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from odoo.exceptions import ValidationError

from ..constants.fiscal import (
DOCUMENT_ISSUER,
DOCUMENT_ISSUER_COMPANY,
DOCUMENT_ISSUER_DICT,
DOCUMENT_ISSUER_PARTNER,
Expand Down Expand Up @@ -49,7 +50,8 @@ class Document(models.Model):
_name = "l10n_br_fiscal.document"
_inherit = [
"l10n_br_fiscal.document.mixin.fields",
"l10n_br_fiscal.document.electronic",
# "l10n_br_fiscal.document.electronic",
"l10n_br_fiscal.document.workflow",
"l10n_br_fiscal.document.move.mixin",
"mail.thread",
]
Expand Down Expand Up @@ -140,22 +142,22 @@ class Document(models.Model):
default=EDOC_PURPOSE_NORMAL,
)

event_ids = fields.One2many(
comodel_name="l10n_br_fiscal.event",
inverse_name="document_id",
string="Events",
copy=False,
readonly=True,
)

correction_event_ids = fields.One2many(
comodel_name="l10n_br_fiscal.event",
inverse_name="document_id",
domain=[("type", "=", "14")],
string="Correction Events",
copy=False,
readonly=True,
)
# event_ids = fields.One2many(
# comodel_name="l10n_br_fiscal.event",
# inverse_name="document_id",
# string="Events",
# copy=False,
# readonly=True,
# )
#
# correction_event_ids = fields.One2many(
# comodel_name="l10n_br_fiscal.event",
# inverse_name="document_id",
# domain=[("type", "=", "14")],
# string="Correction Events",
# copy=False,
# readonly=True,
# )

document_type = fields.Char(
string="Document Type Code",
Expand All @@ -175,6 +177,11 @@ class Document(models.Model):
# TODO Porque não usar o campo state do fiscal.document???
state = fields.Selection(related="state_edoc", string="State")

issuer = fields.Selection(
selection=DOCUMENT_ISSUER,
default=DOCUMENT_ISSUER_COMPANY,
)

document_subsequent_ids = fields.One2many(
comodel_name="l10n_br_fiscal.subsequent.document",
inverse_name="source_document_id",
Expand Down Expand Up @@ -242,9 +249,10 @@ def _check_number(self):
domain.append(("partner_id", "=", record.partner_id.id))
else:
if record.document_serie_id:
invalid_number = record.document_serie_id._is_invalid_number(
record.document_number
)
invalid_number = False
# record.document_serie_id._is_invalid_number(
# record.document_number
# )

documents = record.env["l10n_br_fiscal.document"].search_count(domain)

Expand Down
41 changes: 20 additions & 21 deletions l10n_br_fiscal/models/document_serie.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ class DocumentSerie(models.Model):
related="internal_sequence_id.number_next",
)

invalidate_number_id = fields.One2many(
comodel_name="l10n_br_fiscal.invalidate.number",
inverse_name="document_serie_id",
string="Invalidate Number Range",
)
# invalidate_number_id = fields.One2many(
# comodel_name="l10n_br_fiscal.invalidate.number",
# inverse_name="document_serie_id",
# string="Invalidate Number Range",
# )

@api.model
def _create_sequence(self, values):
Expand Down Expand Up @@ -81,26 +81,25 @@ def create(self, vals_list):
def name_get(self):
return [(r.id, "{}".format(r.name)) for r in self]

def _is_invalid_number(self, document_number):
self.ensure_one()
is_invalid_number = True
# TODO Improve this implementation!
invalids = self.env["l10n_br_fiscal.invalidate.number"].search(
[("state", "=", "done"), ("document_serie_id", "=", self.id)]
)
invalid_numbers = []
for invalid in invalids:
invalid_numbers += range(invalid.number_start, invalid.number_end + 1)
if int(document_number) not in invalid_numbers:
is_invalid_number = False
return is_invalid_number
# def _is_invalid_number(self, document_number):
# self.ensure_one()
# is_invalid_number = True
# # TODO Improve this implementation!
# invalids = self.env["l10n_br_fiscal.invalidate.number"].search(
# [("state", "=", "done"), ("document_serie_id", "=", self.id)]
# )
# invalid_numbers = []
# for invalid in invalids:
# invalid_numbers += range(invalid.number_start, invalid.number_end + 1)
# if int(document_number) not in invalid_numbers:
# is_invalid_number = False
# return is_invalid_number

def next_seq_number(self):
self.ensure_one()
document_number = self.internal_sequence_id._next()
if self._is_invalid_number(document_number) or self.check_number_in_use(
document_number
):
# if self._is_invalid_number(document_number) or self.check_number_in_use(
if self.check_number_in_use(document_number):
document_number = self.next_seq_number()
return document_number

Expand Down
27 changes: 14 additions & 13 deletions l10n_br_fiscal/models/document_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ def _exec_after_SITUACAO_EDOC_EM_DIGITACAO(self, old_state, new_state):

def _exec_after_SITUACAO_EDOC_A_ENVIAR(self, old_state, new_state):
self.ensure_one()
if self._direct_draft_send():
self.action_document_send()
# if self._direct_draft_send():
# self.action_document_send()

def _exec_after_SITUACAO_EDOC_ENVIADA(self, old_state, new_state):
pass
Expand Down Expand Up @@ -322,20 +322,21 @@ def _document_export(self):
pass

def action_document_send(self):
to_send = self.filtered(
lambda d: d.state_edoc
in (
SITUACAO_EDOC_A_ENVIAR,
SITUACAO_EDOC_ENVIADA,
SITUACAO_EDOC_REJEITADA,
)
)
if to_send:
to_send._document_send()
pass
# to_send = self.filtered(
# lambda d: d.state_edoc
# in (
# SITUACAO_EDOC_A_ENVIAR,
# SITUACAO_EDOC_ENVIADA,
# SITUACAO_EDOC_REJEITADA,
# )
# )
# if to_send:
# to_send._document_send()

def document_back2draft(self):
self.xml_error_message = False
self.file_report_id = False
# self.file_report_id = False
if self.issuer == DOCUMENT_ISSUER_COMPANY:
self._change_state(SITUACAO_EDOC_EM_DIGITACAO)
else:
Expand Down
7 changes: 0 additions & 7 deletions l10n_br_fiscal/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,7 @@
"uom_alternative_user","UOM alternative for User","model_uom_uom_alternative","l10n_br_fiscal.group_user",1,0,0,0
"uom_alternative_manager","UOM alternative for Manager","model_uom_uom_alternative","l10n_br_fiscal.group_manager",1,0,0,0
"uom_alternative_maintenance","UOM alternative for Maintenance","model_uom_uom_alternative","l10n_br_fiscal.group_data_maintenance",1,1,1,1
"l10n_br_fiscal_event_user","Fiscal Document Event for User","model_l10n_br_fiscal_event","l10n_br_fiscal.group_user",1,1,1,0
"l10n_br_fiscal_invalidate_number_user","user_l10n_br_fiscal_invalidate_number","model_l10n_br_fiscal_invalidate_number","l10n_br_fiscal.group_user",1,0,0,0
"l10n_br_fiscal_invalidate_number_manager","manager_l10n_br_fiscal_invalidate_number","model_l10n_br_fiscal_invalidate_number","l10n_br_fiscal.group_manager",1,1,1,1
"l10n_br_fiscal_city_taxation_code_user","Fiscal City Taxation Code for User","model_l10n_br_fiscal_city_taxation_code","l10n_br_fiscal.group_user",1,1,1,0
"l10n_br_fiscal_city_taxation_code_manager","Fiscal City Taxation Code for Manager","model_l10n_br_fiscal_city_taxation_code","l10n_br_fiscal.group_user",1,1,1,1
"l10n_br_fiscal_base_wizard_mixin_user",l10n_br_fiscal_base_wizard_mixin,model_l10n_br_fiscal_base_wizard_mixin,base.group_user,1,1,1,1
"l10n_br_fiscal_document_cancel_wizard_user",l10n_br_fiscal_document_cancel_wizard,model_l10n_br_fiscal_document_cancel_wizard,base.group_user,1,1,1,1
"l10n_br_fiscal_document_correction_wizard_user",l10n_br_fiscal_document_correction_wizard,model_l10n_br_fiscal_document_correction_wizard,base.group_user,1,1,1,1
"l10n_br_fiscal_document_status_wizard_user",l10n_br_fiscal_document_status_wizard,model_l10n_br_fiscal_document_status_wizard,base.group_user,1,1,1,1
"l10n_br_fiscal_invalidate_number_wizard_user",l10n_br_fiscal_invalidate_number_wizard,model_l10n_br_fiscal_invalidate_number_wizard,base.group_user,1,1,1,1
"l10n_br_fiscal_document_import_wizard_mixin_user",l10n_br_fiscal_document_import_wizard_mixin_user,model_l10n_br_fiscal_document_import_wizard_mixin,base.group_user,1,1,1,1
13 changes: 5 additions & 8 deletions l10n_br_fiscal/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

/*
:Author: David Goodger ([email protected])
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +274,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: gray; } /* line numbers */
pre.code .ln { color: grey; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +300,7 @@
span.pre {
white-space: pre }

span.problematic, pre.problematic {
span.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -367,7 +366,7 @@ <h1 class="title">Módulo fiscal brasileiro</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1bed2db989532cf5724540e0c3a33de3c3d40c7a665f7ac3b21407cb55e140a2
!! source digest: sha256:4b0134f56ded2ac7e1573d5c13e7cd6542def886778eb4304d7dae52a2dc0d95
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Production/Stable" src="https://img.shields.io/badge/maturity-Production%2FStable-green.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/l10n-brazil/tree/14.0/l10n_br_fiscal"><img alt="OCA/l10n-brazil" src="https://img.shields.io/badge/github-OCA%2Fl10n--brazil-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/l10n-brazil-14-0/l10n-brazil-14-0-l10n_br_fiscal"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/l10n-brazil&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<img alt="https://raw.githubusercontent.com/OCA/l10n-brazil/14.0/l10n_br_fiscal/static/img/fiscal_dashboard.png" src="https://raw.githubusercontent.com/OCA/l10n-brazil/14.0/l10n_br_fiscal/static/img/fiscal_dashboard.png" />
Expand Down Expand Up @@ -534,9 +533,7 @@ <h1>Contributors</h1>
<div class="section" id="maintainers">
<h1>Maintainers</h1>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
18 changes: 9 additions & 9 deletions l10n_br_fiscal/tests/test_fiscal_document_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,17 +180,17 @@ def test_nfe_same_state(self):

self.nfe_same_state.action_document_send()

self.assertEqual(
self.nfe_same_state.state_edoc,
SITUACAO_EDOC_AUTORIZADA,
"Document is not in Authorized state",
)
# self.assertEqual(
# self.nfe_same_state.state_edoc,
# SITUACAO_EDOC_AUTORIZADA,
# "Document is not in Authorized state",
# )

# Total value of the products
self.assertEqual(self.nfe_same_state.amount_price_gross, 200)
# self.assertEqual(self.nfe_same_state.amount_price_gross, 200)

result = self.nfe_same_state.action_document_cancel()
self.assertTrue(result)
# result = self.nfe_same_state.action_document_cancel()
# self.assertTrue(result)

def test_nfe_other_state(self):
"""Test NFe other state."""
Expand Down Expand Up @@ -1076,7 +1076,7 @@ def test_nfe_comments(self):
additional_data = self.nfe_not_taxpayer.fiscal_line_ids[0].additional_data
self.assertEqual(
additional_data,
"manual comment test - Valor Aprox. dos Tributos: R$ 0,00"
"manual comment test - Valor Aprox. dos Tributos: R$ 0,00",
# TODO FIXME changed 0.00 to 0,00 to get tests pass on v13, but not
# correct
)
Expand Down
16 changes: 8 additions & 8 deletions l10n_br_fiscal/tests/test_tax_benefit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from odoo.tests import SavepointCase

from ..constants.fiscal import SITUACAO_EDOC_A_ENVIAR, SITUACAO_EDOC_AUTORIZADA
from ..constants.fiscal import SITUACAO_EDOC_A_ENVIAR


class TestTaxBenefit(SavepointCase):
Expand Down Expand Up @@ -64,11 +64,11 @@ def test_nfe_tax_benefit(self):

self.nfe_tax_benefit.action_document_send()

self.assertEqual(
self.nfe_tax_benefit.state_edoc,
SITUACAO_EDOC_AUTORIZADA,
"Document is not in Authorized state",
)
# self.assertEqual(
# self.nfe_tax_benefit.state_edoc,
# SITUACAO_EDOC_AUTORIZADA,
# "Document is not in Authorized state",
# )

result = self.nfe_tax_benefit.action_document_cancel()
self.assertTrue(result)
# result = self.nfe_tax_benefit.action_document_cancel()
# self.assertTrue(result)
19 changes: 9 additions & 10 deletions l10n_br_fiscal/tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from ..constants.fiscal import (
SITUACAO_EDOC_A_ENVIAR,
SITUACAO_EDOC_AUTORIZADA,
SITUACAO_EDOC_CANCELADA,
SITUACAO_EDOC_EM_DIGITACAO,
SITUACAO_EDOC_REJEITADA,
Expand Down Expand Up @@ -37,9 +36,9 @@ def test_no_electronic_01_confirm(self):
), "Error with document workflow, state 'SITUACAO_EDOC_A_ENVIAR' "

self.fiscal_document.action_document_send()
assert (
self.fiscal_document.state_edoc == SITUACAO_EDOC_AUTORIZADA
), "Error with document workflow, state 'SITUACAO_EDOC_AUTORIZADA' "
# assert (
# self.fiscal_document.state_edoc == SITUACAO_EDOC_AUTORIZADA
# ), "Error with document workflow, state 'SITUACAO_EDOC_AUTORIZADA' "

def test_electronic_01_confirm(self):
self.fiscal_document.document_electronic = True
Expand All @@ -54,9 +53,9 @@ def test_electronic_01_confirm(self):
), "Error with document workflow, state 'SITUACAO_EDOC_A_ENVIAR' "

self.fiscal_document.action_document_send()
assert (
self.fiscal_document.state_edoc == SITUACAO_EDOC_AUTORIZADA
), "Error with document workflow, state 'SITUACAO_EDOC_AUTORIZADA' "
# assert (
# self.fiscal_document.state_edoc == SITUACAO_EDOC_AUTORIZADA
# ), "Error with document workflow, state 'SITUACAO_EDOC_AUTORIZADA' "

def test_electronic_01_rejeitada(self):
self.fiscal_document.document_electronic = True
Expand All @@ -73,9 +72,9 @@ def test_electronic_01_rejeitada(self):
), "Error with document workflow, state 'SITUACAO_EDOC_REJEITADA' "

self.fiscal_document.action_document_send()
assert (
self.fiscal_document.state_edoc == SITUACAO_EDOC_AUTORIZADA
), "Error with document workflow, state 'SITUACAO_EDOC_AUTORIZADA' "
# assert (
# self.fiscal_document.state_edoc == SITUACAO_EDOC_AUTORIZADA
# ), "Error with document workflow, state 'SITUACAO_EDOC_AUTORIZADA' "

def test_no_electronic_01_draft_cancel(self):
self.fiscal_document.document_electronic = False
Expand Down
Loading

0 comments on commit 5e9eb17

Please sign in to comment.