Skip to content

Commit

Permalink
Merge 6bf7f73 into 3a6aa2f
Browse files Browse the repository at this point in the history
  • Loading branch information
nikul-serpentcs committed Dec 24, 2019
2 parents 3a6aa2f + 6bf7f73 commit 81f3c80
Show file tree
Hide file tree
Showing 15 changed files with 219 additions and 0 deletions.
2 changes: 2 additions & 0 deletions agreement_operating_unit/__init__.py
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import models
30 changes: 30 additions & 0 deletions agreement_operating_unit/__manifest__.py
@@ -0,0 +1,30 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
{
"name": 'Agreement with Operating Units',
"summary": """
This module adds operating unit information to agreements and service
profiles.""",
"version": "12.0.1.0.0",
"author": "Open Source Integrators, "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/operating-unit",
"category": "Agreement",
"depends": [
'operating_unit',
'agreement_serviceprofile'
],
"license": "AGPL-3",
"data": [
'security/aggreement_security.xml',
'views/agreement.xml',
'views/agreement_serviceprofile.xml',
],
'installable': True,
'development_status': 'Beta',
'maintainers': [
'max3903',
],
}
3 changes: 3 additions & 0 deletions agreement_operating_unit/models/__init__.py
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import agreement
from . import agreement_serviceprofile
15 changes: 15 additions & 0 deletions agreement_operating_unit/models/agreement.py
@@ -0,0 +1,15 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class Agreement(models.Model):
_inherit = 'agreement'

operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Operating Unit',
default=lambda self: self.env['res.users'].operating_unit_default_get(
self._uid)
)
16 changes: 16 additions & 0 deletions agreement_operating_unit/models/agreement_serviceprofile.py
@@ -0,0 +1,16 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import fields, models


class AgreementServiceprofile(models.Model):
_inherit = 'agreement.serviceprofile'

operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
related='agreement_id.operating_unit_id',
string='Operating Unit',
default=lambda self: self.env['res.users'].operating_unit_default_get(
self._uid)
)
2 changes: 2 additions & 0 deletions agreement_operating_unit/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
* Nikul Chaudhary <nikul.chaudhary.serpentcs@gmail.com>
* Maxime Chambreuil <mchambreuil@opensourceintegrators.com>
2 changes: 2 additions & 0 deletions agreement_operating_unit/readme/CREDITS.rst
@@ -0,0 +1,2 @@
* Open Source Integrators
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
1 change: 1 addition & 0 deletions agreement_operating_unit/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
This module adds operating unit information to agreements and service profiles.
3 changes: 3 additions & 0 deletions agreement_operating_unit/readme/USAGE.rst
@@ -0,0 +1,3 @@
* Go to Agreements
* You only see the agreements of your operating units
* Create an agreement. It is assigned to your default operating unit.
31 changes: 31 additions & 0 deletions agreement_operating_unit/security/aggreement_security.xml
@@ -0,0 +1,31 @@
<odoo>

<!-- Copyright (C) 2019 Open Source Integrators
Copyright (C) 2019 Serpent Consulting Services
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<record id="ir_rule_agreement_operating_unit" model="ir.rule">
<field name="model_id" ref="agreement.model_agreement"/>
<field name="domain_force">['|', ('operating_unit_id','=',False), ('operating_unit_id','in',user.operating_unit_ids.ids)]
</field>
<field name="name">Agreement Operating Unit</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>

<record id="ir_rule_agreement_serviceprofile_operating_unit" model="ir.rule">
<field name="model_id" ref="agreement_serviceprofile.model_agreement_serviceprofile"/>
<field name="domain_force">['|', ('operating_unit_id','=',False), ('operating_unit_id','in',user.operating_unit_ids.ids)]
</field>
<field name="name">Agreement Serviceprofile Operating Unit</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>
2 changes: 2 additions & 0 deletions agreement_operating_unit/tests/__init__.py
@@ -0,0 +1,2 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from . import test_agreement_operating_unit
75 changes: 75 additions & 0 deletions agreement_operating_unit/tests/test_agreement_operating_unit.py
@@ -0,0 +1,75 @@
# Copyright (C) 2019 Open Source Integrators
# Copyright (C) 2019 Serpent Consulting Services
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo.tests import common


class TestAgreementOperatingUnit(common.TransactionCase):

def setUp(self):
super(TestAgreementOperatingUnit, self).setUp()
self.agreement_obj = self.env['agreement']
self.serviceprofile_obj = self.env['agreement.serviceprofile']
self.res_users_model = self.env['res.users']
self.product_id = self.env['product.template'
].search([('type', '=', 'service')], limit=1)

# Groups
self.grp_user = self.env.ref('base.group_user')
# Company
self.company = self.env.ref('base.main_company')
# Main Operating Unit
self.main_OU = self.env.ref('operating_unit.main_operating_unit')
# B2C Operating Unit
self.b2c_OU = self.env.ref('operating_unit.b2c_operating_unit')
# Create User 1 with Main OU
self.user1 = self._create_user('user_1', [self.grp_user],
self.company, [self.main_OU])
# Create User 2 with B2C OU
self.user2 = self._create_user('user_2', [self.grp_user],
self.company, [self.b2c_OU])

self.agreement1 = self._create_agreement(self.user1.id, self.main_OU)
self.agreement2 = self._create_agreement(self.user2.id, self.b2c_OU)

def _create_user(self, login, groups, company, operating_units):
""" Create a user. """
group_ids = [group.id for group in groups]
user = self.res_users_model.create({
'name': login,
'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],
'groups_id': [(6, 0, group_ids)]
})
return user

def _create_agreement(self, uid, operating_unit):
agreement = self.agreement_obj.sudo(uid).create({
'code': 'DA',
'name': 'Demo Agreement',
'operating_unit_id': operating_unit.id,
})
return agreement

def test_agreement(self):
# User 2 is only assigned to B2C Operating Unit, and cannot
# access Agreement for Main Operating Unit.
agreement_ids = self.agreement_obj.sudo(self.user2.id).search(
[('id', '=', self.agreement2.id),
('operating_unit_id', '=', self.main_OU.id)])
self.assertEqual(agreement_ids.ids, [], 'User 2 should not have access '
'to %s' % self.main_OU.name)
self.assertEqual(self.agreement1.operating_unit_id.id, self.main_OU.id)

def test_agreement_serviceprofile(self):
serviceprofile_id = self.serviceprofile_obj.create({
'name': 'Test Agreement Serviceprofile',
'agreement_id': self.agreement1.id,
'product_id': self.product_id.id
})
self.assertEqual(serviceprofile_id.agreement_id.operating_unit_id,
self.main_OU)
18 changes: 18 additions & 0 deletions agreement_operating_unit/views/agreement.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Copyright (C) 2019 Open Source Integrators
Copyright (C) 2019 Serpent Consulting Services
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<record id="view_agreement_form_inherit" model="ir.ui.view">
<field name="name">agreement.form</field>
<field name="model">agreement</field>
<field name="inherit_id" ref="agreement.agreement_form"/>
<field name="arch" type="xml">
<field name="partner_id" position="after">
<field name="operating_unit_id"/>
</field>
</field>
</record>

</odoo>
18 changes: 18 additions & 0 deletions agreement_operating_unit/views/agreement_serviceprofile.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Copyright (C) 2019 Open Source Integrators
Copyright (C) 2019 Serpent Consulting Services
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<record id="view_agreement_serviceprofile_form_inherit" model="ir.ui.view">
<field name="name">Agreement Service Profile Form</field>
<field name="model">agreement.serviceprofile</field>
<field name="inherit_id" ref="agreement_serviceprofile.agreement_serviceprofile_form"/>
<field name="arch" type="xml">
<field name="agreement_id" position="after">
<field name="operating_unit_id"/>
</field>
</field>
</record>

</odoo>
1 change: 1 addition & 0 deletions oca_dependencies.txt
@@ -1,3 +1,4 @@
# list the OCA project dependencies, one per line
# add a github url if you need a forked version
purchase-workflow
contract

0 comments on commit 81f3c80

Please sign in to comment.