Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD][WIP] NFe Import Purchase Conciliation #2553

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
dba062e
[ADD] Added match_or_create_m2o method for product.product
hirokibastos Jun 20, 2022
f5e70c5
[ADD] Added import document wizard
hirokibastos Jun 15, 2022
e0efa01
[ADD] Added menu and action for imported documents
hirokibastos Jun 15, 2022
a2fbdac
[FIX] Small fixes
hirokibastos Jun 15, 2022
1465787
[RMV] Hid buttons from imported document form view
hirokibastos Jun 15, 2022
daf0ea6
[ADD] Added tests and run pre-commit
hirokibastos Jun 15, 2022
aca17cb
[MIG] v14 updates
rvalyi Jul 19, 2022
70dc686
[FIX] ensure all records are assigned
rvalyi Jul 19, 2022
3a5930d
[FIX] avoids default_get errors in test context
rvalyi Jul 19, 2022
959ed54
added ACL for importation wizard
rvalyi Jul 19, 2022
cc09d90
[MIG] v14 updates
rvalyi Jul 19, 2022
1887b5f
[REM] Unnecessary code
lfdivino May 25, 2023
434e60e
[FIX] Document cnpj_cpf_emitente field at wizard
lfdivino May 18, 2023
fc34482
[FIX] Build from binding function name at document
lfdivino May 18, 2023
3209c0a
[ADD] Supplier infos at imported products
lfdivino May 29, 2023
c00f7f2
[ADD] product_code field to import wizard
lfdivino May 29, 2023
d940414
[ADD] Choose between internal and nxm ncm when importing a nfe
lfdivino May 29, 2023
6e95660
[FIX] Default code at product match_or_create_m2o
lfdivino May 30, 2023
a0fb57c
[ADD] Add new fields to nfe import wizard
lfdivino May 29, 2023
013c2e1
[ADD] Add new field to change product line cfop when importing document
lfdivino May 29, 2023
60c00bd
[ADD] Mapped internal products and ncm test cases
lfdivino May 30, 2023
80345db
[FIX] NFE Import Wizard test cases
lfdivino May 25, 2023
bce30d3
[FIX] improve code readability
felipezago Jun 23, 2023
982408a
[ADD] set fields data by xml method
felipezago Jun 23, 2023
18779fd
[DEL] ncm_choice
felipezago Jun 23, 2023
a592f55
[IMP] import xml products tree
felipezago Jun 23, 2023
87535b9
[FIX] PT Br language at demo install
lfdivino May 25, 2023
18b6a3f
[FIX] NFE Import Wizard test cases
lfdivino May 25, 2023
9ddf075
[FIX] wrong context call
felipezago Jun 23, 2023
b683304
[ADD] abstract base import wizard
felipezago Jun 23, 2023
db0b2c1
[FIX] improve code readability
felipezago Jun 26, 2023
33e2a35
[ADD] l10n_br_nfe_purchase module
felipezago Jun 23, 2023
d82a4e3
[FIX] nfe import rebase
felipezago Jun 26, 2023
17ed714
[FIX] make new module inherit l10n_br_fiscal instead of l10n_br_nfe
felipezago Jun 26, 2023
d9658e6
[FIX] reorder methods
felipezago Jun 26, 2023
cac235d
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 26, 2023
5754fc4
[FIX] field names on purchase order creation
felipezago Jun 26, 2023
62d152c
[ADD] res partner match or create
felipezago Jun 26, 2023
9b5db66
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 26, 2023
75a558b
[FIX] link purchase to edoc when choosing manually on import
felipezago Jun 26, 2023
2820cc3
[ADD] dry_run validation on res.partner m2o match
felipezago Jun 27, 2023
23807b4
Merge remote-tracking branch 'oca/14.0' into feature/nfe_import_purch…
felipezago Jun 27, 2023
b530e97
[FIX] realocate function
felipezago Jun 27, 2023
5103289
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 27, 2023
731106b
[FIX] match res partner m2o
felipezago Jun 27, 2023
6aed260
[FIX] onchange partner cnpj
felipezago Jun 27, 2023
1fe819e
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 27, 2023
7050d66
[FIX] l10n_br_nfe tests
felipezago Jun 27, 2023
2478b94
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 27, 2023
56df449
[FIX] remove pt_BR lang context from demo records
felipezago Jun 27, 2023
f152bd8
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 27, 2023
e8ac6cd
[FIX] improve match product
felipezago Jun 28, 2023
bdc88a9
[FIX] improve tests
felipezago Jun 28, 2023
e0f7d58
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 28, 2023
f36b950
[DEL] remove unnecessary code
felipezago Jun 28, 2023
e506f25
[FIX] bug on import
felipezago Jun 28, 2023
2d54afa
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 28, 2023
be22536
[ADD] import nfe tests
felipezago Jun 28, 2023
eced2a9
[FIX] remove code
felipezago Jun 28, 2023
8b842cc
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 28, 2023
2236692
[ADD] purchase nfe import tests
felipezago Jun 28, 2023
c93ae6d
[ADD] l10n_br_fiscal_purchase tests
felipezago Jun 28, 2023
f5bee89
[FIX] change deprecated methods
felipezago Jun 28, 2023
7301bfb
[FIX] prepare import dict
felipezago Jun 28, 2023
662e8d3
Merge branch 'feature/nfe_import' into feature/nfe_import_purchase_co…
felipezago Jun 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions l10n_br_fiscal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"wizards/document_correction_wizard.xml",
"wizards/document_status_wizard.xml",
"wizards/invalidate_number_wizard.xml",
"wizards/document_import_wizard_mixin.xml",
# Actions
"views/l10n_br_fiscal_action.xml",
# Menus
Expand Down
1 change: 1 addition & 0 deletions l10n_br_fiscal/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,4 @@
"l10n_br_fiscal_document_correction_wizard_user",l10n_br_fiscal_document_correction_wizard,model_l10n_br_fiscal_document_correction_wizard,base.group_user,1,1,1,1
"l10n_br_fiscal_document_status_wizard_user",l10n_br_fiscal_document_status_wizard,model_l10n_br_fiscal_document_status_wizard,base.group_user,1,1,1,1
"l10n_br_fiscal_invalidate_number_wizard_user",l10n_br_fiscal_invalidate_number_wizard,model_l10n_br_fiscal_invalidate_number_wizard,base.group_user,1,1,1,1
"l10n_br_fiscal_document_import_wizard_mixin_user",l10n_br_fiscal_document_import_wizard_mixin_user,model_l10n_br_fiscal_document_import_wizard_mixin,base.group_user,1,1,1,1
5 changes: 5 additions & 0 deletions l10n_br_fiscal/tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import os

from erpbrasil.assinatura import misc
from erpbrasil.base.fiscal.edoc import cnpj_cpf
from erpbrasil.base.misc import punctuation_rm

from odoo.tools import config
Expand Down Expand Up @@ -92,3 +93,7 @@ def build_edoc_path(
except Exception as e:
_logger.error("Falha de permissão ao acessar diretorio do e-doc {}".format(e))
return caminho


def format_cnpj_cpf(val):
return cnpj_cpf.formata(val)
1 change: 1 addition & 0 deletions l10n_br_fiscal/wizards/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import document_correction_wizard
from . import document_status_wizard
from . import invalidate_number_wizard
from . import document_import_wizard_mixin
5 changes: 2 additions & 3 deletions l10n_br_fiscal/wizards/base_wizard_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ def _document_fields(self):
@api.model
def default_get(self, fields_list):
default_values = super().default_get(fields_list)
active_model = self.env.context["active_model"]
active_model = self._context.get("active_model")

if self._prepare_key_fields().get(active_model):

active_id = self.env.context["active_id"]
active_id = self._context["active_id"]
active_vals = (
self.env[active_model]
.browse(active_id)
Expand Down
43 changes: 43 additions & 0 deletions l10n_br_fiscal/wizards/document_import_wizard_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Copyright (C) 2023 Felipe Zago Rodrigues - Kmee
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo import _, fields, models

from odoo.addons.l10n_br_fiscal.constants.fiscal import FISCAL_IN_OUT_ALL


class DocumentImportWizardMixin(models.TransientModel):

_name = "l10n_br_fiscal.document.import.wizard.mixin"
_inherit = "l10n_br_fiscal.base.wizard.mixin"

company_id = fields.Many2one(
comodel_name="res.company",
string="Company",
default=lambda self: self.env.user.company_id,
)

importing_type = fields.Selection(
selection=[("xml_file", "XML File")], string="Importing Type", required=True
)

xml = fields.Binary(string="XML to Import")

fiscal_operation_type = fields.Selection(
string="Fiscal Operation Type", selection=FISCAL_IN_OUT_ALL
)

def import_xml(self):
self.document_id = self.create_edoc_from_xml()

return {
"name": _("Document Imported"),
"type": "ir.actions.act_window",
"target": "current",
"views": [[False, "form"]],
"res_id": self.document_id.id,
"res_model": "l10n_br_fiscal.document",
}

def create_edoc_from_xml(self):
return NotImplemented
51 changes: 51 additions & 0 deletions l10n_br_fiscal/wizards/document_import_wizard_mixin.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 KMEE
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="l10n_br_fiscal_document_import_wizard_mixin_form" model="ir.ui.view">
<field name="name">l10n_br_fiscal.document.import.wizard.mixin.form</field>
<field name="model">l10n_br_fiscal.document.import.wizard.mixin</field>
<field name="arch" type="xml">
<form string="Import Document">
<group>
<field name="company_id" />
<field name="importing_type" />
<field
name="xml"
attrs="{
'invisible': [('importing_type', '!=', 'xml_file')],
'required': [('importing_type', '=', 'xml_file')]
}"
/>
</group>
<separator
string="Preview Data"
attrs="{'invisible': [('xml', '=', False)]}"
/>
<group id="document_info" attrs="{'invisible': [('xml', '=', False)]}">
<group>
<field name="document_key" readonly="1" />
<field name="document_number" readonly="1" />
<field name="document_serie" readonly="1" />
</group>

<group>
<field name="partner_id" readonly="1" />
</group>
</group>
<footer>
<button
name="import_xml"
string="Import"
class="btn-primary"
type="object"
attrs="{'invisible': [('importing_type', '!=', 'xml_file')]}"
/>
<button string="Cancel" class="btn-default" special="cancel" />
</footer>
</form>
</field>
</record>

</odoo>
2 changes: 2 additions & 0 deletions l10n_br_fiscal_purchase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import tests
20 changes: 20 additions & 0 deletions l10n_br_fiscal_purchase/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2023 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "L10n Br Fiscal Purchase",
"summary": """
Fiscal Purchase""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "KMEE,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/l10n-brazil",
"depends": [
"l10n_br_fiscal",
"l10n_br_purchase",
],
"data": [
"views/document_view.xml",
"views/purchase_order_view.xml",
],
}
3 changes: 3 additions & 0 deletions l10n_br_fiscal_purchase/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import document_fiscal_mixin_methods
from . import purchase_order
from . import document
24 changes: 24 additions & 0 deletions l10n_br_fiscal_purchase/models/document.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 KMEE (Felipe Zago Rodrigues <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class FiscalDocument(models.Model):
_inherit = "l10n_br_fiscal.document"

linked_purchase_ids = fields.Many2many(
comodel_name="purchase.order",
relation="nfe_purchase_relation_1",
column1="document_id",
column2="purchase_id",
string="Ordens de Compra",
copy=False,
)

linked_purchase_count = fields.Integer(compute="_compute_linked_purchase_count")

@api.depends("linked_purchase_ids")
def _compute_linked_purchase_count(self):
for rec in self:
rec.linked_purchase_count = len(rec.linked_purchase_ids)
24 changes: 24 additions & 0 deletions l10n_br_fiscal_purchase/models/document_fiscal_mixin_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2023 KMEE (Felipe Zago Rodrigues <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class FiscalDocumentMixinMethods(models.AbstractModel):
_inherit = "l10n_br_fiscal.document.mixin.methods"

def action_open_purchase(self):
result = self.env.ref(
"l10n_br_fiscal_purchase.action_purchase_tree_all"
).read()[0]
purchase_ids = self.mapped("linked_purchase_ids")

if len(purchase_ids) == 1:
result = self.env.ref(
"l10n_br_fiscal_purchase.action_purchase_form_all"
).read()[0]
result["res_id"] = purchase_ids[0].id
else:
result["domain"] = "[('id', 'in', %s)]" % (purchase_ids.ids)

return result
27 changes: 27 additions & 0 deletions l10n_br_fiscal_purchase/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2023 KMEE (Felipe Zago Rodrigues <[email protected]>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

imported = fields.Boolean(string="Imported")

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

def _prepare_invoice(self):
return {
**super()._prepare_invoice(),
"fiscal_document_id": self.origin_document_id.id,
"document_type_id": self.origin_document_id.document_type_id.id,
}


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

origin_document_line_id = fields.Many2one(
comodel_name="l10n_br_fiscal.document.line"
)
2 changes: 2 additions & 0 deletions l10n_br_fiscal_purchase/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* `KMEE <https://www.kmee.com.br>`_:
* Felipe Zago Rodrigues <[email protected]>
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions l10n_br_fiscal_purchase/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_purchase_order
85 changes: 85 additions & 0 deletions l10n_br_fiscal_purchase/tests/test_purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Copyright 2023 Felipe Zago Rodrigues - KMEE
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo.tests import TransactionCase


class TestPurchaseOorder(TransactionCase):
def setUp(self):
super().setUp()

self.partner_1 = self.env["res.partner"].create({"name": "PARTNER TEST 1"})
self.product_1 = self.env["product.product"].create(
{
"name": "PRODUCT TEST 1",
"list_price": 10,
"uom_id": self.env.ref("uom.product_uom_unit").id,
}
)
self.nfe_fiscal_document = self.env["l10n_br_fiscal.document"].create(
{
"document_type_id": self.env.ref(
"l10n_br_fiscal.document_55_serie_1"
).id,
"fiscal_operation_type": "out",
"fiscal_line_ids": [
(0, 0, {"name": "LINE TEST 1", "product_id": self.product_1.id})
],
"active": False,
}
)

def create_and_invoice_purchase_order(self):
purchase_order = (
self.env["purchase.order"]
.with_context(tracking_disable=True)
.create(
{
"partner_id": self.partner_1.id,
"origin_document_id": self.nfe_fiscal_document.id,
}
)
)
PurchaseOrderLine = self.env["purchase.order.line"].with_context(
tracking_disable=True
)
PurchaseOrderLine.create(
{
"name": self.product_1.name,
"product_id": self.product_1.id,
"product_qty": 10.0,
"product_uom": self.product_1.uom_id.id,
"price_unit": self.product_1.list_price,
"order_id": purchase_order.id,
"origin_document_line_id": self.nfe_fiscal_document.fiscal_line_ids[
0
].id,
}
)
purchase_order.button_confirm()
purchase_order.order_line.qty_received = 10
purchase_order.action_create_invoice()
return purchase_order

def test_create_and_invoice_purchase(self):
purchase_order_1 = self.create_and_invoice_purchase_order()
purchase_order_2 = self.create_and_invoice_purchase_order()

prepare_vals = purchase_order_1._prepare_invoice()
self.assertEqual(
prepare_vals["fiscal_document_id"], self.nfe_fiscal_document.id
)
self.assertEqual(
prepare_vals["document_type_id"],
self.nfe_fiscal_document.document_type_id.id,
)

self.nfe_fiscal_document.linked_purchase_ids = [(4, purchase_order_1.id)]
action = self.nfe_fiscal_document.action_open_purchase()
self.assertEqual(action["res_id"], purchase_order_1.id)

self.nfe_fiscal_document.linked_purchase_ids = [(4, purchase_order_2.id)]
action = self.nfe_fiscal_document.action_open_purchase()
self.assertIn("domain", action)

self.assertEqual(self.nfe_fiscal_document.linked_purchase_count, 2)
27 changes: 27 additions & 0 deletions l10n_br_fiscal_purchase/views/document_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<odoo>
<record id="fiscal_purchase_document_form" model="ir.ui.view">
<field
name="name"
>l10n_br_nfe.fiscal.purchase.document.form (in l10n_br_fiscal_purchase)</field>
<field name="model">l10n_br_fiscal.document</field>
<field name="inherit_id" ref="l10n_br_fiscal.document_form" />
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<field name="linked_purchase_ids" invisible="1" />
<button
type="object"
name="action_open_purchase"
class="oe_stat_button"
icon="fa-folder-open"
attrs="{'invisible':[('linked_purchase_ids', '=', [])]}"
>
<field
name="linked_purchase_count"
widget="statinfo"
string="Purchase Orders"
/>
</button>
</xpath>
</field>
</record>
</odoo>
Loading