Skip to content

Commit

Permalink
[FIX] partner_multi_company: default value for res_partner.company_ids
Browse files Browse the repository at this point in the history
  • Loading branch information
PicchiSeba committed Jan 29, 2024
1 parent 76f417c commit 014fc22
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 7 deletions.
21 changes: 19 additions & 2 deletions partner_multi_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Partner multi-company
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5b2902a5fe7f224a45ee38f48edd1595f5b6f665391f0a81ee50038f1a3074cb
!! source digest: sha256:8dcbd423986cb532c57346eb10cf08ef4ecffbb309a88cfcadf973a5ab905675
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -49,7 +49,10 @@ Usage

On the partner form view, go to the "Sales & Purchases" tab, and put the
companies in which you want to use that partner. If none is selected, the
partner will be visible in all of them. The default value is the current one.
partner will be visible in all of them.

Selecting the option "**Set Active Company Partner**" in the settings
page, will make the default value will be the current company.

Known issues / Roadmap
======================
Expand Down Expand Up @@ -103,6 +106,20 @@ 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.

.. |maintainer-aleuffre| image:: https://github.com/aleuffre.png?size=40px
:target: https://github.com/aleuffre
:alt: aleuffre
.. |maintainer-PicchiSeba| image:: https://github.com/PicchiSeba.png?size=40px
:target: https://github.com/PicchiSeba
:alt: PicchiSeba
.. |maintainer-renda-dev| image:: https://github.com/renda-dev.png?size=40px
:target: https://github.com/renda-dev
:alt: renda-dev

Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-aleuffre| |maintainer-PicchiSeba| |maintainer-renda-dev|

This module is part of the `OCA/multi-company <https://github.com/OCA/multi-company/tree/14.0/partner_multi_company>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
12 changes: 10 additions & 2 deletions partner_multi_company/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
"summary": "Select individually the partner visibility on each company",
"version": "14.0.1.0.1",
"license": "AGPL-3",
"depends": ["base_multi_company"],
"depends": ["base_multi_company", "base_setup"],
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/multi-company",
"category": "Partner Management",
"data": ["views/res_partner_view.xml"],
"data": [
"views/res_config_settings.xml",
"views/res_partner_view.xml",
],
"maintainers": [
"aleuffre",
"PicchiSeba",
"renda-dev",
],
"installable": True,
"post_init_hook": "post_init_hook",
"uninstall_hook": "uninstall_hook",
Expand Down
2 changes: 2 additions & 0 deletions partner_multi_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from . import res_company
from . import res_config_settings
from . import res_partner
from . import res_users
9 changes: 9 additions & 0 deletions partner_multi_company/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

set_active_company_partner = fields.Boolean(
"Set Active Company Partner", default=False
)
11 changes: 11 additions & 0 deletions partner_multi_company/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from odoo import fields, models


class ResConfigSettings(models.TransientModel):
_inherit = "res.config.settings"

set_active_company_partner = fields.Boolean(
string="Set Active Company Partner",
related="company_id.set_active_company_partner",
readonly=False,
)
5 changes: 5 additions & 0 deletions partner_multi_company/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class ResPartner(models.Model):
store=True,
index=True,
)
company_ids = fields.Many2many(
default=lambda self: [(6, 0, [self.env.company.id])]
if self.env.company.set_active_company_partner
else [(6, 0, [])]
)

@api.model
def create(self, vals):
Expand Down
5 changes: 4 additions & 1 deletion partner_multi_company/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
On the partner form view, go to the "Sales & Purchases" tab, and put the
companies in which you want to use that partner. If none is selected, the
partner will be visible in all of them. The default value is the current one.
partner will be visible in all of them.

Selecting the option "**Set Active Company Partner**" in the settings
page, will make the default value will be the current company.
8 changes: 6 additions & 2 deletions partner_multi_company/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Partner multi-company</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:5b2902a5fe7f224a45ee38f48edd1595f5b6f665391f0a81ee50038f1a3074cb
!! source digest: sha256:8dcbd423986cb532c57346eb10cf08ef4ecffbb309a88cfcadf973a5ab905675
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/multi-company/tree/14.0/partner_multi_company"><img alt="OCA/multi-company" src="https://img.shields.io/badge/github-OCA%2Fmulti--company-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/multi-company-14-0/multi-company-14-0-partner_multi_company"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/multi-company&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This modules allows to select in which of the companies you want to use each
Expand Down Expand Up @@ -398,7 +398,9 @@ <h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
<h1><a class="toc-backref" href="#toc-entry-2">Usage</a></h1>
<p>On the partner form view, go to the “Sales &amp; Purchases” tab, and put the
companies in which you want to use that partner. If none is selected, the
partner will be visible in all of them. The default value is the current one.</p>
partner will be visible in all of them.</p>
<p>Selecting the option “<strong>Set Active Company Partner</strong>” in the settings
page, will make the default value will be the current company.</p>
</div>
<div class="section" id="known-issues-roadmap">
<h1><a class="toc-backref" href="#toc-entry-3">Known issues / Roadmap</a></h1>
Expand Down Expand Up @@ -446,6 +448,8 @@ <h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<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>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainers</a>:</p>
<p><a class="reference external image-reference" href="https://github.com/aleuffre"><img alt="aleuffre" src="https://github.com/aleuffre.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/PicchiSeba"><img alt="PicchiSeba" src="https://github.com/PicchiSeba.png?size=40px" /></a> <a class="reference external image-reference" href="https://github.com/renda-dev"><img alt="renda-dev" src="https://github.com/renda-dev.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/multi-company/tree/14.0/partner_multi_company">OCA/multi-company</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
Expand Down
79 changes: 79 additions & 0 deletions partner_multi_company/tests/test_partner_multi_company.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ def setUp(self):
)
self.company_1 = self.env["res.company"].create({"name": "Test company 1"})
self.company_2 = self.env["res.company"].create({"name": "Test company 2"})

self.is_account_module_installed = bool(
self.env["ir.module.module"].search(
[
("name", "=", "account"),
("state", "=", "installed"),
]
)
)

self.partner_company_none = self.partner_model.create(
{"name": "partner without company", "company_ids": False}
)
Expand Down Expand Up @@ -167,3 +177,72 @@ def test_avoid_updating_company_ids_in_global_partners(self):
user_partner.write({"company_id": False, "company_ids": [(5, False)]})
self.user_company_1.write({"company_id": self.company_2.id})
self.assertEqual(user_partner.company_ids.ids, [])

def test_partner_default_company_ids(self):
view = self.env.ref("base.view_partner_form")
self.company_2.set_active_company_partner = True

Form1 = common.Form(
self.partner_model.with_user(self.user_company_1), view=view
)
Form1.name = "Test partner 1"

Form2 = common.Form(
self.partner_model.with_user(self.user_company_2), view=view
)
Form2.name = "Test partner 2"

if self.is_account_module_installed:
account_type = self.env["account.account.type"].create(
{
"name": "test account type",
"type": "other",
"internal_group": "off_balance",
}
)

account_receivable_1 = self.env["account.account"].create(
{
"name": "Test account 1 Rec",
"code": "001R",
"user_type_id": account_type.id,
"company_id": self.company_1.id,
}
)
account_payable_1 = self.env["account.account"].create(
{
"name": "Test account 1 Pay",
"code": "001P",
"user_type_id": account_type.id,
"company_id": self.company_1.id,
}
)
Form1.property_account_receivable_id = account_receivable_1
Form1.property_account_payable_id = account_payable_1

account_receivable_2 = self.env["account.account"].create(
{
"name": "Test account 2",
"code": "002R",
"user_type_id": account_type.id,
"company_id": self.company_2.id,
}
)
account_payable_2 = self.env["account.account"].create(
{
"name": "Test account 2 Pay",
"code": "002P",
"user_type_id": account_type.id,
"company_id": self.company_2.id,
}
)
Form2.property_account_receivable_id = account_receivable_2
Form2.property_account_payable_id = account_payable_2

partner_1 = Form1.save()
partner_2 = Form2.save()

self.assertFalse(self.company_1.set_active_company_partner)
self.assertFalse(partner_1.company_ids)
self.assertTrue(self.company_2.set_active_company_partner)
self.assertEqual(partner_2.company_ids, self.company_2)
29 changes: 29 additions & 0 deletions partner_multi_company/views/res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">account settings </field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="base.res_config_settings_view_form" />
<field name="arch" type="xml">
<div id="inter_company" position="after">
<div
class="col-xs-12 col-md-6 o_setting_box"
id="active_company_partner"
>
<div class="o_setting_left_pane">
<field name="set_active_company_partner" />
</div>
<div
class="o_setting_right_pane"
id="active_company_partner_settings"
>
<label for="set_active_company_partner" />
<div class="text-muted">
Set active company in partner's companies on create
</div>
</div>
</div>
</div>
</field>
</record>
</odoo>

0 comments on commit 014fc22

Please sign in to comment.