-
-
Notifications
You must be signed in to change notification settings - Fork 314
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] account_invoice_import: Migration to 16.0
- Loading branch information
Showing
8 changed files
with
480 additions
and
208 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
|
@@ -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( | ||
{ | ||
|
@@ -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 = [ | ||
{ | ||
|
@@ -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( | ||
|
@@ -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) | ||
|
@@ -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( | ||
|
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.