Skip to content

Commit

Permalink
[WIP] Refactor modals
Browse files Browse the repository at this point in the history
  • Loading branch information
ODBreno authored and lfdivino committed Sep 26, 2023
1 parent 7aec56a commit 25f5915
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 132 deletions.
1 change: 0 additions & 1 deletion l10n_br_cte/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,3 @@
from . import aereo
from . import dutoviario
from . import aquaviario
from . import rodo_occ
37 changes: 19 additions & 18 deletions l10n_br_cte/models/aereo.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
# Copyright 2023 KMEE INFORMATICA LTDA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields
from nfelib.cte.bindings.v4_0.cte_modal_aquaviario_v4_00 import Aquav

from odoo import api, fields

from odoo.addons.spec_driven_model.models import spec_models


class Aereo(spec_models.SpecModel):
_name = "l10n_br_cte.aereo"
_name = "l10n_br_cte.modal.aereo"
_inherit = "cte.40.aereo"

document_id = fields.One2many(
comodel_name="l10n_br_fiscal.document", inverse_name="cte40_aereo"
)

cte40_dPrevAereo = fields.Date(
string="Data prevista da entrega",
help="Data prevista da entrega\nFormato AAAA-MM-DD",
Expand All @@ -24,23 +22,15 @@ class Aereo(spec_models.SpecModel):
related="document_id.fiscal_line_ids",
)

cte40_tarifa = fields.Many2one(comodel_name="l10n_br_cte.tarifa")

def export_data(self):
return {
"cte40_dPrevAereo": self.cte40_dPrevAereo,
"cte40_natCarga": {"cte40_xDime": self.cte40_natCarga.xDime},
"cte40_tarifa": {
"cte40_CL": self.cte40_tarifa.cte40_CL,
"cte40_vTar": self.cte40_tarifa.cte40_vTar,
},
}
cte40_tarifa = fields.Many2one(comodel_name="l10n_br_cte.modal.aereo.tarifa")


class Tarifa(spec_models.SpecModel):
_name = "l10n_br_cte.tarifa"
_name = "l10n_br_cte.modal.aereo.tarifa"
_inherit = "cte.40.tarifa"

document_id = fields.Many2one(comodel_name="l10n_br_fiscal.document")

cte40_CL = fields.Selection(
string="Classe",
selection=[
Expand All @@ -53,3 +43,14 @@ class Tarifa(spec_models.SpecModel):
)

cte40_vTar = fields.Monetary(currency_field="brl_currency_id")

@api.model
def export_fields(self):
if len(self) > 1:
return self.export_fields_multi()

return Aquav.Tarifa(CL=self.cte40_CL, vTar=self.cte40_vTar)

@api.model
def export_fields_multi(self):
return [record.export_fields() for record in self]
13 changes: 1 addition & 12 deletions l10n_br_cte/models/aquaviario.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class Aquaviario(spec_models.SpecModel):
_name = "l10n_br_cte.aquaviario"
_name = "l10n_br_cte.modal.aquaviario"
_inherit = "cte.40.aquav"

document_id = fields.One2many(
Expand Down Expand Up @@ -61,14 +61,3 @@ class Aquaviario(spec_models.SpecModel):
def _compute_vPrest(self):
for record in self.document_id.fiscal_line_ids:
record.cte40_vPrest += record.cte40_vTPrest

def export_data(self):
return {
"cte40_vPrest": self.cte40_vPrest,
"cte40_vAFRMM": self.cte40_vAFRMM,
"cte40_xNavio": self.cte40_xNavio,
"cte40_nViag": self.cte40_nViag,
"cte40_direc": self.cte40_direc,
"cte40_irin": self.cte40_irin,
"cte40_tpNav": self.cte40_tpNav,
}
142 changes: 141 additions & 1 deletion l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,13 +468,153 @@ def _default_cte40_autxml(self):
cte40_autXML = fields.One2many(default=_default_cte40_autxml)

##########################
# CT-e tag: modal
# CT-e tag: infmodal
##########################

cte40_modal = fields.Selection(related="transport_modal")

cte40_infModal = fields.Many2one(compute="_compute_modal")

# Campos do Modal Aereo
cte40_dPrevAereo = fields.Date(
string="Data prevista da entrega",
help="Data prevista da entrega\nFormato AAAA-MM-DD",
store="True",
)

cte40_natCarga = fields.One2many(
related="document_id.fiscal_line_ids",
)

cte40_tarifa = fields.Many2one(comodel_name="l10n_br_cte.tarifa")

# Campos do Modal Aquaviario
cte40_vPrest = fields.Monetary(compute="_compute_vPrest", store=True)

cte40_vAFRMM = fields.Monetary(
string="AFRMM",
currency_field="brl_currency_id",
help=("AFRMM (Adicional de Frete para Renovação da Marinha Mercante)"),
store=True,
)

cte40_xNavio = fields.Char(string="Identificação do Navio", store=True)

cte40_nViag = fields.Char(string="Número da Viagem", store=True)

cte40_direc = fields.Selection(
selection=[
("N", "Norte, L-Leste, S-Sul, O-Oeste"),
("S", "Sul, O-Oeste"),
("L", "Leste, S-Sul, O-Oeste"),
("O", "Oeste"),
],
string="Direção",
store=True,
help="Direção\nPreencher com: N-Norte, L-Leste, S-Sul, O-Oeste",
)

cte40_irin = fields.Char(
string="Irin do navio sempre deverá",
help="Irin do navio sempre deverá ser informado",
store=True,
)

cte40_tpNav = fields.Selection(
selection=[
("0", "Interior"),
("1", "Cabotagem"),
],
string="Tipo de Navegação",
help=(
"Tipo de Navegação\nPreencher com: \n\t\t\t\t\t\t0 - "
"Interior;\n\t\t\t\t\t\t1 - Cabotagem"
),
store=True,
)

def _compute_vPrest(self):
for record in self.document_id.fiscal_line_ids:
record.cte40_vPrest += record.cte40_vTPrest

# Campos do Modal Dutoviario
cte40_dIni = fields.Date(string="Data de Início da prestação do serviço")

cte40_dFim = fields.Date(string="Data de Fim da prestação do serviço")

cte40_vTar = fields.Float(string="Valor da tarifa")

# Campos do Modal Ferroviario
cte40_tpTraf = fields.Selection(
selection=[
("0", "Próprio"),
("1", "Mútuo"),
("2", "Rodoferroviário"),
("3", "Rodoviário."),
],
default="0",
)

cte40_fluxo = fields.Char(
string="Fluxo Ferroviário",
help=(
"Fluxo Ferroviário\nTrata-se de um número identificador do "
"contrato firmado com o cliente"
),
)

# TRAFMUT
cte40_trafMut = fields.Many2one(
comodel_name="l10n_br_fiscal.document",
string="Detalhamento de informações",
help="Detalhamento de informações para o tráfego mútuo",
)

cte40_vFrete = fields.Monetary(
related="cte40_trafMut.amount_freight_value",
currency_field="brl_currency_id",
)

cte40_respFat = fields.Selection(
selection=[
("1", "Ferrovia de origem"),
("2", "Ferrovia de destino"),
]
)

cte40_ferrEmi = fields.Selection(
selection=[
("1", "Ferrovia de origem"),
("2", "Ferrovia de destino"),
],
string="Ferrovia Emitente do CTe",
help=(
"Ferrovia Emitente do CTe\nPreencher com: "
"\n\t\t\t\t\t\t\t\t\t1-Ferrovia de origem; "
"\n\t\t\t\t\t\t\t\t\t2-Ferrovia de destino"
),
)

cte40_ferroEnv = fields.One2many(
comodel_name="l10n_br_cte.ferroenv",
inverse_name="cte40_cInt",
string="Informações das Ferrovias Envolvidas",
)

# Campos do Modal rodoviario
cte40_RNTRC = fields.Char(
string="RNTRC",
store=True,
related="document_id.cte40_emit.partner_id.rntrc_code",
help="Registro Nacional de Transportadores Rodoviários de Carga",
)

cte40_occ = fields.One2many(
comodel_name="l10n_br_cte.occ",
inverse_name="cte40_occ_rodo_id",
string="Ordens de Coleta associados",
)

##########################
# CT-e tag: modal
# Compute Methods
Expand Down
15 changes: 2 additions & 13 deletions l10n_br_cte/models/dutoviario.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,11 @@


class Dutoviario(spec_models.SpecModel):
_name = "l10n_br_cte.dutoviario"
_inherit = ["cte.40.duto"]

document_id = fields.One2many(
comodel_name="l10n_br_fiscal.document", inverse_name="cte40_dutoviario"
)
_name = "l10n_br_cte.modal.dutoviario"
_inherit = "cte.40.duto"

cte40_dIni = fields.Date(string="Data de Início da prestação do serviço")

cte40_dFim = fields.Date(string="Data de Fim da prestação do serviço")

cte40_vTar = fields.Float(string="Valor da tarifa")

def export_data(self):
return {
"cte40_dIni": self.cte40_dIni,
"cte40_dFim": self.cte40_dFim,
"cte40_vTar": self.cte40_vTar,
}
Loading

0 comments on commit 25f5915

Please sign in to comment.