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 Aug 16, 2024
1 parent 86f301f commit de949d1
Show file tree
Hide file tree
Showing 10 changed files with 69 additions and 161 deletions.
7 changes: 5 additions & 2 deletions account_invoice_inter_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ Configuration
To configure this module, you need to go to the menu *Settings > General
Settings*, go to the tab *Companies / Inter Company OCA features*

You now have access to other checks *Common Product Catalog* and
*Invoice Auto Validation*.
You now have access to other options *Intercompany user for invoices*
and *Invoice Auto Validation*.

To customize products sharing don't hesitate to override
\_compute_share_product() in res.company model.
Expand Down Expand Up @@ -106,6 +106,9 @@ Contributors
- Pedro M. Baeza

- Isaac Gallart <igallart@puntsistemes.es>
- \`Komit <https://komit-consulting.com>\`:

- Cuong Nguyen Mtm <cuong.nmtm@komit-consulting.com>

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
6 changes: 2 additions & 4 deletions account_invoice_inter_company/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,6 @@ def action_post(self):

def _check_intercompany_product(self, dest_company):
self.ensure_one()
if dest_company.company_share_product:
return
domain = dest_company._get_user_domain()
dest_user = self.env["res.users"].search(domain, limit=1)
for line in self.invoice_line_ids:
Expand All @@ -76,8 +74,8 @@ def _check_intercompany_product(self, dest_company):
except AccessError as e:
raise UserError(
_(
"You cannot create invoice in company '%(dest_company_name)s' with "
"product '%(product_name)s' because it is not multicompany"
"You cannot create invoice in company '%(dest_company_name)s' "
"with product '%(product_name)s' because it is not multicompany"
)
% {
"dest_company_name": dest_company.name,
Expand Down
16 changes: 0 additions & 16 deletions account_invoice_inter_company/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@
class ResCompany(models.Model):
_inherit = "res.company"

company_share_product = fields.Boolean(
"Share product to all companies",
compute="_compute_share_product",
compute_sudo=True,
help="Share your product to all companies defined in your instance.\n"
" * Checked : Product are visible for every company, "
"even if a company is defined on the partner.\n"
" * Unchecked : Each company can see only its product "
"(product where company is defined). Product not related to a "
"company are visible for all companies.",
)
invoice_auto_validation = fields.Boolean(
help="When an invoice is created by a multi company rule "
"for this company, it will automatically validate it",
Expand All @@ -29,11 +18,6 @@ class ResCompany(models.Model):
"intercompany rules.",
)

def _compute_share_product(self):
product_rule = self.env.ref("product.product_comp_rule")
for company in self:
company.company_share_product = not bool(product_rule.active)

def _get_user_domain(self):
self.ensure_one()
group_account_invoice = self.env.ref("account.group_account_invoice")
Expand Down
26 changes: 1 addition & 25 deletions account_invoice_inter_company/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
Expand All @@ -20,27 +20,3 @@ class ResConfigSettings(models.TransientModel):
"intercompany rules. If not set the user initiating the"
"transaction will be used",
)
company_share_product = fields.Boolean(
"Share product to all companies",
help="Share your product to all companies defined in your instance.\n"
" * Checked : Product are visible for every company, "
"even if a company is defined on the partner.\n"
" * Unchecked : Each company can see only its product "
"(product where company is defined). Product not related to a "
"company are visible for all companies.",
)

@api.model
def get_values(self):
res = super().get_values()
product_rule = self.env.ref("product.product_comp_rule")
res.update(
company_share_product=not bool(product_rule.active),
)
return res

def set_values(self):
res = super().set_values()
product_rule = self.env.ref("product.product_comp_rule")
product_rule.write({"active": not bool(self.company_share_product)})
return res
2 changes: 1 addition & 1 deletion account_invoice_inter_company/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ To configure this module, you need to go to the menu *Settings \>
General Settings*, go to the tab *Companies / Inter Company OCA
features*

You now have access to other checks *Common Product Catalog* and
You now have access to other options *Intercompany user for invoices* and
*Invoice Auto Validation*.

To customize products sharing don't hesitate to override
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 \<<igallart@puntsistemes.es>\>
- \`Komit \<<https://komit-consulting.com>\>\`:
- Cuong Nguyen Mtm \<<cuong.nmtm@komit-consulting.com>\>
20 changes: 13 additions & 7 deletions account_invoice_inter_company/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.

Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.

See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -397,8 +397,8 @@ <h1 class="title">Inter Company Invoices</h1>
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<p>To configure this module, you need to go to the menu <em>Settings &gt; General
Settings</em>, go to the tab <em>Companies / Inter Company OCA features</em></p>
<p>You now have access to other checks <em>Common Product Catalog</em> and
<em>Invoice Auto Validation</em>.</p>
<p>You now have access to other options <em>Intercompany user for invoices</em>
and <em>Invoice Auto Validation</em>.</p>
<p>To customize products sharing don’t hesitate to override
_compute_share_product() in res.company model.</p>
</div>
Expand Down Expand Up @@ -453,12 +453,18 @@ <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">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
76 changes: 25 additions & 51 deletions account_invoice_inter_company/tests/test_inter_company_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
# 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 odoo.exceptions import UserError
from odoo.tests import tagged
from odoo.tests.common import Form, TransactionCase

Expand All @@ -16,37 +15,23 @@ 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,
"invoice_auto_validation": True,
}
)
cls.chart.try_loading(company=cls.company_a, install_demo=False)
cls.partner_company_a = cls.env["res.partner"].create(
{"name": cls.company_a.name, "is_company": True}
)
cls.company_a.partner_id = cls.partner_company_a
cls.company_b = cls.env["res.company"].create(
{
"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,
"invoice_auto_validation": True,
}
)
cls.chart.try_loading(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 All @@ -59,7 +44,6 @@ def setUpClass(cls):
}
)
cls.company_b.partner_id = cls.partner_company_b
# cls.partner_company_b = cls.company_b.parent_id.partner_id
cls.user_company_a = cls.env["res.users"].create(
{
"name": "User A",
Expand Down Expand Up @@ -332,15 +316,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 +338,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 @@ -373,7 +358,6 @@ def setUpClass(cls):
)
cls.invoice_company_a.partner_id = cls.partner_company_b
cls.invoice_company_a.journal_id = cls.sales_journal_company_a
cls.invoice_company_a.currency_id = cls.env.ref("base.EUR")

with cls.invoice_company_a.invoice_line_ids.new() as line_form:
line_form.product_id = cls.product_consultant_multi_company
Expand All @@ -390,7 +374,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 +399,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 +429,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 +440,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 @@ -484,30 +471,17 @@ def test_confirm_invoice_with_child_partner(self):
)
self.assertEqual(len(invoices), 1)

def test_confirm_invoice_with_product_and_shared_catalog(self):
"""With no security rule, child company have access to any product.
Then child invoice can share the same product
"""
# 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})
invoices = self._confirm_invoice_with_product()
self.assertNotEqual(
invoices.invoice_line_ids[0].product_id, self.env["product.product"]
)

def test_confirm_invoice_with_native_product_rule_and_shared_product(self):
"""With native security rule, products with access in both companies
must be present in parent and child invoices.
"""
# 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)]})

Check warning on line 484 in account_invoice_inter_company/tests/test_inter_company_invoice.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_inter_company/tests/test_inter_company_invoice.py#L484

Added line #L484 was not covered by tests
invoices = self._confirm_invoice_with_product()
self.assertEqual(invoices.invoice_line_ids[0].product_id, self.product_a)

Expand All @@ -518,10 +492,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.sudo().write({"company_ids": [(6, 0, [self.company_a.id])]})

Check warning on line 498 in account_invoice_inter_company/tests/test_inter_company_invoice.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_inter_company/tests/test_inter_company_invoice.py#L498

Added line #L498 was not covered by tests
with self.assertRaises(UserError):
self._confirm_invoice_with_product()

Expand Down
Loading

0 comments on commit de949d1

Please sign in to comment.