def setUpClass(cls): super().setUpClass() # 1: Create a subcontracting partner main_company_1 = cls.env['res.partner'].create( {'name': 'main_partner'}) cls.subcontractor_partner1 = cls.env['res.partner'].create({ 'name': 'Subcontractor 1', 'parent_id': main_company_1.id, 'company_id': cls.env.ref('base.main_company').id }) # 2. Create a BOM of subcontracting type # 2.1. Comp1 has tracking by lot cls.comp1_sn = cls.env['product.product'].create({ 'name': 'Component1', 'type': 'product', 'categ_id': cls.env.ref('product.product_category_all').id, 'tracking': 'serial' }) cls.comp2 = cls.env['product.product'].create({ 'name': 'Component2', 'type': 'product', 'categ_id': cls.env.ref('product.product_category_all').id, }) # 2.2. Finished prodcut has tracking by serial number cls.finished_product = cls.env['product.product'].create({ 'name': 'finished', 'type': 'product', 'categ_id': cls.env.ref('product.product_category_all').id, 'tracking': 'lot' }) bom_form = Form(cls.env['mrp.bom']) bom_form.type = 'subcontract' bom_form.consumption = 'strict' bom_form.subcontractor_ids.add(cls.subcontractor_partner1) bom_form.product_tmpl_id = cls.finished_product.product_tmpl_id with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = cls.comp1_sn bom_line.product_qty = 1 with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = cls.comp2 bom_line.product_qty = 1 cls.bom_tracked = bom_form.save()
def setUpClass(cls): super().setUpClass() # 1. Create portal user user = cls.env['res.users'].with_context({ 'no_reset_password': True, 'mail_create_nolog': True }).create({ 'name': 'Georges', 'login': '******', 'password': '******', 'email': '*****@*****.**', 'signature': 'SignGeorges', 'notification_type': 'email', 'groups_id': [Command.set([cls.env.ref('base.group_portal').id])], }) cls.partner_portal = cls.env['res.partner'].with_context({ 'mail_create_nolog': True }).create({ 'name': 'Georges', 'email': '*****@*****.**', 'company_id': False, 'user_ids': [user.id], }) # 2. Create a BOM of subcontracting type cls.comp = cls.env['product.product'].create({ 'name': 'Component', 'type': 'product', }) cls.finished_product = cls.env['product.product'].create({ 'name': 'Finished', 'type': 'product', }) bom_form = Form(cls.env['mrp.bom']) bom_form.type = 'subcontract' bom_form.consumption = 'warning' bom_form.subcontractor_ids.add(cls.partner_portal) bom_form.product_tmpl_id = cls.finished_product.product_tmpl_id with bom_form.bom_line_ids.new() as bom_line: bom_line.product_id = cls.comp bom_line.product_qty = 1 cls.bom_tracked = bom_form.save()