From e8a43ca4f0b18bfa39834667a28d600addf38fb7 Mon Sep 17 00:00:00 2001 From: geomer198 Date: Tue, 4 Jul 2023 16:34:33 +0300 Subject: [PATCH] [ADD] sale_financial_risk_pos_compatibility: Module added --- .../README.rst | 0 .../__init__.py | 1 + .../__manifest__.py | 23 ++++++ .../models/__init__.py | 2 + .../models/pos_config.py | 7 ++ .../models/res_config_settings.py | 9 +++ .../readme/CONFIGURE.rst | 2 + .../readme/DESCRIPTION.rst | 2 + .../static/src/js/CreateOrderButton.esm.js | 36 +++++++++ .../SaleFinancialRiskPosCompatibility.tour.js | 73 +++++++++++++++++++ .../tests/__init__.py | 1 + .../tests/test_module.py | 16 ++++ .../views/res_config_settings_view.xml | 28 +++++++ .../sale_financial_risk_pos_compatibility | 1 + .../setup.py | 6 ++ test-requirements.txt | 1 + 16 files changed, 208 insertions(+) create mode 100644 sale_financial_risk_pos_compatibility/README.rst create mode 100644 sale_financial_risk_pos_compatibility/__init__.py create mode 100644 sale_financial_risk_pos_compatibility/__manifest__.py create mode 100644 sale_financial_risk_pos_compatibility/models/__init__.py create mode 100644 sale_financial_risk_pos_compatibility/models/pos_config.py create mode 100644 sale_financial_risk_pos_compatibility/models/res_config_settings.py create mode 100644 sale_financial_risk_pos_compatibility/readme/CONFIGURE.rst create mode 100644 sale_financial_risk_pos_compatibility/readme/DESCRIPTION.rst create mode 100644 sale_financial_risk_pos_compatibility/static/src/js/CreateOrderButton.esm.js create mode 100644 sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js create mode 100644 sale_financial_risk_pos_compatibility/tests/__init__.py create mode 100644 sale_financial_risk_pos_compatibility/tests/test_module.py create mode 100644 sale_financial_risk_pos_compatibility/views/res_config_settings_view.xml create mode 120000 setup/sale_financial_risk_pos_compatibility/odoo/addons/sale_financial_risk_pos_compatibility create mode 100644 setup/sale_financial_risk_pos_compatibility/setup.py create mode 100644 test-requirements.txt diff --git a/sale_financial_risk_pos_compatibility/README.rst b/sale_financial_risk_pos_compatibility/README.rst new file mode 100644 index 0000000000..e69de29bb2 diff --git a/sale_financial_risk_pos_compatibility/__init__.py b/sale_financial_risk_pos_compatibility/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/sale_financial_risk_pos_compatibility/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_financial_risk_pos_compatibility/__manifest__.py b/sale_financial_risk_pos_compatibility/__manifest__.py new file mode 100644 index 0000000000..c8879ca1b2 --- /dev/null +++ b/sale_financial_risk_pos_compatibility/__manifest__.py @@ -0,0 +1,23 @@ +{ + "name": "Sale Financial Risk Pos Compatibility", + "version": "16.0.1.0.0", + "category": "Sales/Point of Sale", + "summary": "Sale Financial Risk Pos Compatibility", + "depends": ["pos_financial_risk", "pos_order_to_sale_order"], + "website": "https://github.com/OCA/pos", + "author": "Cetmix,Odoo Community Association (OCA)", + "maintainers": ["geomer198", "CetmixGitDrone"], + "data": [ + "views/res_config_settings_view.xml", + ], + "installable": True, + "assets": { + "point_of_sale.assets": [ + "sale_financial_risk_pos_compatibility/static/src/js/CreateOrderButton.esm.js", + ], + "web.assets_tests": [ + "sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js", # noqa + ], + }, + "license": "AGPL-3", +} diff --git a/sale_financial_risk_pos_compatibility/models/__init__.py b/sale_financial_risk_pos_compatibility/models/__init__.py new file mode 100644 index 0000000000..2b92809a3b --- /dev/null +++ b/sale_financial_risk_pos_compatibility/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_config +from . import res_config_settings diff --git a/sale_financial_risk_pos_compatibility/models/pos_config.py b/sale_financial_risk_pos_compatibility/models/pos_config.py new file mode 100644 index 0000000000..9e4eceedcb --- /dev/null +++ b/sale_financial_risk_pos_compatibility/models/pos_config.py @@ -0,0 +1,7 @@ +from odoo import fields, models + + +class PosConfig(models.Model): + _inherit = "pos.config" + + active_financial_risk = fields.Boolean() diff --git a/sale_financial_risk_pos_compatibility/models/res_config_settings.py b/sale_financial_risk_pos_compatibility/models/res_config_settings.py new file mode 100644 index 0000000000..453bb3c417 --- /dev/null +++ b/sale_financial_risk_pos_compatibility/models/res_config_settings.py @@ -0,0 +1,9 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + pos_active_financial_risk = fields.Boolean( + related="pos_config_id.active_financial_risk", readonly=False + ) diff --git a/sale_financial_risk_pos_compatibility/readme/CONFIGURE.rst b/sale_financial_risk_pos_compatibility/readme/CONFIGURE.rst new file mode 100644 index 0000000000..daeff6d1cc --- /dev/null +++ b/sale_financial_risk_pos_compatibility/readme/CONFIGURE.rst @@ -0,0 +1,2 @@ +Go to Point of Sale's settings page and activate financial risk functional for a +specific PoS configuration. diff --git a/sale_financial_risk_pos_compatibility/readme/DESCRIPTION.rst b/sale_financial_risk_pos_compatibility/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..4b92abe679 --- /dev/null +++ b/sale_financial_risk_pos_compatibility/readme/DESCRIPTION.rst @@ -0,0 +1,2 @@ +This module is a bridging module between **sale_financial_risk** and **pos_order_to_sale_order**. It implements control for the Sale Orders created from POS. +Same warning or blocking message will be displayed in POS as if an order was created from the backend. diff --git a/sale_financial_risk_pos_compatibility/static/src/js/CreateOrderButton.esm.js b/sale_financial_risk_pos_compatibility/static/src/js/CreateOrderButton.esm.js new file mode 100644 index 0000000000..9d634a2fc5 --- /dev/null +++ b/sale_financial_risk_pos_compatibility/static/src/js/CreateOrderButton.esm.js @@ -0,0 +1,36 @@ +/** @odoo-module **/ + +import CreateOrderButton from "point_of_sale.CreateOrderButton"; +import Registries from "point_of_sale.Registries"; +import {_t} from "web.core"; + +export const CreateOrderRiskButton = (CreateOrderButton) => + class CreateOrderRiskButton extends CreateOrderButton { + async onClick() { + if (!this.env.pos.config.active_financial_risk) { + return super.onClick(); + } + const order = this.env.pos.get_order(); + const partner = order.partner; + if (!partner) { + return super.onClick(); + } + const partnerFields = await this.rpc({ + model: "res.partner", + method: "read", + args: [partner.id, ["risk_total"]], + }); + if ( + order.get_total_with_tax() + order.get_rounding_applied() > + partnerFields[0].risk_total + ) { + return await this.showPopup("ErrorPopup", { + title: _t("Cannot confirm order"), + body: _t("Order total exceeds customer credit limit"), + }); + } + return super.onClick(); + } + }; + +Registries.Component.extend(CreateOrderButton, CreateOrderRiskButton); diff --git a/sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js b/sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js new file mode 100644 index 0000000000..8b6a3cd758 --- /dev/null +++ b/sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js @@ -0,0 +1,73 @@ +odoo.define( + "sale_financial_risk_pos_compatibility.SaleFinancialRiskPosCompatibility", + function (require) { + "use strict"; + + const Tour = require("web_tour.tour"); + + const steps = [ + { + content: + "Test sale_financial_risk_pos_compatibility: Waiting for loading to finish", + trigger: "body:not(:has(.loader))", + // eslint-disable-next-line no-empty-function + run: () => {}, + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Close Opening cashbox popup", + trigger: "div.opening-cash-control .button:contains('Open session')", + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Leave category displayed by default", + trigger: ".breadcrumb-home", + // eslint-disable-next-line no-empty-function + run: () => {}, + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Order a 'Whiteboard Pen' (price 3.20)", + trigger: ".product-list .product-name:contains('Whiteboard Pen')", + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Click on 'Customer' Button", + trigger: "button.set-partner", + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Select a customer 'Addison Olson'", + trigger: "tr.partner-line td div:contains('Addison Olson')", + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Click on 'Create Order' Button", + trigger: "span.control-button span:contains('Create Order')", + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Error popup click on 'Ok' Button", + trigger: "div.popup-error .button:contains('Ok')", + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Close the Point of Sale frontend", + trigger: ".header-button", + }, + { + content: + "Test sale_financial_risk_pos_compatibility: Confirm closing the frontend", + trigger: ".header-button", + // eslint-disable-next-line no-empty-function + run: () => {}, + }, + ]; + + Tour.register( + "SaleFinancialRiskPosCompatibility", + {test: true, url: "/pos/ui"}, + steps + ); + } +); diff --git a/sale_financial_risk_pos_compatibility/tests/__init__.py b/sale_financial_risk_pos_compatibility/tests/__init__.py new file mode 100644 index 0000000000..d9b96c4fa5 --- /dev/null +++ b/sale_financial_risk_pos_compatibility/tests/__init__.py @@ -0,0 +1 @@ +from . import test_module diff --git a/sale_financial_risk_pos_compatibility/tests/test_module.py b/sale_financial_risk_pos_compatibility/tests/test_module.py new file mode 100644 index 0000000000..e2b5ecfd98 --- /dev/null +++ b/sale_financial_risk_pos_compatibility/tests/test_module.py @@ -0,0 +1,16 @@ +from odoo.tests import tagged + +from odoo.addons.point_of_sale.tests.test_frontend import TestPointOfSaleHttpCommon + + +@tagged("post_install", "-at_install") +class TestUI(TestPointOfSaleHttpCommon): + def test_sale_financial_risk_pos_compatibility(self): + self.main_pos_config.active_financial_risk = True + self.main_pos_config.open_ui() + + self.start_tour( + f"/pos/ui?config_id={self.main_pos_config.id}", + "SaleFinancialRiskPosCompatibility", + login="accountman", + ) diff --git a/sale_financial_risk_pos_compatibility/views/res_config_settings_view.xml b/sale_financial_risk_pos_compatibility/views/res_config_settings_view.xml new file mode 100644 index 0000000000..b9db15112e --- /dev/null +++ b/sale_financial_risk_pos_compatibility/views/res_config_settings_view.xml @@ -0,0 +1,28 @@ + + + + + res.config.settings.view.form + res.config.settings + + + +
+
+
+ +
+
+
+
+ + + + + diff --git a/setup/sale_financial_risk_pos_compatibility/odoo/addons/sale_financial_risk_pos_compatibility b/setup/sale_financial_risk_pos_compatibility/odoo/addons/sale_financial_risk_pos_compatibility new file mode 120000 index 0000000000..f494a185ad --- /dev/null +++ b/setup/sale_financial_risk_pos_compatibility/odoo/addons/sale_financial_risk_pos_compatibility @@ -0,0 +1 @@ +../../../../sale_financial_risk_pos_compatibility \ No newline at end of file diff --git a/setup/sale_financial_risk_pos_compatibility/setup.py b/setup/sale_financial_risk_pos_compatibility/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/sale_financial_risk_pos_compatibility/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..eccd787eb9 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-pos_financial_risk @ git+https://github.com/OCA/pos.git@refs/pull/1018/head#subdirectory=setup/pos_financial_risk