Skip to content

Commit

Permalink
[FIX] sale_financial_risk_pos_compatibility: Js code is changed.
Browse files Browse the repository at this point in the history
  • Loading branch information
geomer198 committed Sep 6, 2023
1 parent b7df021 commit bbbff55
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 35 deletions.
1 change: 1 addition & 0 deletions sale_financial_risk_pos_compatibility/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from . import pos_session
from . import sale_order
11 changes: 11 additions & 0 deletions sale_financial_risk_pos_compatibility/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/** @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);
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
28 changes: 28 additions & 0 deletions sale_financial_risk_pos_compatibility/static/src/js/models.esm.js
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit bbbff55

Please sign in to comment.