Skip to content

Commit

Permalink
[MIG] account_invoice_import: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
V3st1g3 committed Dec 11, 2024
1 parent dce4eea commit b951da2
Show file tree
Hide file tree
Showing 8 changed files with 480 additions and 208 deletions.
10 changes: 5 additions & 5 deletions account_invoice_import/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ Account Invoice Import
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
:target: https://github.com/OCA/edi/tree/14.0/account_invoice_import
:target: https://github.com/OCA/edi/tree/16.0/account_invoice_import
:alt: OCA/edi
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import
:target: https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_invoice_import
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=14.0
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
Expand Down Expand Up @@ -99,7 +99,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2016.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.

Expand Down Expand Up @@ -142,6 +142,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-alexis-via|

This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/14.0/account_invoice_import>`_ project on GitHub.
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/16.0/account_invoice_import>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 1 addition & 1 deletion account_invoice_import/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{
"name": "Account Invoice Import",
"version": "14.0.3.4.0",
"version": "16.0.1.0.0",
"category": "Accounting & Finance",
"license": "AGPL-3",
"summary": "Import supplier invoices/refunds as PDF or XML files",
Expand Down
6 changes: 3 additions & 3 deletions account_invoice_import/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ <h1 class="title">Account Invoice Import</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:26f0853d4122605d020e48687fa420f66fdad1a6c7e41efe74059e0a845f5348
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi/tree/14.0/account_invoice_import"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-14-0/edi-14-0-account_invoice_import"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/edi/tree/16.0/account_invoice_import"><img alt="OCA/edi" src="https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/edi-16-0/edi-16-0-account_invoice_import"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/edi&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module has been started by lazy accounting users who hate enter they vendor bills manually in Odoo. Almost all companies have several vendor bills to enter regularly in the system from the same vendors: phone bill, electricity bill, Internet access, train tickets, etc. Most of these invoices are available as PDF. If we are able to automatically extract from the PDF the required information to enter the invoice as vendor bill in Odoo, then this module will create it automatically. To know the full story behind the development of this module, read this <a class="reference external" href="http://www.akretion.com/blog/akretions-christmas-present-for-the-odoo-community">blog post</a>.</p>
<p>In order to reliably extract the required information from the invoice, two international standards exists to describe an Invoice in XML:</p>
<ul class="simple">
Expand Down Expand Up @@ -441,7 +441,7 @@ <h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/edi/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<a class="reference external" href="https://github.com/OCA/edi/issues/new?body=module:%20account_invoice_import%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand Down Expand Up @@ -474,7 +474,7 @@ <h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/alexis-via"><img alt="alexis-via" src="https://github.com/alexis-via.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/14.0/account_invoice_import">OCA/edi</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/edi/tree/16.0/account_invoice_import">OCA/edi</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
213 changes: 120 additions & 93 deletions account_invoice_import/tests/test_invoice_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,50 @@
# @author: Simone Orsi <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

import logging
from unittest import mock
from contextlib import contextmanager
from logging import getLogger

from odoo import fields
from odoo.tests.common import SavepointCase
from odoo import api, fields
from odoo.tests.common import TransactionCase
from odoo.tools import file_open, float_is_zero

logger = logging.getLogger(__name__)
logger = getLogger(__name__)


class TestInvoiceImport(SavepointCase):
class TestInvoiceImport(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company = cls.env.ref("base.main_company")
cls.company.invoice_import_email = "[email protected]"
cls.expense_account = cls.env["account.account"].create(
{
"code": "612AII",
"name": "expense account invoice import",
"user_type_id": cls.env.ref("account.data_account_type_expenses").id,
"company_id": cls.company.id,
}
[
{
"code": "612AII",
"name": "expense account invoice import",
"account_type": "expense",
"company_id": cls.company.id,
}
]
)
cls.income_account = cls.env["account.account"].create(
{
"code": "707AII",
"name": "revenue account invoice import",
"user_type_id": cls.env.ref("account.data_account_type_revenue").id,
"company_id": cls.company.id,
}
[
{
"code": "707AII",
"name": "revenue account invoice import",
"account_type": "income",
"company_id": cls.company.id,
}
]
)
cls.adjustment_account = cls.env["account.account"].create(
{
"code": "Adjustment",
"name": "adjustment from invoice import",
"user_type_id": cls.env.ref(
"account.data_account_type_current_assets"
).id,
}
[
{
"code": "Adjustment",
"name": "adjustment from invoice import",
"account_type": "asset_current",
}
]
)
purchase_tax_vals = {
"name": "Test 1% VAT Purchase",
Expand All @@ -54,11 +58,12 @@ def setUpClass(cls):
"unece_type_id": cls.env.ref("account_tax_unece.tax_type_vat").id,
"unece_categ_id": cls.env.ref("account_tax_unece.tax_categ_s").id,
"company_id": cls.company.id,
"country_id": cls.env.ref("base.us").id,
# TODO tax armageddon
# "account_id": cls.expense_account.id,
# "refund_account_id": cls.expense_account.id,
}
cls.purchase_tax = cls.env["account.tax"].create(purchase_tax_vals)
cls.purchase_tax = cls.env["account.tax"].create([purchase_tax_vals])
sale_tax_vals = purchase_tax_vals.copy()
sale_tax_vals.update(
{
Expand All @@ -67,16 +72,18 @@ def setUpClass(cls):
"type_tax_use": "sale",
}
)
cls.sale_tax = cls.env["account.tax"].create(sale_tax_vals)
cls.sale_tax = cls.env["account.tax"].create([sale_tax_vals])
cls.product = cls.env["product.product"].create(
{
"name": "Expense product",
"default_code": "AII-TEST-PRODUCT",
"taxes_id": [(6, 0, [cls.sale_tax.id])],
"supplier_taxes_id": [(6, 0, [cls.purchase_tax.id])],
"property_account_income_id": cls.income_account.id,
"property_account_expense_id": cls.expense_account.id,
}
[
{
"name": "Expense product",
"default_code": "AII-TEST-PRODUCT",
"taxes_id": [(6, 0, [cls.sale_tax.id])],
"supplier_taxes_id": [(6, 0, [cls.purchase_tax.id])],
"property_account_income_id": cls.income_account.id,
"property_account_expense_id": cls.expense_account.id,
}
]
)
cls.all_import_config = [
{
Expand All @@ -99,51 +106,60 @@ def setUpClass(cls):
# Deco Addict
cls.env.ref("base.res_partner_2").customer_rank = 1
cls.pur_journal1 = cls.env["account.journal"].create(
{
"type": "purchase",
"code": "XXXP1",
"name": "Test Purchase Journal 1",
"sequence": 10,
"company_id": cls.company.id,
}
[
{
"type": "purchase",
"code": "XXXP1",
"name": "Test Purchase Journal 1",
"sequence": 10,
"company_id": cls.company.id,
}
]
)
cls.pur_journal2 = cls.env["account.journal"].create(
{
"type": "purchase",
"code": "XXXP2",
"name": "Test Purchase Journal 2",
"sequence": 100,
"company_id": cls.company.id,
}
[
{
"type": "purchase",
"code": "XXXP2",
"name": "Test Purchase Journal 2",
"sequence": 100,
"company_id": cls.company.id,
"default_account_id": cls.expense_account.id,
}
]
)
cls.partner_with_email = cls.env["res.partner"].create(
{
"is_company": True,
"name": "AgroMilk",
"email": "[email protected]",
"country_id": cls.env.ref("base.fr").id,
}
[
{
"is_company": True,
"name": "AgroMilk",
"email": "[email protected]",
"country_id": cls.env.ref("base.fr").id,
}
]
)
cls.partner_with_email_with_inv_config = cls.env["res.partner"].create(
{
"is_company": True,
"name": "Anevia",
"email": "[email protected]",
"country_id": cls.env.ref("base.fr").id,
"invoice_import_ids": [
(
0,
0,
{
"name": "Import config for Anevia",
"company_id": cls.company.id,
"invoice_line_method": "1line_static_product",
"static_product_id": cls.product.id,
"label": "Flamingo 220S",
},
)
],
}
[
{
"is_company": True,
"name": "Anevia",
"email": "[email protected]",
"country_id": cls.env.ref("base.fr").id,
"invoice_import_ids": [
(
0,
0,
{
"name": "Import config for Anevia",
"company_id": cls.company.id,
"invoice_line_method": "1line_static_product",
"static_product_id": cls.product.id,
"label": "Flamingo 220S",
},
)
],
}
]
)
company = cls.env.ref("base.main_company")
company.update(
Expand Down Expand Up @@ -364,35 +380,46 @@ def test_email_gateway(self):
mail_channel_noautofollow=True
).message_process("account.invoice.import", self._fake_email)

@contextmanager
def _force_message_parse(self, forced_value):
@api.model
def message_parse(this, message, save_original=False):
return forced_value

MailThread = self.env["mail.thread"]
MailThread._patch_method("message_parse", message_parse)
yield
MailThread._revert_method("message_parse")

def test_email_gateway_multi_comp_1_matching(self):
comp = self.env["res.company"].create(
{
"name": "Let it fail INC",
"invoice_import_email": "[email protected]",
}
[
{
"name": "Let it fail INC",
"invoice_import_email": "[email protected]",
}
]
)
logger_name = "odoo.addons.account_invoice_import.wizard.account_invoice_import"

mock_parse = mock.patch.object(type(self.env["mail.thread"]), "message_parse")
with self.assertLogs(logger_name) as watcher:
# NOTE: for some reason in tests the msg is not parsed properly
# and message_dict is kind of empty.
# Nevertheless, it doesn't really matter
# because here we want to make sure that the code works as expected
# when a msg is properly parsed.
with mock_parse as mocked:
mocked_msg = {
"to": "[email protected]",
"email_from": "Nina Marton <[email protected]>",
"message_id": "<[email protected]>",
"references": "",
"in_reply_to": "",
"subject": "Happy Birthday",
"recipients": "[email protected]",
"body": self._fake_email,
"date": "2022-05-26 10:30:00",
}
mocked.return_value = mocked_msg
mocked_msg = {
"to": "[email protected]",
"email_from": "Nina Marton <[email protected]>",
"message_id": "<[email protected]>",
"references": "",
"in_reply_to": "",
"subject": "Happy Birthday",
"recipients": "[email protected]",
"body": self._fake_email,
"date": "2022-05-26 10:30:00",
}
with self._force_message_parse(forced_value=mocked_msg):
self.env["mail.thread"].with_context(
mail_channel_noautofollow=True
).message_process("account.invoice.import", self._fake_email)
Expand All @@ -408,7 +435,7 @@ def test_email_gateway_multi_comp_1_matching(self):
self.assertIn(msg, "\n".join(watcher.output))

def test_email_gateway_multi_comp_none_matching(self):
self.env["res.company"].create({"name": "Let it fail INC"})
self.env["res.company"].create([{"name": "Let it fail INC"}])
logger_name = "odoo.addons.account_invoice_import.wizard.account_invoice_import"
with self.assertLogs(logger_name, "ERROR") as watcher:
self.env["mail.thread"].with_context(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<group name="main">
<field name="name" />
<field name="partner_id" />
<field name="company_id" invisible="1" />
<field name="company_id" groups="base.group_multi_company" />
<field name="active" invisible="1" />
</group>
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_import/views/account_journal_dashboard.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view" />
<field name="arch" type="xml">
<button
class="btn btn-primary o_button_upload_bill oe_kanban_action_button"
name="action_create_vendor_bill"
journal_type="purchase"
position="attributes"
>
Expand Down
Loading

0 comments on commit b951da2

Please sign in to comment.