| 1 |
# -*- coding: utf-8 -*- |
| 2 |
# Part of Odoo. See LICENSE file for full copyright and licensing details. |
| 3 |
import odoo |
| 4 |
|
| 5 |
from odoo.addons.point_of_sale.tests.common import TestPoSCommon |
| 6 |
|
| 7 |
@odoo.tests.tagged('post_install', '-at_install') |
| 8 |
class TestReportPoSOrder(TestPoSCommon): |
| 9 |
|
| 10 |
def setUp(self): |
| 11 |
super(TestReportPoSOrder, self).setUp() |
| 12 |
self.config = self.basic_config |
| 13 |
|
| 14 |
def test_report_pos_order_0(self): |
| 15 |
"""Test the margin and price_total of a PoS Order with no taxes.""" |
| 16 |
product1 = self.create_product('Product 1', self.categ_basic, 150) |
| 17 |
self.categ_all = self.env['pos.category'].search([]) |
| 18 |
product1.write({'pos_categ_ids': [odoo.Command.set(self.categ_all.ids)]}) |
| 19 |
|
| 20 |
self.open_new_session() |
| 21 |
session = self.pos_session |
| 22 |
self.env['pos.order'].create({ |
| 23 |
'session_id': session.id, |
| 24 |
'lines': [ |
| 25 |
(0, 0, { |
| 26 |
'name': "OL/0001", |
| 27 |
'product_id': product1.id, |
| 28 |
'price_unit': 150, |
| 29 |
'discount': 0, |
| 30 |
'qty': 1.0, |
| 31 |
'price_subtotal': 150, |
| 32 |
'price_subtotal_incl': 150, |
| 33 |
}) |
| 34 |
], |
| 35 |
'amount_total': 150.0, |
| 36 |
'amount_tax': 0.0, |
| 37 |
'amount_paid': 0.0, |
| 38 |
'amount_return': 0.0, |
| 39 |
}) |
| 40 |
# PoS Orders have negative IDs to avoid conflict, so reports[0] will correspond to the newest order |
| 41 |
reports = self.env['report.pos.order'].sudo().search([('product_id', '=', product1.id)], order='id') |
| 42 |
|
| 43 |
self.assertEqual(len(reports.ids), 1) |
| 44 |
self.assertEqual(reports[0].margin, 150) |
| 45 |
self.assertEqual(reports[0].price_total, 150) |
| 46 |
|
| 47 |
def test_report_pos_order_1(self): |
| 48 |
"""Test the margin and price_total of a PoS Order with taxes.""" |
| 49 |
|
| 50 |
product1 = self.create_product('Product 1', self.categ_basic, 150, self.taxes['tax10'].id) |
| 51 |
|
| 52 |
self.open_new_session() |
| 53 |
session = self.pos_session |
| 54 |
|
| 55 |
self.env['pos.order'].create({ |
| 56 |
'session_id': session.id, |
| 57 |
'lines': [(0, 0, { |
| 58 |
'name': "OL/0001", |
| 59 |
'product_id': product1.id, |
| 60 |
'price_unit': 150, |
| 61 |
'discount': 0, |
| 62 |
'qty': 1.0, |
| 63 |
'price_subtotal': 150, |
| 64 |
'price_subtotal_incl': 165, |
| 65 |
}),], |
| 66 |
'amount_total': 165.0, |
| 67 |
'amount_tax': 15.0, |
| 68 |
'amount_paid': 0.0, |
| 69 |
'amount_return': 0.0, |
| 70 |
}) |
| 71 |
|
| 72 |
# PoS Orders have negative IDs to avoid conflict, so reports[0] will correspond to the newest order |
| 73 |
reports = self.env['report.pos.order'].sudo().search([('product_id', '=', product1.id)], order='id') |
| 74 |
|
| 75 |
self.assertEqual(reports[0].margin, 150) |
| 76 |
self.assertEqual(reports[0].price_total, 165) |
| 77 |
|
| 78 |
def test_report_pos_order_2(self): |
| 79 |
"""Test the margin and price_total of a PoS Order with discount and no taxes""" |
| 80 |
|
| 81 |
product1 = self.create_product('Product 1', self.categ_basic, 150) |
| 82 |
|
| 83 |
self.open_new_session() |
| 84 |
session = self.pos_session |
| 85 |
|
| 86 |
self.env['pos.order'].create({ |
| 87 |
'session_id': session.id, |
| 88 |
'lines': [ |
| 89 |
(0, 0, { |
| 90 |
'name': "OL/0001", |
| 91 |
'product_id': product1.id, |
| 92 |
'price_unit': 150, |
| 93 |
'discount': 10, |
| 94 |
'qty': 1.0, |
| 95 |
'price_subtotal': 135, |
| 96 |
'price_subtotal_incl': 135, |
| 97 |
}) |
| 98 |
], |
| 99 |
'amount_total': 135.0, |
| 100 |
'amount_tax': 0.0, |
| 101 |
'amount_paid': 0.0, |
| 102 |
'amount_return': 0.0, |
| 103 |
}) |
| 104 |
|
| 105 |
# PoS Orders have negative IDs to avoid conflict, so reports[0] will correspond to the newest order |
| 106 |
reports = self.env['report.pos.order'].sudo().search([('product_id', '=', product1.id)], order='id') |
| 107 |
|
| 108 |
self.assertEqual(reports[0].margin, 135) |
| 109 |
self.assertEqual(reports[0].price_total, 135) |