In the web client, in a real use case, it's not possible to write on fields which are invisible, as it's not possible to write on fields which are readonly. This is a first step in the goal to change the behavior of the `groups=` attribute in the back-end views, to remove them for the view instead of making them invisible. This is mainly to reduce the diff of the revision that will introduce the mentioned above behavior change. As nodes with `groups=` will be removed from the view when the user doesn't have the group, it's no longer possible to set a value on a field having a `groups=` the user doesn't have in the `Form` test class, as the field will no longer be at all in the view. However, these unit tests shouldn't have been able to set values on invisible fields in the first place. This revision therefore aims to correct the unit tests setting value on fields which were invisible because the user executing the test was not part of the required group(s) for these fields to be visible in the view. closes odoo/odoo#94337 Related: odoo/enterprise#28936 Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
214 lines
9.0 KiB
Python
214 lines
9.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
from odoo.tests import Form
|
|
from odoo.addons.mail.tests.common import mail_new_test_user
|
|
from odoo.addons.stock.tests import common2
|
|
|
|
|
|
class TestMrpCommon(common2.TestStockCommon):
|
|
|
|
@classmethod
|
|
def generate_mo(cls, tracking_final='none', tracking_base_1='none', tracking_base_2='none', qty_final=5, qty_base_1=4, qty_base_2=1, picking_type_id=False, consumption=False):
|
|
""" This function generate a manufacturing order with one final
|
|
product and two consumed product. Arguments allows to choose
|
|
the tracking/qty for each different products. It returns the
|
|
MO, used bom and the tree products.
|
|
"""
|
|
product_to_build = cls.env['product.product'].create({
|
|
'name': 'Young Tom',
|
|
'type': 'product',
|
|
'tracking': tracking_final,
|
|
})
|
|
product_to_use_1 = cls.env['product.product'].create({
|
|
'name': 'Botox',
|
|
'type': 'product',
|
|
'tracking': tracking_base_1,
|
|
})
|
|
product_to_use_2 = cls.env['product.product'].create({
|
|
'name': 'Old Tom',
|
|
'type': 'product',
|
|
'tracking': tracking_base_2,
|
|
})
|
|
bom_1 = cls.env['mrp.bom'].create({
|
|
'product_id': product_to_build.id,
|
|
'product_tmpl_id': product_to_build.product_tmpl_id.id,
|
|
'product_uom_id': cls.uom_unit.id,
|
|
'product_qty': 1.0,
|
|
'type': 'normal',
|
|
'consumption': consumption if consumption else 'flexible',
|
|
'bom_line_ids': [
|
|
(0, 0, {'product_id': product_to_use_2.id, 'product_qty': qty_base_2}),
|
|
(0, 0, {'product_id': product_to_use_1.id, 'product_qty': qty_base_1})
|
|
]})
|
|
mo_form = Form(cls.env['mrp.production'])
|
|
mo_form.product_id = product_to_build
|
|
if picking_type_id:
|
|
mo_form.picking_type_id = picking_type_id
|
|
mo_form.bom_id = bom_1
|
|
mo_form.product_qty = qty_final
|
|
mo = mo_form.save()
|
|
mo.action_confirm()
|
|
return mo, bom_1, product_to_build, product_to_use_1, product_to_use_2
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(TestMrpCommon, cls).setUpClass()
|
|
|
|
# Update demo products
|
|
(cls.product_2 | cls.product_3 | cls.product_4 | cls.product_5 | cls.product_6 | cls.product_7_3 | cls.product_8).write({
|
|
'type': 'product',
|
|
})
|
|
|
|
# User Data: mrp user and mrp manager
|
|
cls.user_mrp_user = mail_new_test_user(
|
|
cls.env,
|
|
name='Hilda Ferachwal',
|
|
login='hilda',
|
|
email='h.h@example.com',
|
|
notification_type='inbox',
|
|
groups='mrp.group_mrp_user, stock.group_stock_user, mrp.group_mrp_byproducts, uom.group_uom',
|
|
)
|
|
cls.user_mrp_manager = mail_new_test_user(
|
|
cls.env,
|
|
name='Gary Youngwomen',
|
|
login='gary',
|
|
email='g.g@example.com',
|
|
notification_type='inbox',
|
|
groups='mrp.group_mrp_manager, stock.group_stock_user, mrp.group_mrp_byproducts, uom.group_uom',
|
|
)
|
|
# Required for `product_uom_id` to be visible in the view
|
|
# This class is used by a lot of tests which sets `product_uom_id` on `mrp.production`
|
|
cls.env.user.groups_id += cls.env.ref('uom.group_uom')
|
|
|
|
cls.workcenter_1 = cls.env['mrp.workcenter'].create({
|
|
'name': 'Nuclear Workcenter',
|
|
'default_capacity': 2,
|
|
'time_start': 10,
|
|
'time_stop': 5,
|
|
'time_efficiency': 80,
|
|
})
|
|
cls.workcenter_2 = cls.env['mrp.workcenter'].create({
|
|
'name': 'Simple Workcenter',
|
|
'default_capacity': 1,
|
|
'time_start': 0,
|
|
'time_stop': 0,
|
|
'time_efficiency': 100,
|
|
})
|
|
cls.workcenter_3 = cls.env['mrp.workcenter'].create({
|
|
'name': 'Double Workcenter',
|
|
'default_capacity': 2,
|
|
'time_start': 0,
|
|
'time_stop': 0,
|
|
'time_efficiency': 100,
|
|
})
|
|
|
|
cls.bom_1 = cls.env['mrp.bom'].create({
|
|
'product_id': cls.product_4.id,
|
|
'product_tmpl_id': cls.product_4.product_tmpl_id.id,
|
|
'product_uom_id': cls.uom_unit.id,
|
|
'product_qty': 4.0,
|
|
'consumption': 'flexible',
|
|
'operation_ids': [
|
|
],
|
|
'type': 'normal',
|
|
'bom_line_ids': [
|
|
(0, 0, {'product_id': cls.product_2.id, 'product_qty': 2}),
|
|
(0, 0, {'product_id': cls.product_1.id, 'product_qty': 4})
|
|
]})
|
|
cls.bom_2 = cls.env['mrp.bom'].create({
|
|
'product_id': cls.product_5.id,
|
|
'product_tmpl_id': cls.product_5.product_tmpl_id.id,
|
|
'product_uom_id': cls.product_5.uom_id.id,
|
|
'consumption': 'flexible',
|
|
'product_qty': 1.0,
|
|
'operation_ids': [
|
|
(0, 0, {'name': 'Gift Wrap Maching', 'workcenter_id': cls.workcenter_1.id, 'time_cycle': 15, 'sequence': 1}),
|
|
],
|
|
'type': 'phantom',
|
|
'sequence': 2,
|
|
'bom_line_ids': [
|
|
(0, 0, {'product_id': cls.product_4.id, 'product_qty': 2}),
|
|
(0, 0, {'product_id': cls.product_3.id, 'product_qty': 3})
|
|
]})
|
|
cls.bom_3 = cls.env['mrp.bom'].create({
|
|
'product_id': cls.product_6.id,
|
|
'product_tmpl_id': cls.product_6.product_tmpl_id.id,
|
|
'product_uom_id': cls.uom_dozen.id,
|
|
'ready_to_produce': 'asap',
|
|
'consumption': 'flexible',
|
|
'product_qty': 2.0,
|
|
'operation_ids': [
|
|
(0, 0, {'name': 'Cutting Machine', 'workcenter_id': cls.workcenter_1.id, 'time_cycle': 12, 'sequence': 1}),
|
|
(0, 0, {'name': 'Weld Machine', 'workcenter_id': cls.workcenter_1.id, 'time_cycle': 18, 'sequence': 2}),
|
|
],
|
|
'type': 'normal',
|
|
'bom_line_ids': [
|
|
(0, 0, {'product_id': cls.product_5.id, 'product_qty': 2}),
|
|
(0, 0, {'product_id': cls.product_4.id, 'product_qty': 8}),
|
|
(0, 0, {'product_id': cls.product_2.id, 'product_qty': 12})
|
|
]})
|
|
cls.bom_4 = cls.env['mrp.bom'].create({
|
|
'product_id': cls.product_6.id,
|
|
'product_tmpl_id': cls.product_6.product_tmpl_id.id,
|
|
'consumption': 'flexible',
|
|
'product_qty': 1.0,
|
|
'operation_ids': [
|
|
(0, 0, {'name': 'Rub it gently with a cloth', 'workcenter_id': cls.workcenter_2.id,
|
|
'time_mode_batch': 1, 'time_mode': "auto", 'sequence': 1}),
|
|
],
|
|
'type': 'normal',
|
|
'bom_line_ids': [
|
|
(0, 0, {'product_id': cls.product_1.id, 'product_qty': 1}),
|
|
]})
|
|
cls.bom_5 = cls.env['mrp.bom'].create({
|
|
'product_id': cls.product_6.id,
|
|
'product_tmpl_id': cls.product_6.product_tmpl_id.id,
|
|
'consumption': 'flexible',
|
|
'product_qty': 1.0,
|
|
'operation_ids': [
|
|
(0, 0, {'name': 'Rub it gently with a cloth two at once', 'workcenter_id': cls.workcenter_3.id,
|
|
'time_mode_batch': 2, 'time_mode': "auto", 'sequence': 1}),
|
|
],
|
|
'type': 'normal',
|
|
'bom_line_ids': [
|
|
(0, 0, {'product_id': cls.product_1.id, 'product_qty': 1}),
|
|
]})
|
|
cls.bom_6 = cls.env['mrp.bom'].create({
|
|
'product_id': cls.product_6.id,
|
|
'product_tmpl_id': cls.product_6.product_tmpl_id.id,
|
|
'consumption': 'flexible',
|
|
'product_qty': 1.0,
|
|
'operation_ids': [
|
|
(0, 0, {'name': 'Rub it gently with a cloth two at once', 'workcenter_id': cls.workcenter_3.id,
|
|
'time_mode_batch': 1, 'time_mode': "auto", 'sequence': 1}),
|
|
],
|
|
'type': 'normal',
|
|
'bom_line_ids': [
|
|
(0, 0, {'product_id': cls.product_1.id, 'product_qty': 1}),
|
|
]})
|
|
|
|
cls.stock_location_14 = cls.env['stock.location'].create({
|
|
'name': 'Shelf 2',
|
|
'location_id': cls.env.ref('stock.warehouse0').lot_stock_id.id,
|
|
})
|
|
cls.stock_location_components = cls.env['stock.location'].create({
|
|
'name': 'Shelf 1',
|
|
'location_id': cls.env.ref('stock.warehouse0').lot_stock_id.id,
|
|
})
|
|
cls.laptop = cls.env['product.product'].create({
|
|
'name': 'Acoustic Bloc Screens',
|
|
'uom_id': cls.env.ref("uom.product_uom_unit").id,
|
|
'uom_po_id': cls.env.ref("uom.product_uom_unit").id,
|
|
'type': 'product',
|
|
'tracking': 'none',
|
|
'categ_id': cls.env.ref('product.product_category_all').id,
|
|
})
|
|
cls.graphics_card = cls.env['product.product'].create({
|
|
'name': 'Individual Workplace',
|
|
'uom_id': cls.env.ref("uom.product_uom_unit").id,
|
|
'uom_po_id': cls.env.ref("uom.product_uom_unit").id,
|
|
'type': 'product',
|
|
'tracking': 'none',
|
|
'categ_id': cls.env.ref('product.product_category_all').id,
|
|
})
|