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/purchase/tests/test_purchase_order_report.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/purchase/tests/test_purchase_order_report.py')
| -rw-r--r-- | addons/purchase/tests/test_purchase_order_report.py | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/addons/purchase/tests/test_purchase_order_report.py b/addons/purchase/tests/test_purchase_order_report.py new file mode 100644 index 00000000..8b386113 --- /dev/null +++ b/addons/purchase/tests/test_purchase_order_report.py @@ -0,0 +1,68 @@ +# -*- 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 Form, tagged + +from datetime import datetime + + +@tagged('post_install', '-at_install') +class TestPurchaseOrderReport(AccountTestInvoicingCommon): + + def test_00_purchase_order_report(self): + uom_dozen = self.env.ref('uom.product_uom_dozen') + + po = self.env['purchase.order'].create({ + 'partner_id': self.partner_a.id, + 'currency_id': self.currency_data['currency'].id, + 'order_line': [ + (0, 0, { + 'name': self.product_a.name, + 'product_id': self.product_a.id, + 'product_qty': 1.0, + 'product_uom': uom_dozen.id, + 'price_unit': 100.0, + 'date_planned': datetime.today(), + 'taxes_id': False, + }), + (0, 0, { + 'name': self.product_b.name, + 'product_id': self.product_b.id, + 'product_qty': 1.0, + 'product_uom': uom_dozen.id, + 'price_unit': 200.0, + 'date_planned': datetime.today(), + 'taxes_id': False, + }), + ], + }) + po.button_confirm() + + f = Form(self.env['account.move'].with_context(default_move_type='in_invoice')) + f.invoice_date = f.date + f.partner_id = po.partner_id + f.purchase_id = po + invoice = f.save() + invoice.action_post() + po.flush() + + res_product1 = self.env['purchase.report'].search([ + ('order_id', '=', po.id), + ('product_id', '=', self.product_a.id), + ('company_id', '=', self.company_data['company'].id), + ]) + + # check that report will convert dozen to unit or not + self.assertEqual(res_product1.qty_ordered, 12.0, 'UoM conversion is not working') + # report should show in company currency (amount/rate) = (100/2) + self.assertEqual(res_product1.price_total, 50.0, 'Currency conversion is not working') + + res_product2 = self.env['purchase.report'].search([ + ('order_id', '=', po.id), + ('product_id', '=', self.product_b.id), + ('company_id', '=', self.company_data['company'].id), + ]) + + self.assertEqual(res_product2.qty_ordered, 1.0, 'No conversion needed since product_b is already a dozen') + # report should show in company currency (amount/rate) = (200/2) + self.assertEqual(res_product2.price_total, 100.0, 'Currency conversion is not working') |
