diff --git a/addons/repair/tests/test_repair.py b/addons/repair/tests/test_repair.py index 7d8578d3f3f..a144de37972 100644 --- a/addons/repair/tests/test_repair.py +++ b/addons/repair/tests/test_repair.py @@ -10,33 +10,158 @@ from odoo.tests import tagged @tagged('post_install', '-at_install') class TestRepair(AccountingTestCase): - def setUp(self): - super(TestRepair, self).setUp() + @classmethod + def setUpClass(cls): + super(TestRepair, cls).setUpClass() - self.Repair = self.env['repair.order'] - self.ResUsers = self.env['res.users'] - self.RepairMakeInvoice = self.env['repair.order.make_invoice'] - self.res_group_user = self.env.ref('stock.group_stock_user') - self.res_group_manager = self.env.ref('stock.group_stock_manager') - self.repair_r0 = self.env.ref('repair.repair_r0') - self.repair_r1 = self.env.ref('repair.repair_r1') - self.repair_r2 = self.env.ref('repair.repair_r2') + # Partners + cls.res_partner_1 = cls.env['res.partner'].create({'name': 'Wood Corner'}) + cls.res_partner_address_1 = cls.env['res.partner'].create({'name': 'Willie Burke', 'parent_id': cls.res_partner_1.id}) + cls.res_partner_12 = cls.env['res.partner'].create({'name': 'Partner 12'}) - self.res_repair_user = self.ResUsers.create({ + # Products + cls.product_product_3 = cls.env['product.product'].create({'name': 'Desk Combination'}) + cls.product_product_11 = cls.env['product.product'].create({'name': 'Conference Chair'}) + cls.product_product_5 = cls.env['product.product'].create({'name': 'Product 5'}) + cls.product_product_6 = cls.env['product.product'].create({'name': 'Large Cabinet'}) + cls.product_product_12 = cls.env['product.product'].create({'name': 'Office Chair Black'}) + cls.product_product_13 = cls.env['product.product'].create({'name': 'Corner Desk Black'}) + cls.product_product_2 = cls.env['product.product'].create({'name': 'Virtual Home Staging'}) + cls.product_service_order_repair = cls.env['product.product'].create({ + 'name': 'Repair Services', + 'type': 'service', + }) + + # Location + cls.stock_location_14 = cls.env['stock.location'].create({ + 'name': 'Shelf 2', + 'location_id': cls.env.ref('stock.warehouse0').lot_stock_id.id, + }) + + # Repair Orders + cls.repair1 = cls.env['repair.order'].create({ + 'address_id': cls.res_partner_address_1.id, + 'guarantee_limit': datetime.today().strftime('%Y-%m-%d'), + 'invoice_method': 'none', + 'user_id': False, + 'product_id': cls.product_product_3.id, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'partner_invoice_id': cls.res_partner_address_1.id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, + 'operations': [ + (0, 0, { + 'location_dest_id': cls.product_product_11.property_stock_production.id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, + 'name': cls.product_product_11.get_product_multiline_description_sale(), + 'product_id': cls.product_product_11.id, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'product_uom_qty': 1.0, + 'price_unit': 50.0, + 'state': 'draft', + 'type': 'add', + 'company_id': cls.env.company.id, + }) + ], + 'fees_lines': [ + (0, 0, { + 'name': cls.product_service_order_repair.get_product_multiline_description_sale(), + 'product_id': cls.product_service_order_repair.id, + 'product_uom_qty': 1.0, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'price_unit': 50.0, + 'company_id': cls.env.company.id, + }) + ], + 'partner_id': cls.res_partner_12.id, + }) + + cls.repair0 = cls.env['repair.order'].create({ + 'product_id': cls.product_product_5.id, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'address_id': cls.res_partner_address_1.id, + 'guarantee_limit': datetime.today().strftime('%Y-%m-%d'), + 'invoice_method': 'after_repair', + 'user_id': False, + 'partner_invoice_id': cls.res_partner_address_1.id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, + 'operations': [ + (0, 0, { + 'location_dest_id': cls.product_product_12.property_stock_production.id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, + 'name': cls.product_product_12.get_product_multiline_description_sale(), + 'price_unit': 50.0, + 'product_id': cls.product_product_12.id, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'product_uom_qty': 1.0, + 'state': 'draft', + 'type': 'add', + 'company_id': cls.env.company.id, + }) + ], + 'fees_lines': [ + (0, 0, { + 'name': cls.product_service_order_repair.get_product_multiline_description_sale(), + 'product_id': cls.product_service_order_repair.id, + 'product_uom_qty': 1.0, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'price_unit': 50.0, + 'company_id': cls.env.company.id, + }) + ], + 'partner_id': cls.res_partner_12.id, + }) + + cls.repair2 = cls.env['repair.order'].create({ + 'product_id': cls.product_product_6.id, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'address_id': cls.res_partner_address_1.id, + 'guarantee_limit': datetime.today().strftime('%Y-%m-%d'), + 'invoice_method': 'b4repair', + 'user_id': False, + 'partner_invoice_id': cls.res_partner_address_1.id, + 'location_id': cls.stock_location_14.id, + 'operations': [ + (0, 0, { + 'location_dest_id': cls.product_product_13.property_stock_production.id, + 'location_id': cls.env.ref('stock.stock_location_stock').id, + 'name': cls.product_product_13.get_product_multiline_description_sale(), + 'price_unit': 50.0, + 'product_id': cls.product_product_13.id, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'product_uom_qty': 1.0, + 'state': 'draft', + 'type': 'add', + 'company_id': cls.env.company.id, + }) + ], + 'fees_lines': [ + (0, 0, { + 'name': cls.product_service_order_repair.get_product_multiline_description_sale(), + 'product_id': cls.product_service_order_repair.id, + 'product_uom_qty': 1.0, + 'product_uom': cls.env.ref('uom.product_uom_unit').id, + 'price_unit': 50.0, + 'company_id': cls.env.company.id, + }) + ], + 'partner_id': cls.res_partner_12.id, + }) + + cls.res_repair_user = cls.env['res.users'].create({ 'name': 'Repair User', 'login': 'maru', 'email': 'repair_user@yourcompany.com', - 'groups_id': [(6, 0, [self.res_group_user.id])]}) + 'groups_id': [(6, 0, [cls.env.ref('stock.group_stock_user').id])]}) - self.res_repair_manager = self.ResUsers.create({ + cls.res_repair_manager = cls.env['res.users'].create({ 'name': 'Repair Manager', 'login': 'marm', 'email': 'repair_manager@yourcompany.com', - 'groups_id': [(6, 0, [self.res_group_manager.id])]}) + 'groups_id': [(6, 0, [cls.env.ref('stock.group_stock_manager').id])]}) def _create_simple_repair_order(self, invoice_method): - product_to_repair = self.env.ref('product.product_product_5') - partner = self.env.ref('base.res_partner_address_1') + product_to_repair = self.product_product_5 + partner = self.res_partner_address_1 return self.env['repair.order'].create({ 'product_id': product_to_repair.id, 'product_uom': product_to_repair.uom_id.id, @@ -45,11 +170,11 @@ class TestRepair(AccountingTestCase): 'invoice_method': invoice_method, 'partner_invoice_id': partner.id, 'location_id': self.env.ref('stock.stock_location_stock').id, - 'partner_id': self.env.ref('base.res_partner_12').id + 'partner_id': self.res_partner_12.id }) def _create_simple_operation(self, repair_id=False, qty=0.0, price_unit=0.0): - product_to_add = self.env.ref('product.product_product_5') + product_to_add = self.product_product_5 return self.env['repair.line'].create({ 'name': 'Add The product', 'type': 'add', @@ -64,7 +189,7 @@ class TestRepair(AccountingTestCase): }) def _create_simple_fee(self, repair_id=False, qty=0.0, price_unit=0.0): - product_service = self.env.ref('product.product_product_2') + product_service = self.product_product_2 return self.env['repair.fee'].create({ 'name': 'PC Assemble + Custom (PC on Demand)', 'product_id': product_service.id, @@ -92,7 +217,7 @@ class TestRepair(AccountingTestCase): repair.action_repair_end() # I define Invoice Method 'After Repair' option in this Repair order.so I create invoice by clicking on "Make Invoice" wizard. - make_invoice = self.RepairMakeInvoice.create({ + make_invoice = self.env['repair.order.make_invoice'].create({ 'group': True}) # I click on "Create Invoice" button of this wizard to make invoice. context = { @@ -147,7 +272,7 @@ class TestRepair(AccountingTestCase): 'Repaired product went to the wrong location') self.assertEqual(repair.operations.move_id.location_id.id, self.env.ref('stock.stock_location_stock').id, 'Consumed product was taken in the wrong location') - self.assertEqual(repair.operations.move_id.location_dest_id.id, self.env.ref('product.product_product_5').property_stock_production.id, + self.assertEqual(repair.operations.move_id.location_dest_id.id, self.product_product_5.property_stock_production.id, 'Consumed product went to the wrong location') # I define Invoice Method 'No Invoice' option in this repair order.