Skip to content

Commit

Permalink
[IMP] account_invoice_inter_company: add setting to disable or enable…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
MarinaAForgeFlow authored and HviorForgeFlow committed Jan 22, 2025
1 parent 01f1a49 commit a57e342
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 2 deletions.
6 changes: 6 additions & 0 deletions account_invoice_inter_company/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def action_post(self):
dest_company = src_invoice._find_company_from_invoice_partner()
if not dest_company or src_invoice.auto_generated:
continue
# Skip if one of the involved companies have intercompany setting disabled
if (
not dest_company.intercompany_invoicing
or not src_invoice.company_id.intercompany_invoicing
):
continue
intercompany_user = dest_company.intercompany_invoice_user_id
if intercompany_user:
src_invoice = src_invoice.with_user(intercompany_user).sudo()

Check warning on line 61 in account_invoice_inter_company/models/account_move.py

View check run for this annotation

Codecov / codecov/patch

account_invoice_inter_company/models/account_move.py#L61

Added line #L61 was not covered by tests
Expand Down
8 changes: 8 additions & 0 deletions account_invoice_inter_company/models/res_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ class ResCompany(models.Model):
help="Responsible user for creation of invoices triggered by "
"intercompany rules.",
)
intercompany_invoicing = fields.Boolean(
string="Generate Inter company Invoices",
help="Enable intercompany invoicing: "
"\n* Generate a Customer Invoice when a bill with this company is created."
"\n* Generate a Vendor Bill when an invoice with this company as a customer"
" is created.",
default=True,
)

def _get_user_domain(self):
self.ensure_one()
Expand Down
10 changes: 10 additions & 0 deletions account_invoice_inter_company/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ class ResConfigSettings(models.TransientModel):
"intercompany rules. If not set the user initiating the"
"transaction will be used",
)

intercompany_invoicing = fields.Boolean(
string="Generate Inter company Invoices",
related="company_id.intercompany_invoicing",
help="Enable intercompany invoicing: "
"\n * Generate a Customer Invoice when a bill with this company is created."
"\n * Generate a Vendor Bill when an invoice with this company as a customer"
" is created.",
readonly=False,
)
15 changes: 15 additions & 0 deletions account_invoice_inter_company/tests/test_inter_company_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def setUpClass(cls):
{
"name": "Company A",
"invoice_auto_validation": True,
"intercompany_invoicing": True,
}
)
cls.partner_company_a = cls.env["res.partner"].create(
Expand All @@ -30,6 +31,7 @@ def setUpClass(cls):
{
"name": "Company B",
"invoice_auto_validation": True,
"intercompany_invoicing": True,
}
)
cls.partner_company_b = cls.env["res.partner"].create(
Expand Down Expand Up @@ -412,3 +414,16 @@ def _confirm_invoice_with_product(self):
)
self.assertEqual(len(invoices), 1)
return invoices

def test_confirm_invoice_intercompany_disabled(self):
# ensure the catalog is shared
self.env.ref("product.product_comp_rule").write({"active": False})
# Disable the configuration in company A
self.company_a.intercompany_invoicing = False
# Confirm the invoice of company A
self.invoice_company_a.with_user(self.user_company_a.id).action_post()
# Check that no destination invoice has been created in company B
invoices = self.account_move_obj.with_user(self.user_company_b.id).search(
[("auto_invoice_id", "=", self.invoice_company_a.id)]
)
self.assertFalse(invoices)
18 changes: 16 additions & 2 deletions account_invoice_inter_company/views/res_config_settings_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@
>
<div class="text-decoration-underline mt8 mb8">Invoice</div>
<div class="content-group" string="Invoice">
<div>
<div id="intercompany_invoicing">
<label
for="intercompany_invoicing"
string="Generate Intercompany Invoices"
class="o_light_label mr8"
/>
<field name="intercompany_invoicing" class="oe_inline" />
</div>
<div
id="intercompany_invoice_user_id"
invisible="not intercompany_invoicing"
>
<label
for="intercompany_invoice_user_id"
string="Invoices User"
Expand All @@ -28,7 +39,10 @@
class="oe_inline"
/>
</div>
<div>
<div
id="intercompany_invoice_auto_validation"
invisible="not intercompany_invoicing"
>
<label
for="invoice_auto_validation"
class="o_light_label mr8"
Expand Down

0 comments on commit a57e342

Please sign in to comment.