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/product_margin/tests | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/product_margin/tests')
| -rw-r--r-- | addons/product_margin/tests/__init__.py | 4 | ||||
| -rw-r--r-- | addons/product_margin/tests/test_product_margin.py | 67 |
2 files changed, 71 insertions, 0 deletions
diff --git a/addons/product_margin/tests/__init__.py b/addons/product_margin/tests/__init__.py new file mode 100644 index 00000000..e0b4e4d8 --- /dev/null +++ b/addons/product_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_product_margin diff --git a/addons/product_margin/tests/test_product_margin.py b/addons/product_margin/tests/test_product_margin.py new file mode 100644 index 00000000..161b09d3 --- /dev/null +++ b/addons/product_margin/tests/test_product_margin.py @@ -0,0 +1,67 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.addons.account.tests.common import AccountTestInvoicingCommon +from odoo.tests import tagged + + +@tagged('post_install', '-at_install') +class TestProductMargin(AccountTestInvoicingCommon): + + def test_product_margin(self): + ''' In order to test the product_margin module ''' + + supplier = self.env['res.partner'].create({'name': 'Supplier'}) + customer = self.env['res.partner'].create({'name': 'Customer'}) + ipad = self.env['product.product'].create({ + 'name': 'Ipad', + 'standard_price': 500.0, + 'list_price': 750.0, + }) + + invoices = self.env['account.move'].create([ + { + 'move_type': 'in_invoice', + 'partner_id': supplier.id, + 'invoice_line_ids': [(0, 0, {'product_id': ipad.id, 'quantity': 10.0, 'price_unit': 300.0})], + }, + { + 'move_type': 'in_invoice', + 'partner_id': supplier.id, + 'invoice_line_ids': [(0, 0, {'product_id': ipad.id, 'quantity': 4.0, 'price_unit': 450.0})], + }, + { + 'move_type': 'out_invoice', + 'partner_id': customer.id, + 'invoice_line_ids': [(0, 0, {'product_id': ipad.id, 'quantity': 20.0, 'price_unit': 750.0})], + }, + { + 'move_type': 'out_invoice', + 'partner_id': customer.id, + 'invoice_line_ids': [(0, 0, {'product_id': ipad.id, 'quantity': 10.0, 'price_unit': 550.0})], + }, + ]) + invoices.invoice_date = invoices[0].date + invoices.action_post() + + result = ipad._compute_product_margin_fields_values() + + # Sale turnover ( Quantity * Price Subtotal / Quantity) + sale_turnover = ((20.0 * 750.00) + (10.0 * 550.00)) + + # Expected sale (Total quantity * Sale price) + sale_expected = (750.00 * 30.0) + + # Purchase total cost (Quantity * Unit price) + purchase_total_cost = ((10.0 * 300.00) + (4.0 * 450.00)) + + # Purchase normal cost ( Total quantity * Cost price) + purchase_normal_cost = (14.0 * 500.00) + + total_margin = sale_turnover - purchase_total_cost + expected_margin = sale_expected - purchase_normal_cost + + # Check total margin + self.assertEqual(result[ipad.id]['total_margin'], total_margin, "Wrong Total Margin.") + + # Check expected margin + self.assertEqual(result[ipad.id]['expected_margin'], expected_margin, "Wrong Expected Margin.") |
