diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/sale_margin/tests | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/sale_margin/tests')
| -rw-r--r-- | addons/sale_margin/tests/__init__.py | 4 | ||||
| -rw-r--r-- | addons/sale_margin/tests/test_sale_margin.py | 153 |
2 files changed, 157 insertions, 0 deletions
diff --git a/addons/sale_margin/tests/__init__.py b/addons/sale_margin/tests/__init__.py new file mode 100644 index 00000000..4a3d8eb4 --- /dev/null +++ b/addons/sale_margin/tests/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import test_sale_margin diff --git a/addons/sale_margin/tests/test_sale_margin.py b/addons/sale_margin/tests/test_sale_margin.py new file mode 100644 index 00000000..01bb1638 --- /dev/null +++ b/addons/sale_margin/tests/test_sale_margin.py @@ -0,0 +1,153 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests import common +from datetime import datetime + + +class TestSaleMargin(common.TransactionCase): + + def setUp(self): + super(TestSaleMargin, self).setUp() + self.SaleOrder = self.env['sale.order'] + + self.product_uom_id = self.ref('uom.product_uom_unit') + self.product = self.env['product.product'].create({'name': 'Individual Workplace'}) + self.product_id = self.product.id + self.partner_id = self.env['res.partner'].create({'name': 'A test partner'}).id + self.partner_invoice_address_id = self.env['res.partner'].create({ + 'name': 'A test partner address', + 'parent_id': self.partner_id, + }).id + self.pricelist_id = self.ref('product.list0') + self.pricelist = self.env.ref('product.list0') + + def test_sale_margin(self): + """ Test the sale_margin module in Odoo. """ + self.pricelist.currency_id = self.env.company.currency_id + self.product.standard_price = 700.0 + sale_order_so11 = self.SaleOrder.create({ + 'date_order': datetime.today(), + 'name': 'Test_SO011', + 'order_line': [ + (0, 0, { + 'name': '[CARD] Individual Workplace', + 'price_unit': 1000.0, + 'product_uom': self.product_uom_id, + 'product_uom_qty': 10.0, + 'state': 'draft', + 'product_id': self.product_id}), + (0, 0, { + 'name': 'Line without product_uom', + 'price_unit': 1000.0, + 'product_uom_qty': 10.0, + 'state': 'draft', + 'product_id': self.product_id})], + 'partner_id': self.partner_id, + 'partner_invoice_id': self.partner_invoice_address_id, + 'partner_shipping_id': self.partner_invoice_address_id, + 'pricelist_id': self.pricelist_id}) + # Confirm the sales order. + sale_order_so11.action_confirm() + # Verify that margin field gets bind with the value. + self.assertEqual(sale_order_so11.margin, 6000.00, "Sales order profit should be 6000.00") + self.assertEqual(sale_order_so11.margin_percent, 0.3, "Sales order margin should be 30%") + sale_order_so11.order_line[1].purchase_price = 800 + self.assertEqual(sale_order_so11.margin, 5000.00, "Sales order margin should be 5000.00") + + def test_sale_margin1(self): + """ Test the margin when sales price is less then cost.""" + sale_order_so12 = self.SaleOrder.create({ + 'date_order': datetime.today(), + 'name': 'Test_SO012', + 'order_line': [ + (0, 0, { + 'name': '[CARD] Individual Workplace', + 'purchase_price': 40.0, + 'price_unit': 20.0, + 'product_uom': self.product_uom_id, + 'product_uom_qty': 1.0, + 'state': 'draft', + 'product_id': self.product_id}), + (0, 0, { + 'name': 'Line without product_uom', + 'price_unit': -100.0, + 'purchase_price': 0.0, + 'product_uom_qty': 1.0, + 'state': 'draft', + 'product_id': self.product_id})], + 'partner_id': self.partner_id, + 'partner_invoice_id': self.partner_invoice_address_id, + 'partner_shipping_id': self.partner_invoice_address_id, + 'pricelist_id': self.pricelist_id}) + # Confirm the sales order. + sale_order_so12.action_confirm() + # Verify that margin field of Sale Order Lines gets bind with the value. + self.assertEqual(sale_order_so12.order_line[0].margin, -20.00, "Sales order profit should be -20.00") + self.assertEqual(sale_order_so12.order_line[0].margin_percent, -1, "Sales order margin percentage should be -100%") + self.assertEqual(sale_order_so12.order_line[1].margin, -100.00, "Sales order profit should be -100.00") + self.assertEqual(sale_order_so12.order_line[1].margin_percent, 1.00, "Sales order margin should be 100% when the cost is zero and price defined") + # Verify that margin field gets bind with the value. + self.assertEqual(sale_order_so12.margin, -120.00, "Sales order margin should be -120.00") + self.assertEqual(sale_order_so12.margin_percent, 1.5, "Sales order margin should be 150%") + + def test_sale_margin2(self): + """ Test the margin when cost is 0 margin percentage should always be 100%.""" + sale_order_so13 = self.SaleOrder.create({ + 'date_order': datetime.today(), + 'name': 'Test_SO013', + 'order_line': [ + (0, 0, { + 'name': '[CARD] Individual Workplace', + 'purchase_price': 0.0, + 'price_unit': 70.0, + 'product_uom': self.product_uom_id, + 'product_uom_qty': 1.0, + 'state': 'draft', + 'product_id': self.product_id})], + 'partner_id': self.partner_id, + 'partner_invoice_id': self.partner_invoice_address_id, + 'partner_shipping_id': self.partner_invoice_address_id, + 'pricelist_id': self.pricelist_id}) + # Verify that margin field of Sale Order Lines gets bind with the value. + self.assertEqual(sale_order_so13.order_line[0].margin, 70.00, "Sales order profit should be 70.00") + self.assertEqual(sale_order_so13.order_line[0].margin_percent, 1.0, "Sales order margin percentage should be 100.00") + # Verify that margin field gets bind with the value. + self.assertEqual(sale_order_so13.margin, 70.00, "Sales order profit should be 70.00") + self.assertEqual(sale_order_so13.margin_percent, 1.00, "Sales order margin percentage should be 100.00") + + def test_sale_margin3(self): + """ Test the margin and margin percentage when product with multiple quantity""" + sale_order_so14 = self.SaleOrder.create({ + 'date_order': datetime.today(), + 'name': 'Test_SO014', + 'order_line': [ + (0, 0, { + 'name': '[CARD] Individual Workplace', + 'purchase_price': 50.0, + 'price_unit': 100.0, + 'product_uom': self.product_uom_id, + 'product_uom_qty': 3.0, + 'state': 'draft', + 'product_id': self.product_id}), + (0, 0, { + 'name': 'Line without product_uom', + 'price_unit': -50.0, + 'purchase_price': 0.0, + 'product_uom_qty': 1.0, + 'state': 'draft', + 'product_id': self.product_id})], + 'partner_id': self.partner_id, + 'partner_invoice_id': self.partner_invoice_address_id, + 'partner_shipping_id': self.partner_invoice_address_id, + 'pricelist_id': self.pricelist_id}) + # Confirm the sales order. + sale_order_so14.action_confirm() + # Verify that margin field of Sale Order Lines gets bind with the value. + self.assertEqual(sale_order_so14.order_line[0].margin, 150.00, "Sales order profit should be 150.00") + self.assertEqual(sale_order_so14.order_line[0].margin_percent, 0.5, "Sales order margin should be 100%") + self.assertEqual(sale_order_so14.order_line[1].margin, -50.00, "Sales order profit should be -50.00") + self.assertEqual(sale_order_so14.order_line[1].margin_percent, 1.0, "Sales order margin should be 100%") + # Verify that margin field gets bind with the value. + self.assertEqual(sale_order_so14.margin, 100.00, "Sales order profit should be 100.00") + self.assertEqual(sale_order_so14.margin_percent, 0.4, "Sales order margin should be 40%") |
