[MIG]rma_operating_unit to v10

This commit is contained in:
aheficent
2018-01-09 14:02:51 +01:00
committed by Aaron ForgeFlow
parent 3eeaa50707
commit 11e53f04fa
8 changed files with 204 additions and 68 deletions

View File

@@ -1,7 +1,8 @@
# -*- 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
from odoo.tests import common
from odoo import exceptions
class TestRmaOperatingUnit(common.TransactionCase):
@@ -10,10 +11,14 @@ class TestRmaOperatingUnit(common.TransactionCase):
super(TestRmaOperatingUnit, self).setUp()
self.res_users_model = self.env['res.users']
self.rma_model = self.env['rma.order']
self.rma_line_model = self.env['rma.order.line']
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')
self.grp_ou = self.env.ref("operating_unit.group_multi_operating_unit")
self.grp_stock = self.env.ref("stock.group_stock_manager")
self.product = self.env.ref('product.product_product_12')
# Main Operating Unit
self.main_OU = self.env.ref('operating_unit.main_operating_unit')
@@ -22,15 +27,18 @@ class TestRmaOperatingUnit(common.TransactionCase):
# Users
self.user1 = self._create_user('user_1',
[self.grp_rma_manager],
[self.grp_rma_manager, self.grp_ou,
self.grp_stock],
self.company,
[self.main_OU, self.b2c_OU])
self.user2 = self._create_user('user_2',
[self.grp_rma_manager],
[self.grp_rma_manager, self.grp_ou,
self.grp_stock],
self.company,
[self.b2c_OU])
self.user3 = self._create_user('user_3',
[self.grp_rma_manager],
[self.grp_rma_manager, self.grp_ou,
self.grp_stock],
self.company,
[self.main_OU, self.b2c_OU])
@@ -66,6 +74,25 @@ class TestRmaOperatingUnit(common.TransactionCase):
})
return rma_order
def _create_rma_line(self, rma, uid, operating_unit):
"""Creates an RMA"""
rma_order_line = self.rma_line_model.sudo(uid).create({
'operating_unit_id': operating_unit.id,
'rma_id': rma.id,
'partner_id': self.partner.id,
'in_route_id': 1,
'out_route_id': 1,
'in_warehouse_id': 1,
'out_warehouse_id': 1,
'location_id': 1,
'receipt_policy': 'ordered',
'delivery_policy': 'ordered',
'name': self.product.name,
'product_id': self.product.id,
'uom_id': self.product.uom_id.id
})
return rma_order_line
def test_security(self):
# User 2 is only assigned to Operating Unit B2C, and cannot
# access RMA of Main Operating Unit.
@@ -75,3 +102,10 @@ class TestRmaOperatingUnit(common.TransactionCase):
self.main_OU.id)])
self.assertEqual(record.ids, [], 'User 2 should not have access to '
'OU %s.' % self.main_OU.name)
def test_constraint(self):
# RMA group should contain rma lines for the same OU
with self.assertRaises(exceptions.ValidationError):
self._create_rma_line(self.rma_order1, self.user1.id, self.main_OU)
self._create_rma_line(self.rma_order1, self.user1.id, self.b2c_OU)
self.rma_order1._check_operating_unit()