From 7d9035c79a98b0715a793cbdfa520ed277f8ec4a Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Tue, 28 Mar 2023 11:27:21 +0000 Subject: [PATCH] [FIX] point_of_sale: Correct margin for product with no cost Current behavior: In the pos order report the margin is not shown for products with no cost. Steps to reproduce: - Create a product with no cost - Open a pos session, add the product to the order and validate it - Go to the pos order report and check the margin for the product - The margin is not shown opw-3232131 closes odoo/odoo#117723 X-original-commit: 223400d371615907a7ba7d5616ffeec307892f16 Signed-off-by: Trinh Jacky (trj) Signed-off-by: Engels Robin (roen) --- .../point_of_sale/report/pos_order_report.py | 2 +- addons/point_of_sale/tests/__init__.py | 1 + .../tests/test_report_pos_order.py | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 addons/point_of_sale/tests/test_report_pos_order.py diff --git a/addons/point_of_sale/report/pos_order_report.py b/addons/point_of_sale/report/pos_order_report.py index c0b483de991..f3169a0fe0a 100644 --- a/addons/point_of_sale/report/pos_order_report.py +++ b/addons/point_of_sale/report/pos_order_report.py @@ -66,7 +66,7 @@ class PosOrderReport(models.Model): s.pricelist_id, s.session_id, s.account_move IS NOT NULL AS invoiced, - SUM(l.price_subtotal - l.total_cost / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) AS margin + SUM(l.price_subtotal - COALESCE(l.total_cost,0) / CASE COALESCE(s.currency_rate, 0) WHEN 0 THEN 1.0 ELSE s.currency_rate END) AS margin """ def _from(self): diff --git a/addons/point_of_sale/tests/__init__.py b/addons/point_of_sale/tests/__init__.py index b2f9e832f77..488ae8db501 100644 --- a/addons/point_of_sale/tests/__init__.py +++ b/addons/point_of_sale/tests/__init__.py @@ -17,4 +17,5 @@ from . import test_pos_other_currency_config from . import test_pos_with_fiscal_position from . import test_pos_stock_account from . import test_js +from . import test_report_pos_order from . import test_res_config_settings diff --git a/addons/point_of_sale/tests/test_report_pos_order.py b/addons/point_of_sale/tests/test_report_pos_order.py new file mode 100644 index 00000000000..0aa069129f6 --- /dev/null +++ b/addons/point_of_sale/tests/test_report_pos_order.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +import odoo + +from odoo.addons.point_of_sale.tests.common import TestPoSCommon + +@odoo.tests.tagged('post_install', '-at_install') +class TestReportPoSOrder(TestPoSCommon): + + def setUp(self): + super(TestReportPoSOrder, self).setUp() + self.config = self.basic_config + + def test_report_pos_order(self): + + product1 = self.create_product('Product 1', self.categ_basic, 150) + + self.open_new_session() + session = self.pos_session + + self.env['pos.order'].create({ + 'session_id': session.id, + 'lines': [(0, 0, { + 'name': "OL/0001", + 'product_id': product1.id, + 'price_unit': 150, + 'discount': 0, + 'qty': 1.0, + 'price_subtotal': 150, + 'price_subtotal_incl': 150, + }),], + 'amount_total': 150.0, + 'amount_tax': 0.0, + 'amount_paid': 0.0, + 'amount_return': 0.0, + }) + + # PoS Orders have negative IDs to avoid conflict, so reports[0] will correspond to the newest order + reports = self.env['report.pos.order'].sudo().search([('product_id', '=', product1.id)], order='id') + + self.assertEqual(reports[0].margin, 150)