Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][IMP] account_invoice_inter_company: add setting to disable or enable… #684

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion account_invoice_inter_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ 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* (if two companies don't have both flags "Generate Intercompany Invoices" enabled, there's no invoice or bill creation between them)
- *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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition should be only for dest_company. You may want to do invoices from A to B, but not from B to A.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza was this overlooked when original PR #631 was merged in v16 or is there another reason for changing it in v14?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An overlook, sorry. It should be changed also in 16.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedrobaeza I think functionally it's a bit unclear with current documentation, is this the behavior you'd like to achieve?

With "Generate Intercompany Invoices" enabled for both Company 1 and Company 2:

Customer invoice from C1 to C2 generates vendor bill from C2 to C1
Customer invoice from C2 to C1 generates vendor bill from C1 to C2
Vendor bill from C1 to C2 generates customer invoice from C1 to C2
Vendor bill from C1 to C2 generates customer invoice from C1 to C2

With "Generate Intercompany Invoices" enabled for C1 but not for Company 2:

Customer invoice from C1 to C2 generates vendor bill from C2 to C1
Vendor bill from C1 to C2 generates customer invoice from C1 to C2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK, vendor bills don't generate customer invoices, no matter these checks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to DESCRIPTION file it should:

Imagine you have company A and company B in the same Odoo database.

First scenario: company B create an invoice with company A as customer. The module will automate the generation of the supplier invoice in company A.

Second scenario: company A create an invoice with company B as supplier. The module will automate the generation of the customer invoice in company B.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, that's not correct IMO. Only one side should generate the document for the other side. If not, you may have duplicated things. It's the same as sale/purchase. The purchase order generates the sales order, not the reverse.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the current documentation is valid, correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know right now, as you have touched a lot 14.0 version, but the original intention when this module was forked in 9.0 wasn't the bi-directional creation IIRC.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know right now, as you have touched a lot 14.0 version, but the original intention when this module was forked in 9.0 wasn't the bi-directional creation IIRC.

As far as I can see the feature has been the same since v12 (2019) and from what I've tested it works as described (with several caveats)

That said, I don't agree with this behavior:

With "Generate Intercompany Invoices" enabled for both Company 1 and Company 2:

Customer invoice from C1 to C2 generates vendor bill from C2 to C1
Customer invoice from C2 to C1 generates vendor bill from C1 to C2
Vendor bill from C1 to C2 generates customer invoice from C1 to C2
Vendor bill from C1 to C2 generates customer invoice from C1 to C2

With "Generate Intercompany Invoices" enabled for C1 but not for Company 2:

Customer invoice from C1 to C2 generates vendor bill from C2 to C1
Vendor bill from C1 to C2 generates customer invoice from C1 to C2

As the use case I need to address is "I want to prevent C1 from generating invoices for C2, but I want C1 to generate invoices to C3" as we're in a multi-company environment where C2 is not ready for receiving invoices.

So this PR's behavior (and that of the merged one in 16) looks correct to me, if both companies don't have flag enabled there's no invoice/bill creation.

For a more complete implementation, the boolean could be changed to a select with options:

  • Disable intercompany invoice/bills creation
  • Only create invoices from intercompany bills
  • Only create bills from intercompany invoices
  • Create both bills and invoices from other companies

So as to accommodate all use cases. But this can be done in a later PR with a migration.

I would anyway improve description specifying "if two companies don't have both flag "Generate Intercompany Invoices" enabled, there's no invoice or bill creation between them."

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
6 changes: 5 additions & 1 deletion account_invoice_inter_company/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
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* (if two companies don't have both flags "Generate Intercompany Invoices" enabled, there's no invoice or bill creation between them)
- *Invoice Auto Validation*

To customize products sharing don't hesitate to override `_compute_share_product()` in `res.company` model.
19 changes: 13 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,12 @@ <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:</p>
<ul class="simple">
<li><em>Common Product Catalog</em></li>
<li><em>Generate Intercompany Invoices</em> (if two companies don’t have both flags “Generate Intercompany Invoices” enabled, there’s no invoice or bill creation between them)</li>
<li><em>Invoice Auto Validation</em></li>
</ul>
<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 +463,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
Loading