diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..abbf32c --- /dev/null +++ b/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import report diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..3bf132b --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + + +{ + 'name': 'POS - Sale Margin', + 'version': '1.1', + 'category': 'Hidden', + 'summary': 'Link module between Point of Sale and Sales Margin', + 'description': """ + +This module adds enable you to view the margin of your Point of Sale orders in the Sales Margin report. +""", + 'depends': ['pos_sale', 'sale_margin'], + 'installable': True, + 'auto_install': True, + 'license': 'LGPL-3', +} diff --git a/i18n/pos_sale_margin.pot b/i18n/pos_sale_margin.pot new file mode 100644 index 0000000..f08c75f --- /dev/null +++ b/i18n/pos_sale_margin.pot @@ -0,0 +1,21 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_sale_margin +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-26 21:55+0000\n" +"PO-Revision-Date: 2023-10-26 21:55+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: pos_sale_margin +#: model:ir.model,name:pos_sale_margin.model_sale_report +msgid "Sales Analysis Report" +msgstr "" diff --git a/i18n/ru.po b/i18n/ru.po new file mode 100644 index 0000000..224808e --- /dev/null +++ b/i18n/ru.po @@ -0,0 +1,23 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_sale_margin +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-26 21:55+0000\n" +"PO-Revision-Date: 2024-01-30 15:14+0400\n" +"Last-Translator: \n" +"Language-Team: Russian (https://app.transifex.com/odoo/teams/41243/ru/)\n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);\n" + +#. module: pos_sale_margin +#: model:ir.model,name:pos_sale_margin.model_sale_report +msgid "Sales Analysis Report" +msgstr "Отчет об анализе продаж" diff --git a/report/__init__.py b/report/__init__.py new file mode 100644 index 0000000..7b0761d --- /dev/null +++ b/report/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import sale_report diff --git a/report/sale_report.py b/report/sale_report.py new file mode 100644 index 0000000..9053ea8 --- /dev/null +++ b/report/sale_report.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models + + +class SaleReport(models.Model): + _inherit = "sale.report" + + def _fill_pos_fields(self, additional_fields): + values = super()._fill_pos_fields(additional_fields) + values['margin'] = 'SUM(l.price_subtotal - COALESCE(l.total_cost,0) / CASE COALESCE(pos.currency_rate, 0) WHEN 0 THEN 1.0 ELSE pos.currency_rate END)' + return values diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..a01c088 --- /dev/null +++ b/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_pos_sale_margin_report diff --git a/tests/test_pos_sale_margin_report.py b/tests/test_pos_sale_margin_report.py new file mode 100644 index 0000000..5a61bc4 --- /dev/null +++ b/tests/test_pos_sale_margin_report.py @@ -0,0 +1,43 @@ +# -*- 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 TestPoSSaleMarginReport(TestPoSCommon): + + def setUp(self): + super(TestPoSSaleMarginReport, self).setUp() + self.config = self.basic_config + + def test_pos_sale_margin_report(self): + + product1 = self.create_product('Product 1', self.categ_basic, 150, standard_price=50) + + 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': 450, + 'discount': 5.0, + 'qty': 1.0, + 'price_subtotal': 150, + 'price_subtotal_incl': 150, + 'total_cost': 50, + }),], + '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['sale.report'].sudo().search([('product_id', '=', product1.id)], order='id') + + self.assertEqual(reports[0].margin, 100)