Skip to content

Commit

Permalink
[FIX] Refactor modals and modal fields in document
Browse files Browse the repository at this point in the history
  • Loading branch information
ODBreno authored and lfdivino committed Sep 28, 2023
1 parent 9d154c3 commit caf834e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 60 deletions.
33 changes: 30 additions & 3 deletions l10n_br_cte/models/aereo.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class Aereo(spec_models.SpecModel):
store="True",
)

cte40_natCarga = fields.One2many(
related="document_id.fiscal_line_ids",
)
cte40_natCarga = fields.Many2one(comodel_name="l10n_br_cte.modal.aereo.natcarga")

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

Expand Down Expand Up @@ -54,3 +52,32 @@ def export_fields(self):
@api.model
def export_fields_multi(self):
return [record.export_fields() for record in self]


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

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

cte40_xDime = fields.Char(
string="Dimensão",
help=(
"Dimensão\nFormato:1234X1234X1234 (cm). Esse campo deve sempre que"
" possível ser preenchido. Entretanto, quando for impossível o "
"preenchimento das dimensões, fica obrigatório o preenchimento da "
"cubagem em metro cúbico do leiaute do CT-e da estrutura genérica "
"(infQ)."
),
)

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

return Aquav.Tarifa(xDime=self.cte40_xDime)

@api.model
def export_fields_multi(self):
return [record.export_fields() for record in self]
4 changes: 0 additions & 4 deletions l10n_br_cte/models/aquaviario.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ class Aquaviario(spec_models.SpecModel):
_name = "l10n_br_cte.modal.aquaviario"
_inherit = "cte.40.aquav"

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

cte40_vPrest = fields.Monetary(compute="_compute_vPrest", store=True)

cte40_vAFRMM = fields.Monetary(
Expand Down
56 changes: 12 additions & 44 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def _default_cte40_autxml(self):
)

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

cte40_tarifa = fields.Many2one(comodel_name="l10n_br_cte.tarifa")
Expand Down Expand Up @@ -534,8 +534,10 @@ def _default_cte40_autxml(self):
)

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

# Campos do Modal Dutoviario
cte40_dIni = fields.Date(string="Data de Início da prestação do serviço")
Expand Down Expand Up @@ -565,13 +567,13 @@ def _compute_vPrest(self):

# TRAFMUT
cte40_trafMut = fields.Many2one(
comodel_name="l10n_br_fiscal.document",
comodel_name="l10n_br_fiscal.document.line",
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",
related="amount_freight_value",
currency_field="brl_currency_id",
)

Expand All @@ -596,22 +598,22 @@ def _compute_vPrest(self):
)

cte40_ferroEnv = fields.One2many(
comodel_name="l10n_br_cte.ferroenv",
inverse_name="cte40_cInt",
comodel_name="l10n_br_cte.modal.ferroviario.trafmut.ferroenv",
inverse_name="document_id",
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",
related="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",
comodel_name="l10n_br_cte.modal.rodoviario.occ",
inverse_name="document_id",
string="Ordens de Coleta associados",
)

Expand All @@ -620,40 +622,6 @@ def _compute_vPrest(self):
# Compute Methods
##########################

def _compute_modal(self):
if self.cte40_modal == "1":
self.cte40_infModal = self.cte40_rodoviario
elif self.cte40_modal == "2":
self.cte40_infModal = self.cte40_aereo
elif self.cte40_modal == "3":
self.cte40_infModal = self.cte40_aquav
elif self.cte40_modal == "4":
self.cte40_infModal = self.cte40_ferroviario
elif self.cte40_modal == "5":
self.cte40_infModal = self.cte40_dutoviario
elif self.cte40_modal == "6":
pass # TODO

cte40_aquav = fields.Many2one(
comodel_name="l10n_br_cte.aquaviario", inverse_name="document_id"
)

cte40_dutoviario = fields.Many2one(
comodel_name="l10n_br_cte.dutoviario", inverse_name="document_id"
)

cte40_rodoviario = fields.Many2one(
comodel_name="l10n_br_cte.rodoviario", inverse_name="document_id"
)

cte40_ferroviario = fields.Many2one(
comodel_name="l10n_br_cte.ferroviario", inverse_name="document_id"
)

cte40_aereo = fields.Many2one(
comodel_name="l10n_br_cte.aereo", inverse_name="document_id"
)

################################
# Business Model Methods
################################
Expand Down
5 changes: 2 additions & 3 deletions l10n_br_cte/models/ferroviario.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class Ferroviario(spec_models.SpecModel):

class TrafMut(spec_models.SpecModel):
_name = "l10n_br_cte.modal.ferroviario.trafmut"
_inherit = "cte.40.trafmut"

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

Expand All @@ -67,7 +67,6 @@ class TrafMut(spec_models.SpecModel):

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

Expand Down Expand Up @@ -113,7 +112,7 @@ def export_fields_multi(self):

class TenderFerrov(spec_models.SpecModel):
_name = "l10n_br_cte.modal.tenderfer"
_inherit = "spec.mixin.cte"
_inherit = "cte.40.tenderfer"

cte40_xLgr = fields.Char(string="Logradouro")

Expand Down
6 changes: 0 additions & 6 deletions l10n_br_cte/models/rodoviario.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,14 @@ class Rodoviario(spec_models.SpecModel):
_name = "l10n_br_cte.modal.rodoviario"
_inherit = "cte.40.rodo"

document_id = fields.One2many(
comodel_name="l10n_br_fiscal.document", inverse_name="cte40_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.modal.rodoviario.occ",
inverse_name="document_id",
string="Ordens de Coleta associados",
)

Expand Down

0 comments on commit caf834e

Please sign in to comment.