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 index 66b1690927..0d7f69e675 100644 --- a/sale_financial_risk_pos_compatibility/static/src/js/ConfirmRiskPopup.esm.js +++ b/sale_financial_risk_pos_compatibility/static/src/js/ConfirmRiskPopup.esm.js @@ -1,7 +1,6 @@ /** @odoo-module **/ import ConfirmPopup from "point_of_sale.ConfirmPopup"; -import Registries from "point_of_sale.Registries"; export class ConfirmRiskPopup extends ConfirmPopup {} ConfirmRiskPopup.template = "ConfirmRiskPopup"; @@ -9,5 +8,3 @@ 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..0ccd394699 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("ConfirmRiskPopup", { + 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;