[ADD] rma_operating_unit

This commit is contained in:
aheficent
2017-08-03 18:13:44 +02:00
committed by Aaron ForgeFlow
parent 186fe929a0
commit 3eeaa50707
9 changed files with 248 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
.. image:: https://img.shields.io/badge/license-LGPLv3-blue.svg
:target: https://www.gnu.org/licenses/lgpl.html
:alt: License: LGPL-3
==============================
RMA with Operating Units
==============================
This module introduces the following features:
* Adds the Operating Unit (OU) to the RMA order.
* Users can only view and manage the rma orders associated to their operating
unit.
Usage
=====
* The default operating unit of the RMA comes from the default operating unit
of the user
Contributors
------------
* Aaron Henriquez <ahenriquez@eficent.com>
Maintainer
----------
This module is maintained by Eficent.

View File

@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
from . import tests

View File

@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
{
"name": "Operating Unit in RMA Orders",
"version": "9.0.1.0.0",
"author": "Eficent",
"license": "LGPL-3",
"website": "http://www.eficent.com",
"category": "Operating Units",
"depends": ["rma", "operating_unit"],
"data": [
"security/rma_security.xml",
"views/rma_order_view.xml"
],
'installable': True,
}

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import rma_order

View File

@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from openerp import api, fields, models, _
from openerp.exceptions import ValidationError
class RmaOrder(models.Model):
_inherit = "rma.order"
@api.model
def _default_operating_unit(self):
return self.env.user.default_operating_unit_id
operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Operating Unit',
default=_default_operating_unit,
)

View File

@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<odoo>
<data noupdate="0">
<record id="ir_rule_rma_allowed_operating_units"
model="ir.rule">
<field name="model_id" ref="rma.model_rma_order"/>
<field name="domain_force">['|',('operating_unit_id','=',False),('operating_unit_id','in',[g.id for g in user.operating_unit_ids])]</field>
<field name="name">RMA 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>
</data>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import test_rma_operating_unit

View File

@@ -0,0 +1,77 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from openerp.tests import common
class TestRmaOperatingUnit(common.TransactionCase):
def setUp(self):
super(TestRmaOperatingUnit, self).setUp()
self.res_users_model = self.env['res.users']
self.rma_model = self.env['rma.order']
self.company = self.env.ref('base.main_company')
self.partner = self.env.ref('base.res_partner_1')
self.grp_rma_manager = self.env.ref('rma.group_rma_manager')
# 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')
# Users
self.user1 = self._create_user('user_1',
[self.grp_rma_manager],
self.company,
[self.main_OU, self.b2c_OU])
self.user2 = self._create_user('user_2',
[self.grp_rma_manager],
self.company,
[self.b2c_OU])
self.user3 = self._create_user('user_3',
[self.grp_rma_manager],
self.company,
[self.main_OU, self.b2c_OU])
# RMA Orders
self.rma_order1 = self._create_rma(self.user1.id, self.main_OU)
self.rma_order2 = self._create_rma(self.user2.id, self.b2c_OU)
self.rma_order3 = self._create_rma(self.user3.id)
def _create_user(self, login, groups, company, operating_units):
"""Creates a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.create({
'name': login,
'login': login,
'password': 'demo',
'email': 'example@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_rma(self, uid, operating_unit=False):
"""Creates an RMA"""
if not operating_unit:
operating_unit = self.rma_model.sudo(uid).\
_default_operating_unit()
rma_order = self.rma_model.sudo(uid).create({
'operating_unit_id': operating_unit.id,
'partner_id': self.partner.id,
'user_id': uid,
})
return rma_order
def test_security(self):
# User 2 is only assigned to Operating Unit B2C, and cannot
# access RMA of Main Operating Unit.
record = self.rma_model.sudo(
self.user2.id).search([('id', '=', self.rma_order1.id),
('operating_unit_id', '=',
self.main_OU.id)])
self.assertEqual(record.ids, [], 'User 2 should not have access to '
'OU %s.' % self.main_OU.name)

View File

@@ -0,0 +1,67 @@
<?xml version="1.0"?>
<!-- Copyright 2017 Eficent Business and IT Consulting Services S.L.
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl-3.0) -->
<openerp>
<data>
<record id="view_rma_tree" model="ir.ui.view">
<field name="name">rma.order.tree</field>
<field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_tree"/>
<field name="arch" type="xml">
<field name="assigned_to" position="after">
<field name="operating_unit_id"/>
</field>
</field>
</record>
<record id="view_rma_supplier_tree" model="ir.ui.view">
<field name="name">rma.order.supplier.tree</field>
<field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_supplier_tree"/>
<field name="arch" type="xml">
<field name="assigned_to" position="after">
<field name="operating_unit_id"/>
</field>
</field>
</record>
<record id="view_rma_supplier_form" model="ir.ui.view">
<field name="name">rma.order.supplier.form</field>
<field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_supplier_form"/>
<field name="arch" type="xml">
<group name="company" position="inside">
<field name="company_id" invisible = "True"/>
<field name="operating_unit_id" domain = "[('company_id','=', company_id)]"
options="{'no_create': True}"/>
</group>
</field>
</record>
<record id="view_rma_form" model="ir.ui.view">
<field name="name">rma.order.form</field>
<field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_form"/>
<field name="arch" type="xml">
<group name="company" position="inside">
<field name="company_id" invisible = "True"/>
<field name="operating_unit_id" domain = "[('company_id','=', company_id)]"
options="{'no_create': True}"/>
</group>
</field>
</record>
<record id="view_rma_rma_filter" model="ir.ui.view">
<field name="name">rma.order.select</field>
<field name="model">rma.order</field>
<field name="inherit_id" ref="rma.view_rma_rma_filter"/>
<field name="arch" type="xml">
<field name="assigned_to" position="after">
<field name="operating_unit_id"/>
</field>
</field>
</record>
</data>
</openerp>