1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
|
# -*- coding: utf-8 -*-
from odoo.tests import Form
from odoo.addons.mail.tests.common import mail_new_test_user
from odoo.addons.stock.tests.common import TestStockCommon
class TestMrpCommon(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': 'consu',
'is_storable': True,
'tracking': tracking_final,
})
product_to_use_1 = cls.env['product.product'].create({
'name': 'Botox',
'type': 'consu',
'is_storable': True,
'tracking': tracking_base_1,
})
product_to_use_2 = cls.env['product.product'].create({
'name': 'Old Tom',
'type': 'consu',
'is_storable': True,
'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, 'manual_consumption': tracking_base_2 != 'none'}),
(0, 0, {'product_id': product_to_use_1.id, 'product_qty': qty_base_1, 'manual_consumption': tracking_base_1 != 'none'})
]})
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()
(
cls.product_4,
cls.product_5,
cls.product_6,
cls.product_8,
) = cls.env['product.product'].create([{
'name': 'Stick', # product_4
'uom_id': cls.uom_dozen.id,
'uom_po_id': cls.uom_dozen.id,
}, {
'name': 'Stone Tools', # product_5
}, {
'name': 'Door', # product_6
}, {
'name': 'House', # product_8
}])
# 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': 'consu',
'is_storable': True,
})
# 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',
)
# Both groups below are required to make fields `product_uom_id` and
# `workorder_ids` to be visible in the view of `mrp.production`. The
# field `product_uom_id` must be set by many tests, and subviews of
# `workorder_ids` must be present in many tests to create records.
cls.env.user.groups_id += cls.env.ref('uom.group_uom') + cls.env.ref('mrp.group_mrp_routings')
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': 'consu',
'is_storable': True,
'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': 'consu',
'is_storable': True,
'tracking': 'none',
'categ_id': cls.env.ref('product.product_category_all').id,
})
@classmethod
def make_prods(cls, n):
return [
cls.env["product.product"].create(
{"name": f"p{k + 1}", 'is_storable': True}
)
for k in range(n)
]
@classmethod
def make_bom(cls, p, *cs):
return cls.env["mrp.bom"].create(
{
"product_tmpl_id": p.product_tmpl_id.id,
"product_id": p.id,
"product_qty": 1,
"type": "phantom",
"product_uom_id": cls.uom_unit.id,
"bom_line_ids": [
(0, 0, {
"product_id": c.id,
"product_qty": 1,
"product_uom_id": cls.uom_unit.id
})
for c in cs
],
}
)
|