From 8cf2faa6d2642c342632874f61ebe4d15c134dff Mon Sep 17 00:00:00 2001 From: geomer198 Date: Wed, 6 Sep 2023 03:33:18 +0300 Subject: [PATCH] [FIX] sale_financial_risk_pos_compatibility: Js code is changed. --- .../__manifest__.py | 1 - .../models/__init__.py | 1 + .../models/sale_order.py | 11 +++++ .../static/src/js/ConfirmRiskPopup.esm.js | 13 ----- .../static/src/js/CreateOrderPopup.esm.js | 48 +++++++------------ .../static/src/js/models.esm.js | 28 +++++++++++ .../static/src/xml/ConfirmRiskPopup.xml | 15 ------ 7 files changed, 56 insertions(+), 61 deletions(-) create mode 100644 sale_financial_risk_pos_compatibility/models/sale_order.py delete mode 100644 sale_financial_risk_pos_compatibility/static/src/js/ConfirmRiskPopup.esm.js create mode 100644 sale_financial_risk_pos_compatibility/static/src/js/models.esm.js delete mode 100644 sale_financial_risk_pos_compatibility/static/src/xml/ConfirmRiskPopup.xml diff --git a/sale_financial_risk_pos_compatibility/__manifest__.py b/sale_financial_risk_pos_compatibility/__manifest__.py index de2670fc61..342b07c99b 100644 --- a/sale_financial_risk_pos_compatibility/__manifest__.py +++ b/sale_financial_risk_pos_compatibility/__manifest__.py @@ -12,7 +12,6 @@ "assets": { "point_of_sale.assets": [ "sale_financial_risk_pos_compatibility/static/src/js/*.esm.js", - "sale_financial_risk_pos_compatibility/static/src/xml/*.xml", ], "web.assets_tests": [ "sale_financial_risk_pos_compatibility/static/src/tests/tours/SaleFinancialRiskPosCompatibility.tour.js", # noqa diff --git a/sale_financial_risk_pos_compatibility/models/__init__.py b/sale_financial_risk_pos_compatibility/models/__init__.py index f7116e3d45..77ec692e71 100644 --- a/sale_financial_risk_pos_compatibility/models/__init__.py +++ b/sale_financial_risk_pos_compatibility/models/__init__.py @@ -1 +1,2 @@ from . import pos_session +from . import sale_order diff --git a/sale_financial_risk_pos_compatibility/models/sale_order.py b/sale_financial_risk_pos_compatibility/models/sale_order.py new file mode 100644 index 0000000000..34281bd17e --- /dev/null +++ b/sale_financial_risk_pos_compatibility/models/sale_order.py @@ -0,0 +1,11 @@ +from odoo import api, models + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + @api.model + def create_order_from_pos(self, order_data, action): + if "bypass_risk" in order_data: + self = self.with_context(bypass_risk=order_data.get("bypass_risk")) + return super(SaleOrder, self).create_order_from_pos(order_data, action) diff --git a/sale_financial_risk_pos_compatibility/static/src/js/ConfirmRiskPopup.esm.js b/sale_financial_risk_pos_compatibility/static/src/js/ConfirmRiskPopup.esm.js deleted file mode 100644 index 66b1690927..0000000000 --- a/sale_financial_risk_pos_compatibility/static/src/js/ConfirmRiskPopup.esm.js +++ /dev/null @@ -1,13 +0,0 @@ -/** @odoo-module **/ - -import ConfirmPopup from "point_of_sale.ConfirmPopup"; -import Registries from "point_of_sale.Registries"; - -export class ConfirmRiskPopup extends ConfirmPopup {} -ConfirmRiskPopup.template = "ConfirmRiskPopup"; -ConfirmRiskPopup.defaultProps = { - ...ConfirmPopup.defaultProps, - showButton: false, -}; - -Registries.Component.add(ConfirmRiskPopup); diff --git a/sale_financial_risk_pos_compatibility/static/src/js/CreateOrderPopup.esm.js b/sale_financial_risk_pos_compatibility/static/src/js/CreateOrderPopup.esm.js index 33e2728e69..200ff42c85 100644 --- a/sale_financial_risk_pos_compatibility/static/src/js/CreateOrderPopup.esm.js +++ b/sale_financial_risk_pos_compatibility/static/src/js/CreateOrderPopup.esm.js @@ -2,7 +2,6 @@ import CreateOrderPopup from "point_of_sale.CreateOrderPopup"; import Registries from "point_of_sale.Registries"; -import framework from "web.framework"; export const CreateOrderPopupRisk = (CreateOrderPopup) => class CreateOrderPopupRisk extends CreateOrderPopup { @@ -50,40 +49,25 @@ export const CreateOrderPopupRisk = (CreateOrderPopup) => } else { return await super._actionCreateSaleOrder(order_state); } - const {confirmed} = await this.showPopup("ConfirmRiskPopup", { - title: "Partner risk exceeded", - body: exception_msg, - showButton: this.env.pos.user.has_role_risk_manager, - }); - if (confirmed) { - this.extraContext = {context: {bypass_risk: true}}; - return await super._actionCreateSaleOrder(order_state); + if (this.env.pos.user.has_role_risk_manager) { + const {confirmed} = await this.showPopup("ConfirmPopup", { + title: this.env._t("Partner risk exceeded"), + body: exception_msg, + }); + if (confirmed) { + order.set_bypass_risk(true); + const result = await super._actionCreateSaleOrder(order_state); + order.set_bypass_risk(false); + return result; + } + } else { + await this.showPopup("ErrorPopup", { + title: this.env._t("Partner risk exceeded"), + body: exception_msg, + }); } return await this.cancel(); } - - async _createSaleOrder(order_state) { - if (!this.extraContext) { - return await super._createSaleOrder(order_state); - } - const current_order = this.env.pos.get_order(); - framework.blockUI(); - const request = { - model: "sale.order", - method: "create_order_from_pos", - args: [current_order.export_as_JSON(), order_state], - }; - if (this.extraContext) { - request.kwargs = this.extraContext; - } - return await this.rpc(request) - .catch(function (error) { - throw error; - }) - .finally(function () { - framework.unblockUI(); - }); - } }; Registries.Component.extend(CreateOrderPopup, CreateOrderPopupRisk); diff --git a/sale_financial_risk_pos_compatibility/static/src/js/models.esm.js b/sale_financial_risk_pos_compatibility/static/src/js/models.esm.js new file mode 100644 index 0000000000..62b51ddf5b --- /dev/null +++ b/sale_financial_risk_pos_compatibility/static/src/js/models.esm.js @@ -0,0 +1,28 @@ +/** @odoo-module **/ + +import {Order} from "point_of_sale.models"; +import Registries from "point_of_sale.Registries"; + +const PosSaleFinancialRiskOrder = (Order) => + class PosSaleFinancialRiskOrder extends Order { + constructor() { + super(...arguments); + this.bypass_risk = false; + } + set_bypass_risk(bypass_risk) { + this.bypass_risk = bypass_risk; + } + export_as_JSON() { + const result = super.export_as_JSON(...arguments); + result.bypass_risk = this.bypass_risk; + return result; + } + init_from_JSON(json) { + super.init_from_JSON(...arguments); + this.bypass_risk = json.bypass_risk; + } + }; + +Registries.Model.extend(Order, PosSaleFinancialRiskOrder); + +export default PosSaleFinancialRiskOrder; diff --git a/sale_financial_risk_pos_compatibility/static/src/xml/ConfirmRiskPopup.xml b/sale_financial_risk_pos_compatibility/static/src/xml/ConfirmRiskPopup.xml deleted file mode 100644 index b8e8ba6e39..0000000000 --- a/sale_financial_risk_pos_compatibility/static/src/xml/ConfirmRiskPopup.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - props.showButton - - - -