Skip to content

Commit

Permalink
[IMP] Add modal
Browse files Browse the repository at this point in the history
  • Loading branch information
ODBreno committed Aug 1, 2023
1 parent 8e6fcab commit 1804791
Show file tree
Hide file tree
Showing 12 changed files with 470 additions and 56 deletions.
6 changes: 6 additions & 0 deletions l10n_br_cte/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
from . import document_related
from . import document_line
from . import res_config_settings
from . import ferroviario
from . import rodoviario
from . import aereo
from . import dutoviario
from . import aquaviario
from . import rodo_occ
61 changes: 61 additions & 0 deletions l10n_br_cte/models/aereo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2023 KMEE INFORMATICA LTDA
# 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 Aereo(spec_models.SpecModel):
_name = "l10n_br_cte.aereo"
_inherit = "cte.40.aereo"

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

cte40_dPrevAereo = fields.Date(related="dPrevAereo", store=True)

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")

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,
},
}


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

cte40_CL = fields.Selection(related="CL", store=True)

CL = fields.Selection(
string="Classe",
selection=[
("M", "Tarifa Mínima"),
("G", "Tarifa Geral"),
("E", "Tarifa Específica"),
],
store=True,
default="G",
)

cte40_vTar = fields.Monetary(related="vTar")

vTar = fields.Monetary(currency_field="brl_currency_id")
86 changes: 86 additions & 0 deletions l10n_br_cte/models/aquaviario.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Copyright 2023 KMEE INFORMATICA LTDA
# 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 Aquaviario(spec_models.SpecModel):
_name = "l10n_br_cte.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(related="vAFRMM", store=True)

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(related="xNavio", store=True)

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

cte40_nViag = fields.Char(related="nViag", store=True)

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

cte40_direc = fields.Selection(related="direc", store=True)

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(related="irin", store=True)

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

cte40_tpNav = fields.Selection(related="tpNav", store=True)

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

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,
}
57 changes: 51 additions & 6 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,15 +349,13 @@ def _compute_dest_data(self):
# CT-e tag: imp
##########################

cte40_imp = fields.One2many(
comodel_name="l10n_br_fiscal.document.line", related="fiscal_line_ids"
)
cte40_imp = fields.One2many(related="fiscal_line_ids")

#####################################
# CT-e tag: infCTeNorm and infCteComp
#####################################

cte40_choice244 = fields.Selection(
cte40_choice_infcteNorm_infcteComp = fields.Selection(
selection=[
("cte40_infCTeComp", "infCTeComp"),
("cte40_infCTeNorm", "infCTeNorm"),
Expand Down Expand Up @@ -396,9 +394,9 @@ def _compute_cte_doc(self):
"""Set schema data which are not just related fields"""
for rec in self:
if rec.document_type_id:
if rec.cte40_choice244 == "cte40_infNorm":
if rec.cte40_choice_infcteNorm_infcteComp == "cte40_infCTeNorm":
rec.cte40_infCTeNorm = rec
elif rec.cte40_choice244 == "cte40_infComp":
elif rec.cte40_choice_infcteNorm_infcteComp == "infCTeComp":
rec.cte40_infCTeComp = rec

##########################
Expand Down Expand Up @@ -464,3 +462,50 @@ def _default_cte40_autxml(self):
tpImp = fields.Selection(
selection=[("1", "Retrato"), ("2", "Paisagem")], default="1"
)

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

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

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

##########################
# CT-e tag: modal
# 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"
)
21 changes: 17 additions & 4 deletions l10n_br_cte/models/document_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class CTeLine(spec_models.StackedModel):
# Grupo N06. Grupo Tributação do ICMS= 01 - ISSN
#################################################

cte40_choice11 = fields.Selection(
cte40_choice_ICMS = fields.Selection(
selection=[
("cte40_ICMS00", "ICMS00"),
("cte40_ICMS20", "ICMS20"),
Expand All @@ -51,7 +51,7 @@ class CTeLine(spec_models.StackedModel):
("cte40_ICMSSN", "ICMSSN"),
],
string="Tipo de ICMS",
compute="_compute_choice11",
compute="_compute_choice_icms",
store=True,
)

Expand Down Expand Up @@ -89,7 +89,7 @@ class CTeLine(spec_models.StackedModel):
##########################

@api.depends("icms_cst_id")
def _compute_choice11(self):
def _compute_choice_icms(self):
for record in self:
icms_choice = ""
if record.icms_cst_id.code in ICMS_CST:
Expand All @@ -104,7 +104,7 @@ def _compute_choice11(self):
icms_choice = "{}{}".format("cte40_ICMS", record.icms_cst_id.code)
elif record.icms_cst_id.code in ICMS_SN_CST:
icms_choice = "cte40_ICMSSN"
record.cte40_choice11 = icms_choice
record.cte40_choice_ICMS = icms_choice

indSN = fields.Selection(
selection=[
Expand Down Expand Up @@ -138,3 +138,16 @@ def _compute_cte40_ICMSUFFim(self):
cte40_vFCPUFfim = fields.Monetary(related="icmsfcp_value", store=True)
cte40_vICMSUFFim = fields.Monetary(related="icms_destination_value", store=True)
cte40_vICMSUFIni = fields.Monetary(related="icms_origin_value", store=True)

##########################
# CT-e tag: natCarga
##########################

cte40_xDime = fields.Char(compute="_compute_dime", store=True)

def _compute_dime(self):
for record in self:
for package in record.product_id.packaging_ids:
record.cte40_xDime = (
package.width + "X" + package.packaging_length + "X" + package.width
)
18 changes: 9 additions & 9 deletions l10n_br_cte/models/document_related.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class CTeRelated(spec_models.StackedModel):
_spec_module = "odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00"
_spec_tab_name = "CTe"

# infQ
# infQ TODO computes/relateds
cte40_cUnid = fields.Selection(related="cUnid")

cte40_tpMed = fields.Char()
Expand Down Expand Up @@ -69,7 +69,7 @@ class CTeRelated(spec_models.StackedModel):
inverse="_inverse_cte40_tpDoc",
)

cte40_infDoc = fields.Selection(related="cte40_choice254")
cte40_infDoc = fields.Selection(related="cte40_choice_infNF_infNFE_infOutros")

# infCteNorm
cte40_chCTe = fields.Char(compute="_compute_chCte", string="chCte")
Expand All @@ -86,14 +86,14 @@ def _compute_chCTe(self):
records += rec.document_key
self.cte40_chCTe = records

cte40_choice254 = fields.Selection(
cte40_choice_infNF_infNFE_infOutros = fields.Selection(
selection=[
("cte40_infNF", "infNF"),
("cte40_infNF", "infNF"), # TODO
("cte40_infNFe", "infNFe"),
("cte40_infOutros", "Outros"),
],
compute="_compute_cte_data",
inverse="_inverse_cte40_choice254",
inverse="_inverse_cte40_choice_infNF_infNFE_infOutros",
)

def _compute_vCarga(self):
Expand All @@ -107,10 +107,10 @@ def _compute_cte_data(self):
for rec in self:
if rec.document_type_id:
if rec.document_type_id.code in ("55",):
rec.cte40_choice254 = "cte40_infNFe"
rec.cte40_choice_infNF_infNFE_infOutros = "cte40_infNFe"
rec.cte40_chave = rec.document_key
elif rec.document_type_id.code in ("00", "10", "59", "65", "99"):
rec.cte40_choice254 = "cte40_infOutros"
rec.cte40_choice_infNF_infNFE_infOutros = "cte40_infOutros"
rec.cte40_tpDoc = rec.document_type_id.code

def _inverse_cte40_chave(self):
Expand All @@ -123,7 +123,7 @@ def _inverse_cte40_tpDoc(self):
if rec.cte40_tpDoc:
rec.document_type_id = rec.cte40_tpDoc

def _inverse_cte40_choice254(self):
def _inverse_cte40_choice_infNF_infNFE_infOutros(self):
for rec in self:
if rec.cte40_choice254 == "cte40_infNFe":
if rec.cte40_choice_infNF_infNFE_infOutros == "cte40_infNFe":
rec.document_type_id = self.env.ref("l10n_br_fiscal.document_55")
34 changes: 34 additions & 0 deletions l10n_br_cte/models/dutoviario.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2023 KMEE INFORMATICA LTDA
# 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 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"
)

cte40_dIni = fields.Date(related="dIni")

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

cte40_dFim = fields.Date(related="dFim")

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

cte40_vTar = fields.Float(related="vTar")

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 1804791

Please sign in to comment.