Skip to content

Commit

Permalink
[MIG] account_invoice_inter_company: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cuongnmtm committed Mar 15, 2024
1 parent 1d14f35 commit 92f1a19
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 90 deletions.
3 changes: 3 additions & 0 deletions account_invoice_inter_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ Contributors
- Pedro M. Baeza

- Isaac Gallart <[email protected]>
- \`Komit <https://komit-consulting.com>\`:

- Cuong Nguyen Mtm <[email protected]>

Maintainers
-----------
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_inter_company/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
{
"name": "Inter Company Invoices",
"summary": "Intercompany invoice rules",
"version": "16.0.1.0.2",
"version": "17.0.1.0.0",
"category": "Accounting & Finance",
"website": "https://github.com/OCA/multi-company",
"author": "Odoo SA, Akretion, Odoo Community Association (OCA)",
Expand Down
2 changes: 2 additions & 0 deletions account_invoice_inter_company/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
- David Vidal
- Pedro M. Baeza
- Isaac Gallart \<<[email protected]>\>
- \`Komit \<<https://komit-consulting.com>\>\`:
- Cuong Nguyen Mtm \<<[email protected]>\>
4 changes: 4 additions & 0 deletions account_invoice_inter_company/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
</ul>
</li>
<li>Isaac Gallart &lt;<a class="reference external" href="mailto:igallart&#64;puntsistemes.es">igallart&#64;puntsistemes.es</a>&gt;</li>
<li>`Komit &lt;<a class="reference external" href="https://komit-consulting.com">https://komit-consulting.com</a>&gt;`:<ul>
<li>Cuong Nguyen Mtm &lt;<a class="reference external" href="mailto:cuong.nmtm&#64;komit-consulting.com">cuong.nmtm&#64;komit-consulting.com</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
102 changes: 69 additions & 33 deletions account_invoice_inter_company/tests/test_inter_company_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,60 @@
# Copyright 2020 Tecnativa - Pedro M. Baeza
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _
from odoo.exceptions import UserError, ValidationError
from unittest.mock import patch

from odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.tests.common import Form, TransactionCase

from odoo.addons.account.models.chart_template import AccountChartTemplate
from odoo.addons.account.tests.test_chart_template import test_get_data


def _get_chart_template_mapping(self, get_all=False):
return {
"test": {
"name": "test",
"country_id": None,
"country_code": None,
"modules": ["account"],
"parent": None,
}
}


@tagged("post_install", "-at_install")
@patch.object(
AccountChartTemplate, "_get_chart_template_mapping", _get_chart_template_mapping
)
class TestAccountInvoiceInterCompanyBase(TransactionCase):
@classmethod
@patch.object(
AccountChartTemplate, "_get_chart_template_mapping", _get_chart_template_mapping
)
def setUpClass(cls):
super().setUpClass()
cls.account_obj = cls.env["account.account"]
cls.account_move_obj = cls.env["account.move"]
cls.chart = cls.env["account.chart.template"].search([], limit=1)
if not cls.chart:
raise ValidationError(
# translation to avoid pylint warnings
_("No Chart of Account Template has been defined !")
)

cls.company_a = cls.env["res.company"].create(
{
"name": "Company A",
"currency_id": cls.env.ref("base.EUR").id,
"country_id": cls.env.ref("base.fr").id,
"parent_id": cls.env.ref("base.main_company").id,
# "parent_id": cls.env.ref("base.main_company").id,
"invoice_auto_validation": True,
}
)
cls.chart.try_loading(company=cls.company_a, install_demo=False)
with patch.object(
AccountChartTemplate,
"_get_chart_template_data",
side_effect=test_get_data,
autospec=True,
):
cls.env["account.chart.template"].try_loading(
"test", company=cls.company_a, install_demo=False
)
cls.partner_company_a = cls.env["res.partner"].create(
{"name": cls.company_a.name, "is_company": True}
)
Expand All @@ -42,11 +66,19 @@ def setUpClass(cls):
"name": "Company B",
"currency_id": cls.env.ref("base.EUR").id,
"country_id": cls.env.ref("base.fr").id,
"parent_id": cls.env.ref("base.main_company").id,
# "parent_id": cls.env.ref("base.main_company").id,
"invoice_auto_validation": True,
}
)
cls.chart.try_loading(company=cls.company_b, install_demo=False)
with patch.object(
AccountChartTemplate,
"_get_chart_template_data",
side_effect=test_get_data,
autospec=True,
):
cls.env["account.chart.template"].try_loading(
"test", company=cls.company_b, install_demo=False
)
cls.partner_company_b = cls.env["res.partner"].create(
{"name": cls.company_b.name, "is_company": True}
)
Expand Down Expand Up @@ -332,15 +364,6 @@ def setUpClass(cls):
"company_id": cls.company_a.id,
}
)
cls.pcg_X58 = cls.env["account.account.template"].create(
{
"name": "Internal Transfers",
"code": "X58",
"account_type": "asset_current",
"reconcile": True,
}
)

cls.a_recv_company_a = cls.account_obj.create(
{
"code": "X11002.A",
Expand All @@ -363,8 +386,18 @@ def setUpClass(cls):
cls.partner_company_a.property_account_receivable_id = cls.a_recv_company_a.id
cls.partner_company_a.property_account_payable_id = cls.a_pay_company_a.id

cls.partner_company_b.property_account_receivable_id = cls.a_recv_company_b.id
cls.partner_company_b.property_account_payable_id = cls.a_pay_company_b.id
cls.partner_company_b.with_user(
cls.user_company_a.id
).property_account_receivable_id = cls.a_recv_company_a.id
cls.partner_company_b.with_user(
cls.user_company_a.id
).property_account_payable_id = cls.a_pay_company_a.id
cls.partner_company_b.with_user(
cls.user_company_b.id
).property_account_receivable_id = cls.a_recv_company_b.id
cls.partner_company_b.with_user(
cls.user_company_b.id
).property_account_payable_id = cls.a_pay_company_b.id

cls.invoice_company_a = Form(
cls.account_move_obj.with_user(cls.user_company_a.id).with_context(
Expand All @@ -390,7 +423,7 @@ def setUpClass(cls):
cls.product_a = cls.invoice_line_a.product_id
cls.product_a.with_user(
cls.user_company_b.id
).property_account_expense_id = cls.a_expense_company_b.id
).sudo().property_account_expense_id = cls.a_expense_company_b.id


class TestAccountInvoiceInterCompany(TestAccountInvoiceInterCompanyBase):
Expand All @@ -415,7 +448,9 @@ def test03_confirm_invoice_and_cancel(self):
# ensure the catalog is shared
self.env.ref("product.product_comp_rule").write({"active": False})
# Make sure there are no taxes in target company for the used product
self.product_a.with_user(self.user_company_b.id).supplier_taxes_id = False
self.product_a.with_user(
self.user_company_b.id
).sudo().supplier_taxes_id = False
# Confirm the invoice of company A
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
# Check destination invoice created in company B
Expand Down Expand Up @@ -443,9 +478,9 @@ def test03_confirm_invoice_and_cancel(self):
self.invoice_company_a.invoice_line_ids[0].product_id,
)
# Cancel the invoice of company A
invoice_origin = ("%s - Canceled Invoice: %s") % (
self.invoice_company_a.company_id.name,
self.invoice_company_a.name,
invoice_origin = "{company_name} - Canceled Invoice: {invoice_name}".format(
company_name=self.invoice_company_a.company_id.name,
invoice_name=self.invoice_company_a.name,
)
self.invoice_company_a.with_user(self.user_company_a.id).button_cancel()
# Check invoices after to cancel invoice of company A
Expand All @@ -454,6 +489,7 @@ def test03_confirm_invoice_and_cancel(self):
self.assertEqual(invoices[0].invoice_origin, invoice_origin)
# Check if keep the invoice number
invoice_number = self.invoice_company_a.name
self.invoice_company_a.with_user(self.user_company_a.id).button_draft()
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
self.assertEqual(self.invoice_company_a.name, invoice_number)
# When the destination invoice is posted we can't modify the origin either
Expand Down Expand Up @@ -491,7 +527,7 @@ def test_confirm_invoice_with_product_and_shared_catalog(self):
# ensure the catalog is shared even if product is in other company
self.env.ref("product.product_comp_rule").write({"active": False})
# Product is set to a specific company
self.product_a.write({"company_id": self.company_a.id})
self.product_a.sudo().write({"company_id": self.company_a.id})
invoices = self._confirm_invoice_with_product()
self.assertNotEqual(
invoices.invoice_line_ids[0].product_id, self.env["product.product"]
Expand All @@ -504,10 +540,10 @@ def test_confirm_invoice_with_native_product_rule_and_shared_product(self):
# ensure the catalog is shared even if product is in other company
self.env.ref("product.product_comp_rule").write({"active": True})
# Product is set to a specific company
self.product_a.write({"company_id": False})
self.product_a.sudo().write({"company_id": False})
# If product_multi_company is installed
if "company_ids" in dir(self.product_a):
self.product_a.write({"company_ids": [(5, 0, 0)]})
self.product_a.sudo().write({"company_ids": [(5, 0, 0)]})
invoices = self._confirm_invoice_with_product()
self.assertEqual(invoices.invoice_line_ids[0].product_id, self.product_a)

Expand All @@ -518,10 +554,10 @@ def test_confirm_invoice_with_native_product_rule_and_unshared_product(self):
# ensure the catalog is shared even if product is in other company
self.env.ref("product.product_comp_rule").write({"active": True})
# Product is set to a specific company
self.product_a.write({"company_id": self.company_a.id})
self.product_a.sudo().write({"company_id": self.company_a.id})
# If product_multi_company is installed
if "company_ids" in dir(self.product_a):
self.product_a.write({"company_ids": [(6, 0, [self.company_a.id])]})
self.product_a.suwrite({"company_ids": [(6, 0, [self.company_a.id])]})
with self.assertRaises(UserError):
self._confirm_invoice_with_product()

Expand Down
91 changes: 35 additions & 56 deletions account_invoice_inter_company/views/res_config_settings_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,74 +4,53 @@
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base_setup.res_config_settings_view_form" />
<field name="arch" type="xml">
<xpath expr="//div[@id='inter_company']" position="attributes">
<attribute name="title" />
<xpath expr="//setting[@id='inter_company']" position="attributes">
<attribute name="invisible">1</attribute>
</xpath>
<xpath expr="//div[@id='inter_company']/div[2]/span" position="before">
<div class="o_form_label">Inter Company OCA features
<span
class="fa fa-lg fa-building-o"
title="Values set here are company-specific."
aria-label="Values set here are company-specific."
groups="base.group_multi_company"
role="img"
/>
</div>
</xpath>
<xpath expr="//div[@id='inter_company']/div[2]" position="inside">
<div id="company_share_product">
<field name="company_share_product" class="oe_inline" />
<label
string="Common Product Catalog"
class="o_light_label"
for="company_share_product"
/>
</div>
</xpath>
<xpath expr="//div[@id='inter_company']" position="after">
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane" />
<div class="o_setting_right_pane">
<div class="o_form_label mt8">Invoicing</div>
<div id="intercompany_invoice_user">
<xpath expr="//setting[@id='inter_company']" position="before">
<setting
id="inter_company_oca"
string="Inter Company OCA features"
company_dependent="1"
help="Automatically generate counterpart documents for orders/invoices between companies"
groups="base.group_multi_company"
>
<div>
<div>
<field name="company_share_product" />
<label
string="Intercompany user for invoices"
for="company_share_product"
string="Common Product Catalog"
class="o_light_label"
for="intercompany_invoice_user_id"
/>
<field
name="intercompany_invoice_user_id"
class="oe_inline"
</div>
</div>
</setting>
<setting
id="inter_company_oca_invoice"
string="Invoicing"
class="mt24"
groups="base.group_multi_company"
>
<div>
<div>
<label
for="invoice_auto_validation"
string="Intercompany user for invoices"
class="o_light_label"
/>
<field name="intercompany_invoice_user_id" />
</div>
<div id="inter_company_invoice_validation">
<field name="invoice_auto_validation" class="oe_inline" />
<div>
<field name="invoice_auto_validation" />
<label
for="invoice_auto_validation"
string="Invoice Auto Validation"
class="o_light_label"
for="invoice_auto_validation"
/>
</div>
</div>
</div>
</xpath>
<xpath
expr="//div[@id='inter_company']//field[@name='module_account_inter_company_rules']"
position="attributes"
>
<attribute name="attrs">{'invisible': True}</attribute>
</xpath>
<xpath
expr="//div[@id='inter_company']//label[@for='module_account_inter_company_rules']"
position="attributes"
>
<attribute name="attrs">{'invisible': True}</attribute>
</xpath>
<xpath
expr="//div[@id='inter_company']//field[@name='module_account_inter_company_rules']/../../div[2]/span"
position="attributes"
>
<attribute name="attrs">{'invisible': True}</attribute>
</setting>
</xpath>
</field>
</record>
Expand Down

0 comments on commit 92f1a19

Please sign in to comment.