Skip to content

Commit 1b1a300

Browse files
MarinaAForgeFlowHviorForgeFlow
authored andcommitted
[IMP] account_invoice_inter_company: add setting to disable or enable intercompany invoicing
This commit adds a new setting called intercompany_invoicing that allows the user to activate or deactivate the intercompany invoicing. When positing an intercompany invoice, if one of the companies have the setting disabled, the other invoice will not be automatically created.
1 parent 01f1a49 commit 1b1a300

File tree

5 files changed

+51
-1
lines changed

5 files changed

+51
-1
lines changed

Diff for: account_invoice_inter_company/models/account_move.py

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ def action_post(self):
5050
dest_company = src_invoice._find_company_from_invoice_partner()
5151
if not dest_company or src_invoice.auto_generated:
5252
continue
53+
# Skip if one of the involved companies have intercompany setting disabled
54+
if (
55+
not dest_company.intercompany_invoicing
56+
or not src_invoice.company_id.intercompany_invoicing
57+
):
58+
continue
5359
intercompany_user = dest_company.intercompany_invoice_user_id
5460
if intercompany_user:
5561
src_invoice = src_invoice.with_user(intercompany_user).sudo()

Diff for: account_invoice_inter_company/models/res_company.py

+8
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class ResCompany(models.Model):
1717
help="Responsible user for creation of invoices triggered by "
1818
"intercompany rules.",
1919
)
20+
intercompany_invoicing = fields.Boolean(
21+
string="Generate Inter company Invoices",
22+
help="Enable intercompany invoicing: "
23+
"\n* Generate a Customer Invoice when a bill with this company is created."
24+
"\n* Generate a Vendor Bill when an invoice with this company as a customer"
25+
" is created.",
26+
default=True,
27+
)
2028

2129
def _get_user_domain(self):
2230
self.ensure_one()

Diff for: account_invoice_inter_company/models/res_config_settings.py

+10
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,13 @@ class ResConfigSettings(models.TransientModel):
2020
"intercompany rules. If not set the user initiating the"
2121
"transaction will be used",
2222
)
23+
24+
intercompany_invoicing = fields.Boolean(
25+
string="Generate Inter company Invoices",
26+
related="company_id.intercompany_invoicing",
27+
help="Enable intercompany invoicing: "
28+
"\n * Generate a Customer Invoice when a bill with this company is created."
29+
"\n * Generate a Vendor Bill when an invoice with this company as a customer"
30+
" is created.",
31+
readonly=False,
32+
)

Diff for: account_invoice_inter_company/tests/test_inter_company_invoice.py

+15
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def setUpClass(cls):
2020
{
2121
"name": "Company A",
2222
"invoice_auto_validation": True,
23+
"intercompany_invoicing": True,
2324
}
2425
)
2526
cls.partner_company_a = cls.env["res.partner"].create(
@@ -30,6 +31,7 @@ def setUpClass(cls):
3031
{
3132
"name": "Company B",
3233
"invoice_auto_validation": True,
34+
"intercompany_invoicing": True,
3335
}
3436
)
3537
cls.partner_company_b = cls.env["res.partner"].create(
@@ -412,3 +414,16 @@ def _confirm_invoice_with_product(self):
412414
)
413415
self.assertEqual(len(invoices), 1)
414416
return invoices
417+
418+
def test_confirm_invoice_intercompany_disabled(self):
419+
# ensure the catalog is shared
420+
self.env.ref("product.product_comp_rule").write({"active": False})
421+
# Disable the configuration in company A
422+
self.company_a.intercompany_invoicing = False
423+
# Confirm the invoice of company A
424+
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
425+
# Check that no destination invoice has been created in company B
426+
invoices = self.account_move_obj.with_user(self.user_company_b.id).search(
427+
[("auto_invoice_id", "=", self.invoice_company_a.id)]
428+
)
429+
self.assertFalse(invoices)

Diff for: account_invoice_inter_company/views/res_config_settings_view.xml

+12-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,18 @@
1717
>
1818
<div class="text-decoration-underline mt8 mb8">Invoice</div>
1919
<div class="content-group" string="Invoice">
20-
<div>
20+
<div id="intercompany_invoicing">
21+
<label
22+
for="intercompany_invoicing"
23+
string="Generate Intercompany Invoices"
24+
class="o_light_label mr8"
25+
/>
26+
<field name="intercompany_invoicing" class="oe_inline" />
27+
</div>
28+
<div
29+
id="intercompany_invoice_user_id"
30+
invisible="not intercompany_invoicing"
31+
>
2132
<label
2233
for="intercompany_invoice_user_id"
2334
string="Invoices User"

0 commit comments

Comments
 (0)