Skip to content

Commit

Permalink
pre-commit
Browse files Browse the repository at this point in the history
  • Loading branch information
lfdivino committed Nov 17, 2021
1 parent f87b947 commit 6b9dccd
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 103 deletions.
2 changes: 0 additions & 2 deletions l10n_br_nfe/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@
# Security
"security/nfe_security.xml",
"wizards/import_document.xml",

# Menus
"views/nfe_menu.xml",

# Views
"views/res_company_view.xml",
"views/nfe_document_view.xml",
Expand Down
25 changes: 11 additions & 14 deletions l10n_br_nfe/models/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
from erpbrasil.edoc.pdf import base
from erpbrasil.transmissao import TransmissaoSOAP
from lxml import etree
from nfelib.v4_00 import retEnviNFe as leiauteNFe
from nfelib.v4_00 import leiauteNFe_sub as nfe_sub, retEnviNFe as leiauteNFe
from requests import Session

from odoo import _, api, fields
from odoo.exceptions import UserError, ValidationError

from nfelib.v4_00 import leiauteNFe_sub as nfe_sub
from odoo.addons.l10n_br_fiscal.constants.fiscal import (
AUTORIZADO,
CANCELADO,
Expand Down Expand Up @@ -262,13 +261,10 @@ def _compute_dest(self):
compute="_compute_nfe40_additional_data",
)

nfe40_transporta = fields.Many2one(
comodel_name='res.partner',
related='carrier_id'
)
nfe40_transporta = fields.Many2one(comodel_name="res.partner", related="carrier_id")

carrier_id = fields.Many2one(
comodel_name='res.partner',
comodel_name="res.partner",
)

nfe40_infRespTec = fields.Many2one(
Expand Down Expand Up @@ -845,13 +841,14 @@ def _import_xml_nfe(self, xml, dry_run):
arq.write(xml)
arq.seek(0)
nfe_binding = nfe_sub.parse(arq, silence=True)
return self.env["nfe.40.infnfe"].with_context(
tracking_disable=True,
edoc_type='in', # FIXME: IN OUT IMPORT FILE
lang='pt_BR'
).build(
nfe_binding.infNFe,
dry_run=dry_run
return (
self.env["nfe.40.infnfe"]
.with_context(
tracking_disable=True,
edoc_type="in", # FIXME: IN OUT IMPORT FILE
lang="pt_BR",
)
.build(nfe_binding.infNFe, dry_run=dry_run)
)

def import_xml(self, xml, dry_run):
Expand Down
151 changes: 79 additions & 72 deletions l10n_br_nfe/models/document_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -711,91 +711,98 @@ def _build_many2one(self, comodel, vals, new_value, key, value, path):
"l10n_br_fiscal.cst_icms_%s" % (icms.CST,)
).id
# TODO search + log if not found
if hasattr(icms, 'modBC') and icms.modBC is not None:
icms_vals['icms_base_type'] = float(icms.modBC)
if hasattr(icms, 'orig'):
icms_vals['icms_origin'] = icms.orig
if hasattr(icms, 'vBC') and icms.vBC is not None:
icms_vals['icms_base'] = float(icms.vBC)
if hasattr(icms, 'pICMS') and icms.pICMS is not None:
icms_vals['icms_percent'] = float(icms.pICMS)
if hasattr(icms, 'vICMS') and icms.vICMS is not None:
icms_vals['icms_value'] = float(icms.vICMS)
if hasattr(icms, 'pRedBC') and icms.pRedBC is not None:
icms_vals['icms_reduction'] = float(icms.pRedBC)
if hasattr(icms, 'motDesICMS') and icms.motDesICMS is not None:
icms_vals['icms_relief_id'] = self.env.ref(
'l10n_br_fiscal.icms_relief_%s' % (icms.motDesICMS,)).id
if hasattr(icms, 'vICMSDeson') and icms.vICMSDeson is not None:
icms_vals['icms_relief_value'] = float(icms.vICMSDeson)
if hasattr(icms, 'vICMSSubstituto') and icms.vICMSSubstituto is not None:
icms_vals['icms_substitute'] = float(icms.vICMSSubstituto)
if hasattr(icms, "modBC") and icms.modBC is not None:
icms_vals["icms_base_type"] = float(icms.modBC)
if hasattr(icms, "orig"):
icms_vals["icms_origin"] = icms.orig
if hasattr(icms, "vBC") and icms.vBC is not None:
icms_vals["icms_base"] = float(icms.vBC)
if hasattr(icms, "pICMS") and icms.pICMS is not None:
icms_vals["icms_percent"] = float(icms.pICMS)
if hasattr(icms, "vICMS") and icms.vICMS is not None:
icms_vals["icms_value"] = float(icms.vICMS)
if hasattr(icms, "pRedBC") and icms.pRedBC is not None:
icms_vals["icms_reduction"] = float(icms.pRedBC)
if hasattr(icms, "motDesICMS") and icms.motDesICMS is not None:
icms_vals["icms_relief_id"] = self.env.ref(
"l10n_br_fiscal.icms_relief_%s" % (icms.motDesICMS,)
).id
if hasattr(icms, "vICMSDeson") and icms.vICMSDeson is not None:
icms_vals["icms_relief_value"] = float(icms.vICMSDeson)
if (
hasattr(icms, "vICMSSubstituto")
and icms.vICMSSubstituto is not None
):
icms_vals["icms_substitute"] = float(icms.vICMSSubstituto)

# ICMS ST fields
# TODO map icmsst_tax_id
if hasattr(icms, 'modBCST') and icms.modBCST is not None:
icms_vals['icmsst_base_type'] = float(icms.modBCST)
if hasattr(icms, 'pMVAST') and icms.pMVAST is not None:
icms_vals['icmsst_mva_percent'] = float(icms.pMVAST)
if hasattr(icms, 'pRedBCST') and icms.pRedBCST is not None:
icms_vals['icmsst_reduction'] = float(icms.pRedBCST)
if hasattr(icms, 'vBCST') and icms.vBCST is not None:
icms_vals['icmsst_base'] = float(icms.vBCST)
if hasattr(icms, 'pICMSST') and icms.pICMSST is not None:
icms_vals['icmsst_percent'] = float(icms.pICMSST)
if hasattr(icms, 'vICMSST') and icms.vICMSST is not None:
icms_vals['icmsst_value'] = float(icms.vICMSST)
if hasattr(icms, 'vBCSTRet') and icms.vBCSTRet is not None:
icms_vals['icmsst_wh_base'] = float(icms.vBCSTRet)
if hasattr(icms, 'vICMSSTRet') and icms.vICMSSTRet is not None:
icms_vals['icmsst_wh_value'] = float(icms.vICMSSTRet)
if hasattr(icms, "modBCST") and icms.modBCST is not None:
icms_vals["icmsst_base_type"] = float(icms.modBCST)
if hasattr(icms, "pMVAST") and icms.pMVAST is not None:
icms_vals["icmsst_mva_percent"] = float(icms.pMVAST)
if hasattr(icms, "pRedBCST") and icms.pRedBCST is not None:
icms_vals["icmsst_reduction"] = float(icms.pRedBCST)
if hasattr(icms, "vBCST") and icms.vBCST is not None:
icms_vals["icmsst_base"] = float(icms.vBCST)
if hasattr(icms, "pICMSST") and icms.pICMSST is not None:
icms_vals["icmsst_percent"] = float(icms.pICMSST)
if hasattr(icms, "vICMSST") and icms.vICMSST is not None:
icms_vals["icmsst_value"] = float(icms.vICMSST)
if hasattr(icms, "vBCSTRet") and icms.vBCSTRet is not None:
icms_vals["icmsst_wh_base"] = float(icms.vBCSTRet)
if hasattr(icms, "vICMSSTRet") and icms.vICMSSTRet is not None:
icms_vals["icmsst_wh_value"] = float(icms.vICMSSTRet)

# ICMS FCP Fields
# TODO map icmsfcp_tax_id
if hasattr(icms, 'pFCPUFDest') and icms.pFCPUFDest is not None:
icms_vals['icmsfcp_percent'] = float(icms.pFCPUFDest)
if hasattr(icms, 'vFCPUFDest') and icms.vFCPUFDest is not None:
icms_vals['icmsfcp_value'] = float(icms.vFCPUFDest)
if hasattr(icms, 'vBCFCPST') and icms.vBCFCPST is not None:
icms_vals['icmsfcp_base'] = float(icms.vBCFCPST)
if hasattr(icms, "pFCPUFDest") and icms.pFCPUFDest is not None:
icms_vals["icmsfcp_percent"] = float(icms.pFCPUFDest)
if hasattr(icms, "vFCPUFDest") and icms.vFCPUFDest is not None:
icms_vals["icmsfcp_value"] = float(icms.vFCPUFDest)
if hasattr(icms, "vBCFCPST") and icms.vBCFCPST is not None:
icms_vals["icmsfcp_base"] = float(icms.vBCFCPST)

# ICMS DIFAL Fields
if hasattr(icms, 'vBCUFDest') and icms.vBCUFDest is not None:
icms_vals['icms_destination_base'] = float(icms.vBCUFDest)
if hasattr(icms, 'pICMSUFDest') and icms.pICMSUFDest is not None:
icms_vals['icms_origin_percent'] = float(icms.pICMSUFDest)
if hasattr(icms, 'pICMSInter') and icms.pICMSInter is not None:
icms_vals['icms_destination_percent'] = float(icms.pICMSInter)

if hasattr(icms, 'pICMSInterPart') and icms.pICMSInterPart is not None:
icms_vals['icms_sharing_percent'] = float(icms.pICMSInterPart)
if hasattr(icms, 'vICMSUFRemet') and icms.vICMSUFRemet is not None:
icms_vals['icms_origin_value'] = float(icms.vICMSUFRemet)
if hasattr(icms, 'vICMSUFDest') and icms.vICMSUFDest is not None:
icms_vals['icms_destination_value'] = float(icms.vICMSUFDest)
if hasattr(icms, "vBCUFDest") and icms.vBCUFDest is not None:
icms_vals["icms_destination_base"] = float(icms.vBCUFDest)
if hasattr(icms, "pICMSUFDest") and icms.pICMSUFDest is not None:
icms_vals["icms_origin_percent"] = float(icms.pICMSUFDest)
if hasattr(icms, "pICMSInter") and icms.pICMSInter is not None:
icms_vals["icms_destination_percent"] = float(icms.pICMSInter)

if (
hasattr(icms, "pICMSInterPart")
and icms.pICMSInterPart is not None
):
icms_vals["icms_sharing_percent"] = float(icms.pICMSInterPart)
if hasattr(icms, "vICMSUFRemet") and icms.vICMSUFRemet is not None:
icms_vals["icms_origin_value"] = float(icms.vICMSUFRemet)
if hasattr(icms, "vICMSUFDest") and icms.vICMSUFDest is not None:
icms_vals["icms_destination_value"] = float(icms.vICMSUFDest)

# ICMS Simples Nacional Fields
# TODO map icmssn_tax_id using CSOSN
if hasattr(icms, 'pCredSN') and icms.pCredSN is not None:
icms_vals['icmssn_percent'] = float(icms.pCredSN)
if hasattr(icms, 'vCredICMSSN') and icms.vCredICMSSN is not None:
icms_vals['icmssn_credit_value'] = float(icms.vCredICMSSN)
if hasattr(icms, "pCredSN") and icms.pCredSN is not None:
icms_vals["icmssn_percent"] = float(icms.pCredSN)
if hasattr(icms, "vCredICMSSN") and icms.vCredICMSSN is not None:
icms_vals["icmssn_credit_value"] = float(icms.vCredICMSSN)

# ICMS Retido Anteriormente
if hasattr(icms, 'vBCSTRet') and icms.vBCSTRet is not None:
icms_vals['icmsst_wh_base'] = float(icms.vBCSTRet)
if hasattr(icms, 'vICMSSTRet') and icms.vICMSSTRet is not None:
icms_vals['icmsst_wh_value'] = float(icms.vICMSSTRet)
if hasattr(icms, 'vBCFCPSTRet') and icms.vBCFCPSTRet is not None:
icms_vals['icmsfcp_base_wh'] = float(icms.vBCFCPSTRet)
if hasattr(icms, 'vFCPSTRet') and icms.vFCPSTRet is not None:
icms_vals['icmsfcp_value_wh'] = float(icms.vFCPSTRet)
if hasattr(icms, 'vFCPST') and icms.vFCPST is not None:
icms_vals['icmsfcpst_value'] = float(icms.vFCPST)
if hasattr(icms, 'vBCEfet') and icms.vBCEfet is not None:
icms_vals['effective_base_value'] = float(icms.vBCEfet)
if hasattr(icms, 'vICMSEfet') and icms.vICMSEfet is not None:
icms_vals['icms_effective_value'] = float(icms.vICMSEfet)
if hasattr(icms, "vBCSTRet") and icms.vBCSTRet is not None:
icms_vals["icmsst_wh_base"] = float(icms.vBCSTRet)
if hasattr(icms, "vICMSSTRet") and icms.vICMSSTRet is not None:
icms_vals["icmsst_wh_value"] = float(icms.vICMSSTRet)
if hasattr(icms, "vBCFCPSTRet") and icms.vBCFCPSTRet is not None:
icms_vals["icmsfcp_base_wh"] = float(icms.vBCFCPSTRet)
if hasattr(icms, "vFCPSTRet") and icms.vFCPSTRet is not None:
icms_vals["icmsfcp_value_wh"] = float(icms.vFCPSTRet)
if hasattr(icms, "vFCPST") and icms.vFCPST is not None:
icms_vals["icmsfcpst_value"] = float(icms.vFCPST)
if hasattr(icms, "vBCEfet") and icms.vBCEfet is not None:
icms_vals["effective_base_value"] = float(icms.vBCEfet)
if hasattr(icms, "vICMSEfet") and icms.vICMSEfet is not None:
icms_vals["icms_effective_value"] = float(icms.vICMSEfet)
new_value.update(icms_vals)
elif key == "nfe40_IPI":
pass
Expand Down
5 changes: 4 additions & 1 deletion l10n_br_nfe/models/product_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ def create(self, values):
values["list_price"] = parent_dict.get("nfe40_vUnCom")

# Barcode
if parent_dict.get("nfe40_cEANTrib") and parent_dict["nfe40_cEANTrib"] != "SEM GTIN":
if (
parent_dict.get("nfe40_cEANTrib")
and parent_dict["nfe40_cEANTrib"] != "SEM GTIN"
):
values["barcode"] = parent_dict["nfe40_cEANTrib"]

# NCM
Expand Down
8 changes: 7 additions & 1 deletion l10n_br_nfe/views/nfe_menu.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<menuitem id="nfe_import_document" action="l10n_br_nfe_import_xml_action" name="Import XML NF-e" parent="l10n_br_fiscal.document_sub_menu" sequence="46"/>
<menuitem
id="nfe_import_document"
action="l10n_br_nfe_import_xml_action"
name="Import XML NF-e"
parent="l10n_br_fiscal.document_sub_menu"
sequence="46"
/>

</odoo>
15 changes: 5 additions & 10 deletions l10n_br_nfe/wizards/import_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

from openerp import _, api, fields, models


IMPORTING_TYPES = [
("xml_file", "NFe XML File"),
("nfe_key", "NFe key (Not Implemented)"),
("manually", "Manually (Not Implemented)")
("manually", "Manually (Not Implemented)"),
]


Expand All @@ -26,9 +25,7 @@ class NfeImport(models.TransientModel):
)

importing_type = fields.Selection(
string="Importing Type",
selection=IMPORTING_TYPES,
required=True
string="Importing Type", selection=IMPORTING_TYPES, required=True
)

nfe_xml = fields.Binary(
Expand All @@ -45,10 +42,9 @@ def import_nfe_xml(self):
"name": "NFe-Importada-{}.xml".format(edoc.document_key),
"datas": base64.b64decode(self.nfe_xml),
"datas_fname": "NFe-Importada-{}.xml".format(edoc.document_key),
"description":
u'XML NFe - Importada por XML',
"description": u"XML NFe - Importada por XML",
"res_model": "l10n_br_fiscal.document",
"res_id": edoc.id
"res_id": edoc.id,
}

self.env["ir.attachment"].create(vals)
Expand All @@ -62,6 +58,5 @@ def import_nfe_xml(self):
"res_model": "l10n_br_fiscal.document",
"type": "ir.actions.act_window",
"target": "new",
"flags": {"form": {"action_buttons": True,
"options": {"mode": "edit"}}},
"flags": {"form": {"action_buttons": True, "options": {"mode": "edit"}}},
}
8 changes: 5 additions & 3 deletions l10n_br_nfe/wizards/import_document.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2021 KMEE
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="l10n_br_nfe_import_xml_form" model="ir.ui.view">
Expand All @@ -12,7 +11,10 @@
<group>
<field name="company_id" />
<field name="importing_type" />
<field name="nfe_xml" attrs="{'invisible': [('importing_type', '!=', 'xml_file')], 'required': [('importing_type', '=', 'xml_file')]}" />
<field
name="nfe_xml"
attrs="{'invisible': [('importing_type', '!=', 'xml_file')], 'required': [('importing_type', '=', 'xml_file')]}"
/>
</group>
<footer>
<button
Expand Down

0 comments on commit 6b9dccd

Please sign in to comment.