Skip to content

Commit

Permalink
[RFC] l10n_br_cte: full refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelsavegnago committed Sep 14, 2024
1 parent ca54cbc commit b7b9408
Show file tree
Hide file tree
Showing 18 changed files with 892 additions and 445 deletions.
5 changes: 3 additions & 2 deletions l10n_br_cte/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"website": "https://github.com/OCA/l10n-brazil",
"development_status": "Alpha",
"depends": [
"l10n_br_fiscal",
"l10n_br_fiscal_edi",
"l10n_br_cte_spec",
"l10n_br_fiscal_certificate",
"spec_driven_model",
Expand All @@ -27,13 +27,14 @@
"modal/modal_aereo.xml",
"views/res_company.xml",
"views/cte_document.xml",
"wizards/document_correction_wizard.xml",
],
"post_init_hook": "post_init_hook",
"installable": True,
"auto_install": False,
"external_dependencies": {
"python": [
"nfelib>=2.0.0",
"nfelib<=2.0.7",
"erpbrasil.assinatura>=1.7.0",
"erpbrasil.transmissao>=1.1.0",
"erpbrasil.edoc>=2.5.2",
Expand Down
20 changes: 6 additions & 14 deletions l10n_br_cte/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,12 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import SUPERUSER_ID, api

from odoo.addons.spec_driven_model import hooks


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
hooks.register_hook(
env,
"l10n_br_cte",
"odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00",
)

hooks.post_init_hook(
cr,
registry,
"l10n_br_cte",
"odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00",
)
env["cte.40.tcte_infcte"]._register_hook()
# hooks.register_hook(
# env,
# "l10n_br_cte",
# "odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00",
# )
1 change: 1 addition & 0 deletions l10n_br_cte/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
from . import document_supplement
from . import document_transported_vehicles
from . import normal_cte_infos
from . import comment
4 changes: 3 additions & 1 deletion l10n_br_cte/models/aquaviario.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ class Aquav(spec_models.StackedModel):

cte40_vAFRMM = fields.Monetary(related="document_id.cte40_vAFRMM")

cte40_vPrest = fields.Monetary(related="document_id.cte40_vPrest")
cte40_vPrest = fields.Monetary(
related="document_id.cte40_vTPrest"
) # TODO: avaliar melhor

cte40_xNavio = fields.Char(related="document_id.cte40_xNavio")

Expand Down
45 changes: 45 additions & 0 deletions l10n_br_cte/models/comment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright 2024 - TODAY, Marcel Savegnago <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields

from odoo.addons.spec_driven_model.models import spec_models


class CTeComment(spec_models.StackedModel):

_name = "l10n_br_fiscal.comment"
_inherit = ["l10n_br_fiscal.comment", "cte.40.tcte_obscont", "cte.40.tcte_obsfisco"]
_stacked = "cte.40.tcte_obscont"
_field_prefix = "cte40_"
_schema_name = "cte"
_schema_version = "4.0.0"
_odoo_module = "l10n_br_cte"
_spec_module = "odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00"
_spec_tab_name = "CTe"
_stacking_points = {}
_stack_skip = ("cte40_ObsCont_compl_id", "cte40_ObsFisco_compl_id")
_binding_module = "nfelib.cte.bindings.v4_0.cte_tipos_basico_v4_00"

cte40_xCampo = fields.Char()

cte40_xTexto = fields.Text()

def _export_field(self, xsd_field, class_obj, member_spec, export_value=None):
if xsd_field == "cte40_xCampo":
return self.name[:20].strip()
if xsd_field == "cte40_xTexto":
# Aparentemente isso terá que ser feito de outra forma
if (
"active_id" in self.env.context
and self.env.context.get("active_model")
== "l10n_br_fiscal.document.line"
):
active_id = self.env.context["active_id"]
doc = self.env["l10n_br_fiscal.document"].browse(active_id)
vals = {"user": self.env.user, "ctx": self._context, "doc": doc}
message = self.compute_message(vals).strip()
if self.comment_type == "fiscal":
return message[:60]
return message[:160]
return super()._export_field(xsd_field, class_obj, member_spec, export_value)
Loading

0 comments on commit b7b9408

Please sign in to comment.