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 PicchiSeba committed Aug 22, 2024
1 parent 6b75626 commit 47430b3
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 10 deletions.
2 changes: 1 addition & 1 deletion account_invoice_inter_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Configuration

To configure this module, you need to go to the menu *Settings > General Settings*, go to the tab *Multi-Companies* then check *Multi-companies*

You now have access to other checks *Common Product Catalog* and *Invoice Auto Validation*.
You now have access to other checks *Common Product Catalog*, *Generate Intercompany Invoices* and *Invoice Auto Validation*.

To customize products sharing don't hesitate to override `_compute_share_product()` in `res.company` model.

Expand Down
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 @@ -82,6 +82,12 @@ def create_counterpart_invoices(self):
# nor the invoices that were already validated in the past
dest_company = src_invoice._find_company_from_invoice_partner()
if dest_company:
# If one of the involved companies have the intercompany setting disabled, skip
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()
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 @@ -23,6 +23,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 _compute_share_product(self):
product_rule = self.env.ref("product.product_comp_rule")
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 @@ -31,6 +31,16 @@ class ResConfigSettings(models.TransientModel):
"company are visible for all companies.",
)

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,
)

@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
Expand Down
2 changes: 1 addition & 1 deletion account_invoice_inter_company/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
To configure this module, you need to go to the menu *Settings > General Settings*, go to the tab *Multi-Companies* then check *Multi-companies*

You now have access to other checks *Common Product Catalog* and *Invoice Auto Validation*.
You now have access to other checks *Common Product Catalog*, *Generate Intercompany Invoices* and *Invoice Auto Validation*.

To customize products sharing don't hesitate to override `_compute_share_product()` in `res.company` model.
14 changes: 8 additions & 6 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 ([email protected])
: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 @@ -392,7 +392,7 @@ <h1 class="title">Inter Company Invoices</h1>
<div class="section" id="configuration">
<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>Multi-Companies</em> then check <em>Multi-companies</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 checks <em>Common Product Catalog</em>, <em>Generate Intercompany Invoices</em> and <em>Invoice Auto Validation</em>.</p>
<p>To customize products sharing don’t hesitate to override <cite>_compute_share_product()</cite> in <cite>res.company</cite> model.</p>
</div>
<div class="section" id="known-issues-roadmap">
Expand Down Expand Up @@ -458,7 +458,9 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<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
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 @@ -30,6 +30,7 @@ def setUpClass(cls):
"country_id": cls.env.ref("base.fr").id,
"parent_id": cls.env.ref("base.main_company").id,
"invoice_auto_validation": True,
"intercompany_invoicing": True,
}
)
cls.chart.try_loading(cls.company_a)
Expand All @@ -41,6 +42,7 @@ def setUpClass(cls):
"country_id": cls.env.ref("base.fr").id,
"parent_id": cls.env.ref("base.main_company").id,
"invoice_auto_validation": True,
"intercompany_invoicing": True,
}
)
cls.chart.try_loading(cls.company_b)
Expand Down Expand Up @@ -627,3 +629,16 @@ def test_confirm_invoice_and_full_refund(self):
[("auto_invoice_id", "=", refund_company_a.id)]
)
self.assertEqual(len(refund), 1)

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 @@ -33,7 +33,18 @@
<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">
<div id="intercompany_invoicing">
<field name="intercompany_invoicing" class="oe_inline" />
<label
string="Generate Intercompany Invoices"
class="o_light_label"
for="intercompany_invoicing"
/>
</div>
<div
id="intercompany_invoice_user"
attrs="{'invisible': [('intercompany_invoicing', '=', False)]}"
>
<label
string="Intercompany user for invoices"
class="o_light_label"
Expand All @@ -44,7 +55,10 @@
class="oe_inline"
/>
</div>
<div id="inter_company_invoice_validation">
<div
id="inter_company_invoice_validation"
attrs="{'invisible': [('intercompany_invoicing', '=', False)]}"
>
<field name="invoice_auto_validation" class="oe_inline" />
<label
string="Invoice Auto Validation"
Expand Down

0 comments on commit 47430b3

Please sign in to comment.