Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# © 2017 Niaga Solution - Edi Santoso <repodevs@gmail.com> | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
{ | ||
"name": "Partner with Operating Unit", | ||
"summary": "Introduces Operating Unit fields in Partner", | ||
"version": "12.0.1.0.0", | ||
"author": "Edi Santoso, " | ||
"Niaga Solution, " | ||
"Odoo Community Association (OCA)", | ||
"website": "https://github.com/OCA/operating-unit", | ||
"category": "Generic", | ||
"depends": ["operating_unit"], | ||
"license": "LGPL-3", | ||
"data": [ | ||
"security/res_partner_security.xml", | ||
"views/res_partner_view.xml", | ||
], | ||
'installable': True, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from . import res_partner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# © 2017 Niaga Solution - Edi Santoso <repodevs@gmail.com> | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from odoo import api, fields, models | ||
|
||
|
||
class ResPartner(models.Model): | ||
|
||
_inherit = 'res.partner' | ||
|
||
@api.model | ||
def operating_unit_default_get(self, uid2=False): | ||
if not uid2: | ||
uid2 = self._uid | ||
user = self.env['res.users'].browse(uid2) | ||
return user.default_operating_unit_id | ||
|
||
@api.model | ||
def _default_operating_unit(self): | ||
return self.operating_unit_default_get() | ||
|
||
@api.model | ||
def _default_operating_units(self): | ||
return self._default_operating_unit() | ||
|
||
operating_unit_ids = fields.Many2many( | ||
'operating.unit', 'operating_unit_partner_rel', | ||
'partner_id', 'operating_unit_id', | ||
'Operating Units', default=lambda self: self._default_operating_units() | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* Edi Santoso <repodevs@gmail.com> | ||
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com> | ||
* Hiren Dangar <hiren.dangar.serpentcs@gmail.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* Niaga Solution | ||
* Open Source Integrators | ||
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
This module introduces the following features: | ||
|
||
* Adds the Operating Unit (OU) to res partner. | ||
* The user’s default Operating Unit (OU) is proposed at the time of creating Partner. | ||
* Security rules are defined to ensure that users can only see Partner of that Operating Units in which they are allowed access to. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* Go to customer | ||
* You only see the customer of your operating units | ||
* Create an customer. It is assigned to your default operating unit. |
19 changes: 19 additions & 0 deletions
19
res_partner_operating_unit/security/res_partner_security.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<odoo noupdate="1"> | ||
|
||
<!-- Copyright 2017 Niaga Solution - Edi Santoso <repodevs@gmail.com> | ||
Copyright (C) 2019 Serpent Consulting Services | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) --> | ||
|
||
<record id="ir_rule_res_partner_allowed_operating_units" | ||
model="ir.rule"> | ||
<field name="model_id" ref="base.model_res_partner"/> | ||
<field name="domain_force">['|',('operating_unit_ids','=',False),('operating_unit_ids','in',[g.id for g in user.operating_unit_ids])]</field> | ||
<field name="name">Partner from allowed operating units</field> | ||
<field name="global" eval="True"/> | ||
<field eval="0" name="perm_unlink"/> | ||
<field eval="0" name="perm_write"/> | ||
<field eval="1" name="perm_read"/> | ||
<field eval="0" name="perm_create"/> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from . import test_res_partner_operating_unit |
51 changes: 51 additions & 0 deletions
51
res_partner_operating_unit/tests/test_res_partner_operating_unit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# © 2017 Niaga Solution - Edi Santoso <repodevs@gmail.com> | ||
# Copyright (C) 2019 Serpent Consulting Services | ||
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html). | ||
from odoo.tests import common | ||
|
||
|
||
class TestResPartnerOperatingUnit(common.TransactionCase): | ||
|
||
def setUp(self): | ||
super(TestResPartnerOperatingUnit, self).setUp() | ||
self.res_partner_model = self.env['res.partner'] | ||
self.res_users_model = self.env['res.users'] | ||
# Company | ||
self.company = self.env.ref('base.main_company') | ||
# Main Operating Unit | ||
self.ou1 = self.env.ref('operating_unit.main_operating_unit') | ||
# B2C Operating Unit | ||
self.b2c = self.env.ref('operating_unit.b2c_operating_unit') | ||
|
||
# Create User 1 with Main OU | ||
self.user1 = self._create_user('user_1', self.company, [self.ou1]) | ||
# Create User 2 with B2C OU | ||
self.user2 = self._create_user('user_2', self.company, [self.b2c]) | ||
|
||
# Create Partner 1 with Main OU | ||
self.partner1 = self._create_partner('Test Partner 1', self.ou1) | ||
|
||
# Create Partner 2 with B2C OU | ||
self.partner2 = self._create_partner('Test Partner 2', self.b2c) | ||
|
||
def _create_partner(self, name, operating_unit, context=None): | ||
""" Create a partner. """ | ||
partner = self.res_partner_model.create({ | ||
'name': name, | ||
'operating_unit_id': operating_unit.id, | ||
}) | ||
return partner | ||
|
||
def _create_user(self, login, company, operating_units, | ||
context=None): | ||
""" Create a user. """ | ||
user = self.res_users_model.create({ | ||
'name': 'Test User', | ||
'login': login, | ||
'password': 'demo', | ||
'email': 'test@yourcompany.com', | ||
'company_id': company.id, | ||
'company_ids': [(4, company.id)], | ||
'operating_unit_ids': [(4, ou.id) for ou in operating_units], | ||
}) | ||
return user |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<odoo> | ||
<!-- Copyright 2017 Niaga Solution - Edi Santoso <repodevs@gmail.com> | ||
Copyright (C) 2019 Serpent Consulting Services | ||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) --> | ||
|
||
<!-- Partner Form View --> | ||
<record model="ir.ui.view" id="view_partner_form"> | ||
<field name="name">res.partner.form</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_form"/> | ||
<field name="arch" type="xml"> | ||
<field name="category_id" position="after"> | ||
<field name="operating_unit_ids" groups="operating_unit.group_multi_operating_unit" domain = "[('company_id','=', company_id)]" options="{'no_create': True}"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<!-- Partner Tree View --> | ||
<record model="ir.ui.view" id="view_partner_tree"> | ||
<field name="name">res.partner.tree</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_partner_tree"/> | ||
<field name="arch" type="xml"> | ||
<field name="email" position="after"> | ||
<field name="operating_unit_ids" groups="operating_unit.group_multi_operating_unit"/> | ||
</field> | ||
</field> | ||
</record> | ||
|
||
<!-- Partner Search View --> | ||
<record id="view_res_partner_filter" model="ir.ui.view"> | ||
<field name="name">res.partner.select</field> | ||
<field name="model">res.partner</field> | ||
<field name="inherit_id" ref="base.view_res_partner_filter"/> | ||
<field name="arch" type="xml"> | ||
<field name="user_id" position="after"> | ||
<field name="operating_unit_ids" groups="operating_unit.group_multi_operating_unit"/> | ||
</field> | ||
</field> | ||
</record> | ||
</odoo> |