From 620659d8e8566e6a187af9c2ac27d76032a76e33 Mon Sep 17 00:00:00 2001 From: Hiral Bhavsar Date: Tue, 18 Apr 2017 16:43:13 +0530 Subject: [PATCH] [IMP] sale_mrp: Convert yml test into python --- addons/sale_mrp/__manifest__.py | 3 - addons/sale_mrp/test/sale_mrp.yml | 87 --------------- addons/sale_mrp/tests/__init__.py | 1 + .../tests/test_sale_mrp_procurement.py | 100 ++++++++++++++++++ 4 files changed, 101 insertions(+), 90 deletions(-) delete mode 100644 addons/sale_mrp/test/sale_mrp.yml create mode 100644 addons/sale_mrp/tests/test_sale_mrp_procurement.py diff --git a/addons/sale_mrp/__manifest__.py b/addons/sale_mrp/__manifest__.py index 0a68dd48fef..af94326a892 100644 --- a/addons/sale_mrp/__manifest__.py +++ b/addons/sale_mrp/__manifest__.py @@ -19,9 +19,6 @@ from sales order. It adds sales name and sales Reference on production order. 'security/ir.model.access.csv', ], 'demo': [], - 'test':[ - 'test/sale_mrp.yml', - ], 'installable': True, 'auto_install': True, } diff --git a/addons/sale_mrp/test/sale_mrp.yml b/addons/sale_mrp/test/sale_mrp.yml deleted file mode 100644 index 945e4d1414a..00000000000 --- a/addons/sale_mrp/test/sale_mrp.yml +++ /dev/null @@ -1,87 +0,0 @@ -- - In order to test the sale_mrp module in OpenERP, I start by creating a new product 'Slider Mobile' -- - I define product category Mobile Products Sellable. -- - !record {model: product.category, id: product_category_allproductssellable0}: - name: Mobile Products Sellable -- - I define product category Mobile Services. -- - !record {model: product.category, id: product_category_16}: - name: Mobile Services -- - I define product template for Slider Mobile. -- - !record {model: product.template, id: product_template_slidermobile0}: - categ_id: product_category_allproductssellable0 - list_price: 200.0 - name: Slider Mobile - standard_price: 189.0 - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit -- - I define a product Slider Mobile -- - !record {model: product.product, id: product_product_slidermobile0, view: False}: - categ_id: product_category_allproductssellable0 - list_price: 200.0 - name: Slider Mobile - seller_ids: - - delay: 1 - name: base.res_partner_2 - min_qty: 2.0 - standard_price: 189.0 - type: product - uom_id: product.product_uom_unit - uom_po_id: product.product_uom_unit -- - I add the routes manufacture and mto to the product -- - !python {model: product.product, id: product_product_slidermobile0}: | - route_warehouse0_manufacture_id = self.env['stock.warehouse'].browse(ref('stock.warehouse0')).manufacture_pull_id.route_id.id - route_warehouse0_mto_id = self.env['stock.warehouse'].browse(ref('stock.warehouse0')).mto_pull_id.route_id.id - self.write({'route_ids': [(6, 0, [route_warehouse0_mto_id,route_warehouse0_manufacture_id])]}) -- - I create a Bill of Material record for Slider Mobile -- - !record {model: mrp.bom, id: mrp_bom_slidermobile0}: - company_id: base.main_company - product_tmpl_id: product_product_slidermobile0_product_template - product_id: product_product_slidermobile0 - product_qty: 1.0 - product_uom_id: product.product_uom_unit - sequence: 0.0 - type: normal -- - I create a sale order for product Slider mobile -- - !record {model: sale.order, id: sale_order_so0}: - client_order_ref: ref1 - date_order: !eval time.strftime('%Y-%m-%d') - name: Test_SO001 - order_line: - - name: Slider Mobile - price_unit: 200 - product_uom: product.product_uom_unit - product_uom_qty: 500.0 - state: draft - customer_lead: 7.0 - product_id: product_product_slidermobile0 - partner_id: base.res_partner_4 - partner_invoice_id: base.res_partner_address_7 - partner_shipping_id: base.res_partner_address_7 - picking_policy: direct - pricelist_id: product.list0 -- - I confirm the sale order -- - !python {model: sale.order, id: sale_order_so0}: | - self.action_confirm() -- - I verify that a manufacturing order has been generated, and that its name and reference are correct -- - !python {model: sale.order, id: sale_order_so0}: | - mo = self.env['mrp.production'].search([('origin','like',self.name)], limit=1) - assert mo, 'Manufacturing order has not been generated' diff --git a/addons/sale_mrp/tests/__init__.py b/addons/sale_mrp/tests/__init__.py index 7ab4d843744..45ec87d69bd 100644 --- a/addons/sale_mrp/tests/__init__.py +++ b/addons/sale_mrp/tests/__init__.py @@ -4,3 +4,4 @@ from . import test_move_explode from . import test_sale_mrp_flow from . import test_sale_mrp_lead_time +from . import test_sale_mrp_procurement diff --git a/addons/sale_mrp/tests/test_sale_mrp_procurement.py b/addons/sale_mrp/tests/test_sale_mrp_procurement.py new file mode 100644 index 00000000000..b702aea6054 --- /dev/null +++ b/addons/sale_mrp/tests/test_sale_mrp_procurement.py @@ -0,0 +1,100 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import time + +from datetime import datetime + +from odoo.tests.common import TransactionCase + + +class TestSaleMrpProcurement(TransactionCase): + + def test_sale_mrp(self): + # In order to test the sale_mrp module in OpenERP, I start by creating a new product 'Slider Mobile' + # I define product category Mobile Products Sellable. + + product_category_allproductssellable0 = self.env['product.category'].create({ + 'name': 'Mobile Products Sellable' + }) + + # I define product category Mobile Services. + product_category_16 = self.env['product.category'].create({ + 'name': 'Mobile Services', + }) + + uom_unit = self.env.ref('product.product_uom_unit') + + # I define product template for Slider Mobile. + product_template_slidermobile0 = self.env['product.template'].create({ + 'categ_id': product_category_allproductssellable0.id, + 'list_price': 200.0, + 'name': 'Slider Mobile', + 'standard_price': 189.0, + 'type': 'product', + 'uom_id': uom_unit.id, + 'uom_po_id': uom_unit.id, + }) + + # I define a product Slider Mobile + product_product_slidermobile0 = self.env['product.product'].create({ + 'categ_id': product_category_allproductssellable0.id, + 'list_price': 200.0, + 'name': 'Slider Mobile', + 'seller_ids': [(0, 0, { + 'delay': 1, + 'name': self.env.ref('base.res_partner_2').id, + 'min_qty': 2.0, + })], + 'standard_price': 189.0, + 'type': 'product', + 'uom_id': uom_unit.id, + 'uom_po_id': uom_unit.id, + }) + + # I add the routes manufacture and mto to the product + product_product_slidermobile0.write({ + 'route_ids': [(6, 0, [ + self.env.ref('stock.warehouse0').mto_pull_id.route_id.id, + self.env.ref('stock.warehouse0').manufacture_pull_id.route_id.id, + ])] + }) + + # I create a Bill of Material record for Slider Mobile + mrp_bom_slidermobile0 = self.env['mrp.bom'].create({ + 'company_id': self.env.ref('base.main_company').id, + 'product_tmpl_id': product_template_slidermobile0.id, + 'product_id': product_product_slidermobile0.id, + 'product_qty': 1.0, + 'product_uom_id': uom_unit.id, + 'sequence': 0.0, + 'type': 'normal', + }) + + # I create a sale order for product Slider mobile + sale_order_so0 = self.env['sale.order'].create({ + 'client_order_ref': 'ref1', + 'date_order': time.strftime('%Y-%m-%d'), + 'name': 'Test_SO001', + 'order_line': [(0, 0, { + 'name': 'Slider Mobile', + 'price_unit': 200, + 'product_uom': uom_unit.id, + 'product_uom_qty': 500.0, + 'state': 'draft', + 'customer_lead': 7.0, + 'product_id': product_product_slidermobile0.id, + })], + 'partner_id': self.env.ref('base.res_partner_4').id, + 'partner_invoice_id': self.env.ref('base.res_partner_address_7').id, + 'partner_shipping_id': self.env.ref('base.res_partner_address_7').id, + 'picking_policy': 'direct', + 'pricelist_id': self.env.ref('product.list0').id, + }) + + # I confirm the sale order + sale_order_so0.action_confirm() + + # I verify that a manufacturing order has been generated, and that its name and reference are correct + mo = self.env['mrp.production'].search([('origin', 'like', sale_order_so0.name)], limit=1) + self.assertTrue(mo, 'Manufacturing order has not been generated')