Skip to content

Commit

Permalink
[IMP] Added test cases for mrp.
Browse files Browse the repository at this point in the history
  • Loading branch information
SerpentCS authored and LoisRForgeFlow committed Mar 30, 2017
1 parent 000e862 commit 4dca97c
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 11 deletions.
1 change: 1 addition & 0 deletions mrp_operating_unit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import models
from . import tests
1 change: 1 addition & 0 deletions mrp_operating_unit/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
# © 2015 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import test_procurement
from . import test_mrp_operating_unit
92 changes: 92 additions & 0 deletions mrp_operating_unit/tests/test_mrp_operating_unit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
from openerp.tests import common


class TestMrpOperatingUnit(common.TransactionCase):

def setUp(self):
super(TestMrpOperatingUnit, self).setUp()
self.res_users_model = self.env['res.users']
self.mrp_production_model = self.env['mrp.production']
self.company = self.env.ref('base.main_company')

# Products
self.product1 = self.env.ref('product.product_product_4c')
# Stock Location
self.stock_location = self.env.ref('stock.stock_location_shop0')

# Main Operating Unit
self.ou1 = self.env.ref('operating_unit.main_operating_unit')
# Chicago Operating Unit
self.chicago = self.env.ref('stock_operating_unit.operating_unit_shop0')

# Groups
self.grp_mrp_saleman = self.env.ref('base.group_sale_salesman')

# Users
self.user1 = self._create_user('user_1',
[self.grp_mrp_saleman],
self.company,
[self.ou1, self.chicago])
self.user2 = self._create_user('user_2',
[self.grp_mrp_saleman],
self.company,
[self.chicago])

# Manufacturing Orders
self.mrp_record1 = self._create_mrp('Manufacturing Order 1', self.ou1)
self.mrp_record2 = self._create_mrp('Manufacturing Order 2',
self.chicago, self.stock_location)


def _create_user(self, login, groups, company, operating_units,
context=None):
"""Create a user."""
group_ids = [group.id for group in groups]
user = self.res_users_model.create({
'name': 'Test HR Contrac User',
'login': login,
'password': 'demo',
'email': '[email protected]',
'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_mrp(self, name, operating_unit, stock_location=False):
new_line = self.mrp_production_model.new()
res = new_line.product_id_change(product_id=self.product1.id)
if res.get('value') and res.get('value').get('bom_id'):
bom_id = res.get('value').get('bom_id')
if res.get('value') and res.get('value').get('product_uom'):
product_uom = res.get('value').get('product_uom')
if operating_unit is self.ou1:
mrp = self.mrp_production_model.create({
'name': name,
'product_id': self.product1.id,
'bom_id': bom_id,
'product_qty': '10.0',
'product_uom': product_uom,
'operating_unit_id': operating_unit.id,
})
else:
mrp = self.mrp_production_model.create({
'name': name,
'product_id': self.product1.id,
'bom_id': bom_id,
'product_qty': '10.0',
'product_uom': product_uom,
'operating_unit_id': operating_unit.id,
'location_src_id': stock_location.id,
'location_dest_id': stock_location.id
})
return mrp

def test_mrp_ou(self):
record = self.mrp_production_model.sudo(self.user2.id).search(
[('id', '=', self.mrp_record1.id),
('operating_unit_id', '=',
self.ou1.id)])
self.assertEqual(record.ids, [], 'User 2 should not have access to '
'OU : %s' % self.ou1.name)
11 changes: 0 additions & 11 deletions mrp_operating_unit/tests/test_procurement.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,8 @@ def setUp(self):
self.res_users_model = self.env['res.users']
self.procurement_order_model = self.env['procurement.order']
self.procurement_rule_model = self.env['procurement.rule']
self.mrp_line_model = self.env['mrp.bom.line']
self.bom_model = self.env['mrp.bom']
self.property_model = self.env['mrp.property']
self.product_model = self.env['product.product']
self.product_template_model = self.env['product.template']
self.product_category_model = self.env['product.category']
self.product_category = self.env.ref('product.product_category_2')
self.warehouse = self.env.ref('stock.warehouse0')
self.product_unit = self.env.ref('product.product_uom_unit')
self.property = self.env.ref('mrp.mrp_property_0')
self.line = self.env.ref('mrp.mrp_property_0')
self.group = self.env.ref('mrp.mrp_property_group_1')
self.company = self.env.ref('base.main_company')

# Main Operating Unit
self.ou1 = self.env.ref('operating_unit.main_operating_unit')
Expand Down

0 comments on commit 4dca97c

Please sign in to comment.