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

[FIX] account_invoice_inter_company: Move demo data to test #110

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 account_invoice_inter_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Contributors
* Chafique Delli <chafique.delli@akretion.com>
* Alexis de Lattre <alexis.delattre@akretion.com>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Jairo Llopis <jairo.llopis@tecnativa.com>

Maintainer
----------
Expand Down
5 changes: 1 addition & 4 deletions account_invoice_inter_company/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
'name': 'Inter Company Module for Invoices',
'summary': 'Intercompany invoice rules',
'version': '11.0.1.0.1',
'version': '11.0.1.0.2',
'category': 'Accounting & Finance',
'website': 'https://github.com/OCA/multi-company',
'author': 'Odoo SA, Akretion, Odoo Community Association (OCA)',
Expand All @@ -17,8 +17,5 @@
'data': [
'views/res_config_settings_view.xml',
],
'demo': [
'demo/inter_company_invoice.xml',
],
'installable': True,
}
41 changes: 21 additions & 20 deletions account_invoice_inter_company/tests/test_inter_company_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,38 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _
from odoo.tests.common import TransactionCase
from odoo.tests.common import SavepointCase
from odoo.exceptions import ValidationError
from odoo.modules.module import get_resource_path
from odoo.tools import convert_file


class TestAccountInvoiceInterCompany(TransactionCase):
def setUp(self):
super(TestAccountInvoiceInterCompany, self).setUp()
self.wizard_obj = self.env['wizard.multi.charts.accounts']
self.account_obj = self.env['account.account']
self.invoice_obj = self.env['account.invoice']
self.invoice_company_a = self.env.ref(
class TestAccountInvoiceInterCompany(SavepointCase):
@classmethod
def setUpClass(cls):
super(TestAccountInvoiceInterCompany, cls).setUpClass()
module = "account_invoice_inter_company"
convert_file(
cls.cr, module,
get_resource_path(module, "tests", "inter_company_invoice.xml"),
None, 'init', False, 'test', cls.registry._assertion_report,
)
cls.wizard_obj = cls.env['wizard.multi.charts.accounts']
cls.account_obj = cls.env['account.account']
cls.invoice_obj = cls.env['account.invoice']
cls.invoice_company_a = cls.env.ref(
'account_invoice_inter_company.customer_invoice_company_a')
self.user_company_a = self.env.ref(
cls.user_company_a = cls.env.ref(
'account_invoice_inter_company.user_company_a')
self.user_company_b = self.env.ref(
cls.user_company_b = cls.env.ref(
'account_invoice_inter_company.user_company_b')

self.chart = self.env['account.chart.template'].search([], limit=1)
if not self.chart:
cls.chart = cls.env['account.chart.template'].search([], limit=1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be the method. You have a method try_load_chart_template or similar executed on company record for loading the proper chart template.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAICS this line can be removed, as it's not used. I don't want to refactor everything unless strictly necessary, TBH.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But you need to load the chart template any way. Previously they tricked the system adding as demo all the stuff that this method makes. You need also to look for demo XML-IDs used here in the test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I'm just loading the XML data in the test itself. It seems a common pattern for testing when you need to lazy-load some demo data, or you need to ensure its state. This way I don't need to rewrite the tests.

You can see it works fine.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it can cause side effects, as not all data is properly set (from the account module perspective, and this is an irregular way of having a chart of account. For example, field chart_template_id on company is not set - as there's no chart template -), so this can throw side effects, not right now, but on future changes or dependent modules.

if not cls.chart:
raise ValidationError(
# translation to avoid pylint warnings
_("No Chart of Account Template has been defined !"))

# Fix default value of company_id set by the company_ids field
# of base_multi_company module
# if self.invoice_company_a.partner_id.company_ids:
# self.invoice_company_a.partner_id.company_ids = [(6, 0, [])]
# for line in self.invoice_company_a.invoice_line_ids:
# if line.product_id.company_ids:
# line.product_id.company_ids = [(6, 0, [])]

def test01_user(self):
# Check user of company B (company of destination)
# with which we check the intercompany product
Expand Down