-
-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFC] l10n_br_cte: multi-schema refactor
- Loading branch information
1 parent
9a14b8f
commit 8a756f3
Showing
16 changed files
with
152 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,42 @@ | ||
# Copyright (C) 2019-2020 - Raphael Valyi Akretion | ||
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html | ||
import logging | ||
|
||
import nfelib | ||
import pkg_resources | ||
from nfelib.cte.bindings.v4_0.cte_tipos_basico_v4_00 import Tcte | ||
|
||
from odoo import SUPERUSER_ID, api | ||
from odoo.exceptions import ValidationError | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def post_init_hook(cr, registry): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
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", | ||
# ) | ||
cr.execute("select demo from ir_module_module where name='l10n_br_cte';") | ||
is_demo = cr.fetchone()[0] | ||
if is_demo: | ||
res_items = ( | ||
"cte", | ||
"samples", | ||
"v3_0", | ||
"43120178408960000182570010000000041000000047-cte.xml", | ||
) | ||
resource_path = "/".join(res_items) | ||
doc_stream = pkg_resources.resource_stream(nfelib.__name__, resource_path) | ||
binding = Tcte.from_xml(doc_stream.read().decode()) | ||
document_number = binding.infCte.ide.nCTE | ||
existing_docs = env["l10n_br_fiscal.document"].search( | ||
[("document_number", "=", document_number)] | ||
) | ||
try: | ||
existing_docs.unlink() | ||
doc = ( | ||
env["cte.40.tcte_infcte"] | ||
.with_context(tracking_disable=True, edoc_type="in") | ||
.build_from_binding("cte", "40", binding.infMDFe) | ||
) | ||
_logger.info(doc.cte40_emit.cte40_CNPJ) | ||
except ValidationError: | ||
_logger.info(f"CTE-e already {document_number} imported by hooks") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.