Skip to content

Commit

Permalink
[ADD] l10n_br_cte
Browse files Browse the repository at this point in the history
  • Loading branch information
ygcarvalh committed Jul 10, 2023
1 parent b9e2e1e commit d7ff673
Show file tree
Hide file tree
Showing 19 changed files with 857 additions and 0 deletions.
110 changes: 110 additions & 0 deletions l10n_br_cte/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
====
CT-e
====

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--brazil-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-brazil/tree/14.0/l10n_br_cte
:alt: OCA/l10n-brazil
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-brazil-14-0/l10n-brazil-14-0-l10n_br_cte
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/124/14.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

[ This file must be max 2-3 paragraphs, and is required. ]

This module extends the functionality of ... to support ...
and to allow you to ...

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

[ This file is optional, it should explain how to configure
the module before using it; it is aimed at advanced users. ]

To configure this module, you need to:

#. Go to ...

.. figure:: https://raw.githubusercontent.com/OCA/l10n-brazil/14.0/l10n_br_cte/static/description/image.png
:alt: alternative description
:width: 600 px

Usage
=====

[ This file must be present and contains the usage instructions
for end-users. As all other rst files included in the README,
it MUST NOT contain reStructuredText sections
only body text (paragraphs, lists, tables, etc). Should you need
a more elaborate structure to explain the addon, please create a
Sphinx documentation (which may include this file as a "quick start"
section). ]

To use this module, you need to:

#. Go to ...

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-brazil/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/l10n-brazil/issues/new?body=module:%20l10n_br_cte%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
~~~~~~~

* KMEE

Contributors
~~~~~~~~~~~~

* Ygor Carvalho <ygor.carvalho@kmee.com.br>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/l10n-brazil <https://github.com/OCA/l10n-brazil/tree/14.0/l10n_br_cte>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions l10n_br_cte/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from .hooks import post_init_hook
33 changes: 33 additions & 0 deletions l10n_br_cte/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "CT-e",
"summary": """Brazilian Electronic Invoice CT-e""",
"version": "14.0.1.0.0",
"category": "Localisation",
"license": "AGPL-3",
"author": "KMEE, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-brazil",
"development_status": "Alpha",
"depends": [
"l10n_br_fiscal",
"l10n_br_cte_spec",
"spec_driven_model",
],
"data": [
# 'views/res_partner.xml',
# 'views/res_company.xml',
# 'views/cte_document.xml',
],
"post_init_hook": "post_init_hook",
"installable": True,
"auto_install": False,
"external_dependencies": {
"python": [
"nfelib>=2.0.0",
"erpbrasil.transmissao",
"erpbrasil.edoc",
]
},
}
21 changes: 21 additions & 0 deletions l10n_br_cte/hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright (C) 2019-2020 - Raphael Valyi Akretion
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
from odoo import SUPERUSER_ID, api

from odoo.addons.spec_driven_model import hooks


def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
hooks.register_hook(
env,
"l10n_br_cte",
"odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00",
)

hooks.post_init_hook(
cr,
registry,
"l10n_br_cte",
"odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00",
)
3 changes: 3 additions & 0 deletions l10n_br_cte/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import document
from . import res_company
from . import res_partner
75 changes: 75 additions & 0 deletions l10n_br_cte/models/document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# Copyright 2023 KMEE INFORMATICA LTDA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import re

from odoo import api, fields

from odoo.addons.spec_driven_model.models import spec_models


class CTe(spec_models.StackedModel):

_name = "l10n_br_fiscal.document"
_inherit = ["l10n_br_fiscal.document", "cte.40.tcte_infcte", "cte.40.tcte_fat"]
_stacked = "cte.40.tcte_infcte"
_field_prefix = "cte40_"
_schema_name = "cte"
_schema_version = "4.0.0"
_odoo_module = "l10n_br_cte"
_spec_module = "odoo.addons.l10n_br_cte_spec.models.v4_0.cte_tipos_basico_v4_00"
_binding_module = "nfelib.cte.bindings.v4_0.cte_v4_00"
_cte_search_keys = ["cte40_Id"]

INFCTE_TREE = """
> infCte
> <ide>
- <toma> res.partner
> <emit> res.company
> <dest> res.partner
> <vPrest>
> <imp>
- <ICMS>
- <ICMSUFFim>
> <infCTeNorm>
- <infCarga>
- <infModal>"""

##########################
# CT-e spec related fields
##########################

##########################
# CT-e tag: infCte
##########################

cte40_versao = fields.Char(related="document_version")

cte40_Id = fields.Char(
compute="_compute_cte40_Id",
inverse="_inverse_cte40_Id",
)

##########################
# CT-e tag: Id
# Methods
##########################

@api.depends("document_type_id", "document_key")
def _compute_cte40_Id(self):
for record in self.filtered():
if (
record.document_type_id
and record.document_type.prefix
and record.document_key
):
record.cte40_Id = "{}{}".format(
record.document_type.prefix, record.document_key
)
else:
record.cte40_Id = False

def _inverse_cte40_Id(self):
for record in self:
if record.cte40_Id:
record.document_key = re.findall(r"\d+", str(record.cte40_Id))[0]
16 changes: 16 additions & 0 deletions l10n_br_cte/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 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 ResCompany(spec_models.SpecModel):

_name = "res.company"
_inherit = ["res.company", "cte.40.tcte_emit"]
_cte_search_keys = ["cte40_CNPJ", "cte40_xNome", "cte40_xFant"]

cte40_CNPJ = fields.Char(related="partner_id.cte40_CNPJ")
cte40_CPF = fields.Char(related="partner_id.cte40_CPF")
54 changes: 54 additions & 0 deletions l10n_br_cte/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2023 KMEE INFORMATICA LTDA
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging

from odoo import api, fields

from odoo.addons.spec_driven_model.models import spec_models

_logger = logging.getLogger(__name__)

try:
from erpbrasil.base.misc import punctuation_rm
except ImportError:
_logger.error("Biblioteca erpbrasil.base não instalada")


class ResPartner(spec_models.SpecModel):

_name = "res.partner"
_inherit = [
"res.partner",
"cte.40.tendereco",
"cte.40.tlocal",
"cte.40.tendeemi",
"cte.40.tcte_dest",
"cte.40.tresptec",
"cte.40.tcte_autxml",
]
_cte_search_keys = ["cte40_CNPJ", "cte40_CPF", "cte40_xNome"]

cte40_CNPJ = fields.Char(
compute="_compute_cte_data",
inverse="_inverse_cte40_CNPJ",
store=True,
)

cte40_CPF = fields.Char(
compute="_compute_cte_data",
inverse="_inverse_cte40_CPF",
store=True,
)

@api.depends("company_type", "inscr_est", "cnpj_cpf", "country_id")
def _compute_cte_data(self):
for rec in self:
cnpj_cpf = punctuation_rm(rec.cnpj_cpf)
if cnpj_cpf:
if rec.is_company:
rec.cte40_CNPJ = cnpj_cpf
rec.cte40_CPF = None
else:
rec.cte40_CNPJ = None
rec.cte40_CPF = cnpj_cpf
10 changes: 10 additions & 0 deletions l10n_br_cte/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[ This file is optional, it should explain how to configure
the module before using it; it is aimed at advanced users. ]

To configure this module, you need to:

#. Go to ...

.. figure:: ../static/description/image.png
:alt: alternative description
:width: 600 px
1 change: 1 addition & 0 deletions l10n_br_cte/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Ygor Carvalho <ygor.carvalho@kmee.com.br>
4 changes: 4 additions & 0 deletions l10n_br_cte/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[ This file must be max 2-3 paragraphs, and is required. ]

This module extends the functionality of ... to support ...
and to allow you to ...
11 changes: 11 additions & 0 deletions l10n_br_cte/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[ This file must be present and contains the usage instructions
for end-users. As all other rst files included in the README,
it MUST NOT contain reStructuredText sections
only body text (paragraphs, lists, tables, etc). Should you need
a more elaborate structure to explain the addon, please create a
Sphinx documentation (which may include this file as a "quick start"
section). ]

To use this module, you need to:

#. Go to ...
Binary file added l10n_br_cte/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit d7ff673

Please sign in to comment.