Skip to content

Commit de949d1

Browse files
committed
[MIG] account_invoice_inter_company: Migration to 17.0
1 parent 86f301f commit de949d1

10 files changed

Lines changed: 69 additions & 161 deletions

File tree

account_invoice_inter_company/README.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ Configuration
5050
To configure this module, you need to go to the menu *Settings > General
5151
Settings*, go to the tab *Companies / Inter Company OCA features*
5252

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

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

108108
- Isaac Gallart <igallart@puntsistemes.es>
109+
- \`Komit <https://komit-consulting.com>\`:
110+
111+
- Cuong Nguyen Mtm <cuong.nmtm@komit-consulting.com>
109112

110113
Maintainers
111114
-----------

account_invoice_inter_company/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{
88
"name": "Inter Company Invoices",
99
"summary": "Intercompany invoice rules",
10-
"version": "16.0.1.0.2",
10+
"version": "17.0.1.0.0",
1111
"category": "Accounting & Finance",
1212
"website": "https://github.com/OCA/multi-company",
1313
"author": "Odoo SA, Akretion, Odoo Community Association (OCA)",

account_invoice_inter_company/models/account_move.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ def action_post(self):
6262

6363
def _check_intercompany_product(self, dest_company):
6464
self.ensure_one()
65-
if dest_company.company_share_product:
66-
return
6765
domain = dest_company._get_user_domain()
6866
dest_user = self.env["res.users"].search(domain, limit=1)
6967
for line in self.invoice_line_ids:
@@ -76,8 +74,8 @@ def _check_intercompany_product(self, dest_company):
7674
except AccessError as e:
7775
raise UserError(
7876
_(
79-
"You cannot create invoice in company '%(dest_company_name)s' with "
80-
"product '%(product_name)s' because it is not multicompany"
77+
"You cannot create invoice in company '%(dest_company_name)s' "
78+
"with product '%(product_name)s' because it is not multicompany"
8179
)
8280
% {
8381
"dest_company_name": dest_company.name,

account_invoice_inter_company/models/res_company.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,6 @@
66
class ResCompany(models.Model):
77
_inherit = "res.company"
88

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

32-
def _compute_share_product(self):
33-
product_rule = self.env.ref("product.product_comp_rule")
34-
for company in self:
35-
company.company_share_product = not bool(product_rule.active)
36-
3721
def _get_user_domain(self):
3822
self.ensure_one()
3923
group_account_invoice = self.env.ref("account.group_account_invoice")
Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
22

3-
from odoo import api, fields, models
3+
from odoo import fields, models
44

55

66
class ResConfigSettings(models.TransientModel):
@@ -20,27 +20,3 @@ class ResConfigSettings(models.TransientModel):
2020
"intercompany rules. If not set the user initiating the"
2121
"transaction will be used",
2222
)
23-
company_share_product = fields.Boolean(
24-
"Share product to all companies",
25-
help="Share your product to all companies defined in your instance.\n"
26-
" * Checked : Product are visible for every company, "
27-
"even if a company is defined on the partner.\n"
28-
" * Unchecked : Each company can see only its product "
29-
"(product where company is defined). Product not related to a "
30-
"company are visible for all companies.",
31-
)
32-
33-
@api.model
34-
def get_values(self):
35-
res = super().get_values()
36-
product_rule = self.env.ref("product.product_comp_rule")
37-
res.update(
38-
company_share_product=not bool(product_rule.active),
39-
)
40-
return res
41-
42-
def set_values(self):
43-
res = super().set_values()
44-
product_rule = self.env.ref("product.product_comp_rule")
45-
product_rule.write({"active": not bool(self.company_share_product)})
46-
return res

account_invoice_inter_company/readme/CONFIGURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ To configure this module, you need to go to the menu *Settings \>
22
General Settings*, go to the tab *Companies / Inter Company OCA
33
features*
44

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

88
To customize products sharing don't hesitate to override

account_invoice_inter_company/readme/CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@
1111
- David Vidal
1212
- Pedro M. Baeza
1313
- Isaac Gallart \<<igallart@puntsistemes.es>\>
14+
- \`Komit \<<https://komit-consulting.com>\>\`:
15+
- Cuong Nguyen Mtm \<<cuong.nmtm@komit-consulting.com>\>

account_invoice_inter_company/static/description/index.html

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -9,10 +8,11 @@
98

109
/*
1110
:Author: David Goodger (goodger@python.org)
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1616
1717
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
@@ -275,7 +275,7 @@
275275
margin-left: 2em ;
276276
margin-right: 2em }
277277

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

304-
span.problematic {
304+
span.problematic, pre.problematic {
305305
color: red }
306306

307307
span.section-subtitle {
@@ -397,8 +397,8 @@ <h1 class="title">Inter Company Invoices</h1>
397397
<h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
398398
<p>To configure this module, you need to go to the menu <em>Settings &gt; General
399399
Settings</em>, go to the tab <em>Companies / Inter Company OCA features</em></p>
400-
<p>You now have access to other checks <em>Common Product Catalog</em> and
401-
<em>Invoice Auto Validation</em>.</p>
400+
<p>You now have access to other options <em>Intercompany user for invoices</em>
401+
and <em>Invoice Auto Validation</em>.</p>
402402
<p>To customize products sharing don’t hesitate to override
403403
_compute_share_product() in res.company model.</p>
404404
</div>
@@ -453,12 +453,18 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
453453
</ul>
454454
</li>
455455
<li>Isaac Gallart &lt;<a class="reference external" href="mailto:igallart&#64;puntsistemes.es">igallart&#64;puntsistemes.es</a>&gt;</li>
456+
<li>`Komit &lt;<a class="reference external" href="https://komit-consulting.com">https://komit-consulting.com</a>&gt;`:<ul>
457+
<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>
458+
</ul>
459+
</li>
456460
</ul>
457461
</div>
458462
<div class="section" id="maintainers">
459463
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2>
460464
<p>This module is maintained by the OCA.</p>
461-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
465+
<a class="reference external image-reference" href="https://odoo-community.org">
466+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
467+
</a>
462468
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
463469
mission is to support the collaborative development of Odoo features and
464470
promote its widespread use.</p>

account_invoice_inter_company/tests/test_inter_company_invoice.py

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
# Copyright 2020 Tecnativa - Pedro M. Baeza
44
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
55

6-
from odoo import _
7-
from odoo.exceptions import UserError, ValidationError
6+
from odoo.exceptions import UserError
87
from odoo.tests import tagged
98
from odoo.tests.common import Form, TransactionCase
109

@@ -16,37 +15,23 @@ def setUpClass(cls):
1615
super().setUpClass()
1716
cls.account_obj = cls.env["account.account"]
1817
cls.account_move_obj = cls.env["account.move"]
19-
cls.chart = cls.env["account.chart.template"].search([], limit=1)
20-
if not cls.chart:
21-
raise ValidationError(
22-
# translation to avoid pylint warnings
23-
_("No Chart of Account Template has been defined !")
24-
)
2518

2619
cls.company_a = cls.env["res.company"].create(
2720
{
2821
"name": "Company A",
29-
"currency_id": cls.env.ref("base.EUR").id,
30-
"country_id": cls.env.ref("base.fr").id,
31-
"parent_id": cls.env.ref("base.main_company").id,
3222
"invoice_auto_validation": True,
3323
}
3424
)
35-
cls.chart.try_loading(company=cls.company_a, install_demo=False)
3625
cls.partner_company_a = cls.env["res.partner"].create(
3726
{"name": cls.company_a.name, "is_company": True}
3827
)
3928
cls.company_a.partner_id = cls.partner_company_a
4029
cls.company_b = cls.env["res.company"].create(
4130
{
4231
"name": "Company B",
43-
"currency_id": cls.env.ref("base.EUR").id,
44-
"country_id": cls.env.ref("base.fr").id,
45-
"parent_id": cls.env.ref("base.main_company").id,
4632
"invoice_auto_validation": True,
4733
}
4834
)
49-
cls.chart.try_loading(company=cls.company_b, install_demo=False)
5035
cls.partner_company_b = cls.env["res.partner"].create(
5136
{"name": cls.company_b.name, "is_company": True}
5237
)
@@ -59,7 +44,6 @@ def setUpClass(cls):
5944
}
6045
)
6146
cls.company_b.partner_id = cls.partner_company_b
62-
# cls.partner_company_b = cls.company_b.parent_id.partner_id
6347
cls.user_company_a = cls.env["res.users"].create(
6448
{
6549
"name": "User A",
@@ -332,15 +316,6 @@ def setUpClass(cls):
332316
"company_id": cls.company_a.id,
333317
}
334318
)
335-
cls.pcg_X58 = cls.env["account.account.template"].create(
336-
{
337-
"name": "Internal Transfers",
338-
"code": "X58",
339-
"account_type": "asset_current",
340-
"reconcile": True,
341-
}
342-
)
343-
344319
cls.a_recv_company_a = cls.account_obj.create(
345320
{
346321
"code": "X11002.A",
@@ -363,8 +338,18 @@ def setUpClass(cls):
363338
cls.partner_company_a.property_account_receivable_id = cls.a_recv_company_a.id
364339
cls.partner_company_a.property_account_payable_id = cls.a_pay_company_a.id
365340

366-
cls.partner_company_b.property_account_receivable_id = cls.a_recv_company_b.id
367-
cls.partner_company_b.property_account_payable_id = cls.a_pay_company_b.id
341+
cls.partner_company_b.with_user(
342+
cls.user_company_a.id
343+
).property_account_receivable_id = cls.a_recv_company_a.id
344+
cls.partner_company_b.with_user(
345+
cls.user_company_a.id
346+
).property_account_payable_id = cls.a_pay_company_a.id
347+
cls.partner_company_b.with_user(
348+
cls.user_company_b.id
349+
).property_account_receivable_id = cls.a_recv_company_b.id
350+
cls.partner_company_b.with_user(
351+
cls.user_company_b.id
352+
).property_account_payable_id = cls.a_pay_company_b.id
368353

369354
cls.invoice_company_a = Form(
370355
cls.account_move_obj.with_user(cls.user_company_a.id).with_context(
@@ -373,7 +358,6 @@ def setUpClass(cls):
373358
)
374359
cls.invoice_company_a.partner_id = cls.partner_company_b
375360
cls.invoice_company_a.journal_id = cls.sales_journal_company_a
376-
cls.invoice_company_a.currency_id = cls.env.ref("base.EUR")
377361

378362
with cls.invoice_company_a.invoice_line_ids.new() as line_form:
379363
line_form.product_id = cls.product_consultant_multi_company
@@ -390,7 +374,7 @@ def setUpClass(cls):
390374
cls.product_a = cls.invoice_line_a.product_id
391375
cls.product_a.with_user(
392376
cls.user_company_b.id
393-
).property_account_expense_id = cls.a_expense_company_b.id
377+
).sudo().property_account_expense_id = cls.a_expense_company_b.id
394378

395379

396380
class TestAccountInvoiceInterCompany(TestAccountInvoiceInterCompanyBase):
@@ -415,7 +399,9 @@ def test03_confirm_invoice_and_cancel(self):
415399
# ensure the catalog is shared
416400
self.env.ref("product.product_comp_rule").write({"active": False})
417401
# Make sure there are no taxes in target company for the used product
418-
self.product_a.with_user(self.user_company_b.id).supplier_taxes_id = False
402+
self.product_a.with_user(
403+
self.user_company_b.id
404+
).sudo().supplier_taxes_id = False
419405
# Confirm the invoice of company A
420406
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
421407
# Check destination invoice created in company B
@@ -443,9 +429,9 @@ def test03_confirm_invoice_and_cancel(self):
443429
self.invoice_company_a.invoice_line_ids[0].product_id,
444430
)
445431
# Cancel the invoice of company A
446-
invoice_origin = ("%s - Canceled Invoice: %s") % (
447-
self.invoice_company_a.company_id.name,
448-
self.invoice_company_a.name,
432+
invoice_origin = "{company_name} - Canceled Invoice: {invoice_name}".format(
433+
company_name=self.invoice_company_a.company_id.name,
434+
invoice_name=self.invoice_company_a.name,
449435
)
450436
self.invoice_company_a.with_user(self.user_company_a.id).button_cancel()
451437
# Check invoices after to cancel invoice of company A
@@ -454,6 +440,7 @@ def test03_confirm_invoice_and_cancel(self):
454440
self.assertEqual(invoices[0].invoice_origin, invoice_origin)
455441
# Check if keep the invoice number
456442
invoice_number = self.invoice_company_a.name
443+
self.invoice_company_a.with_user(self.user_company_a.id).button_draft()
457444
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
458445
self.assertEqual(self.invoice_company_a.name, invoice_number)
459446
# When the destination invoice is posted we can't modify the origin either
@@ -484,30 +471,17 @@ def test_confirm_invoice_with_child_partner(self):
484471
)
485472
self.assertEqual(len(invoices), 1)
486473

487-
def test_confirm_invoice_with_product_and_shared_catalog(self):
488-
"""With no security rule, child company have access to any product.
489-
Then child invoice can share the same product
490-
"""
491-
# ensure the catalog is shared even if product is in other company
492-
self.env.ref("product.product_comp_rule").write({"active": False})
493-
# Product is set to a specific company
494-
self.product_a.write({"company_id": self.company_a.id})
495-
invoices = self._confirm_invoice_with_product()
496-
self.assertNotEqual(
497-
invoices.invoice_line_ids[0].product_id, self.env["product.product"]
498-
)
499-
500474
def test_confirm_invoice_with_native_product_rule_and_shared_product(self):
501475
"""With native security rule, products with access in both companies
502476
must be present in parent and child invoices.
503477
"""
504478
# ensure the catalog is shared even if product is in other company
505479
self.env.ref("product.product_comp_rule").write({"active": True})
506480
# Product is set to a specific company
507-
self.product_a.write({"company_id": False})
481+
self.product_a.sudo().write({"company_id": False})
508482
# If product_multi_company is installed
509483
if "company_ids" in dir(self.product_a):
510-
self.product_a.write({"company_ids": [(5, 0, 0)]})
484+
self.product_a.sudo().write({"company_ids": [(5, 0, 0)]})
511485
invoices = self._confirm_invoice_with_product()
512486
self.assertEqual(invoices.invoice_line_ids[0].product_id, self.product_a)
513487

@@ -518,10 +492,10 @@ def test_confirm_invoice_with_native_product_rule_and_unshared_product(self):
518492
# ensure the catalog is shared even if product is in other company
519493
self.env.ref("product.product_comp_rule").write({"active": True})
520494
# Product is set to a specific company
521-
self.product_a.write({"company_id": self.company_a.id})
495+
self.product_a.sudo().write({"company_id": self.company_a.id})
522496
# If product_multi_company is installed
523497
if "company_ids" in dir(self.product_a):
524-
self.product_a.write({"company_ids": [(6, 0, [self.company_a.id])]})
498+
self.product_a.sudo().write({"company_ids": [(6, 0, [self.company_a.id])]})
525499
with self.assertRaises(UserError):
526500
self._confirm_invoice_with_product()
527501

0 commit comments

Comments
 (0)