[IMP] point_of_sale, pos*: reference env in models
pos*: pos_loyalty, pos_restaurant, pos_sale, pos_adyen, pos_six, pos_stripe At the moment, the `pos` models don't have access to the `env` variable. This makes using `env` inside a model rather awkward. This PR makes it so all the pos models have access directly to `env`. closes odoo/odoo#124320 Task: 3358456 Related: odoo/enterprise#42209 Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
This commit is contained in:
@@ -24,6 +24,7 @@ export class PaymentInterface {
|
||||
}
|
||||
|
||||
setup(pos, payment_method) {
|
||||
this.env = pos.env;
|
||||
this.pos = pos;
|
||||
this.payment_method = payment_method;
|
||||
this.supports_reversals = false;
|
||||
|
||||
@@ -690,7 +690,7 @@ export class TicketScreen extends Component {
|
||||
// them again, unless invalidated. See `_onInvoiceOrder`.
|
||||
fetchedOrders.forEach((order) => {
|
||||
this._state.syncedOrders.cache[order.id] = new Order(
|
||||
{},
|
||||
{ env: this.env },
|
||||
{ pos: this.pos, json: order }
|
||||
);
|
||||
});
|
||||
|
||||
@@ -121,7 +121,7 @@ export class Product extends PosModel {
|
||||
const attributes = this.attribute_line_ids
|
||||
.map((id) => this.pos.attributes_by_ptal_id[id])
|
||||
.filter((attr) => attr !== undefined);
|
||||
const { confirmed, payload } = await this.pos.env.services.popup.add(
|
||||
const { confirmed, payload } = await this.env.services.popup.add(
|
||||
ProductConfiguratorPopup,
|
||||
{
|
||||
product: this,
|
||||
@@ -200,7 +200,7 @@ export class Product extends PosModel {
|
||||
// Show the ScaleScreen to weigh the product.
|
||||
if (this.isScaleAvailable) {
|
||||
const product = this;
|
||||
const { confirmed, payload } = await this.pos.env.services.pos.showTempScreen(
|
||||
const { confirmed, payload } = await this.env.services.pos.showTempScreen(
|
||||
"ScaleScreen",
|
||||
{
|
||||
product,
|
||||
@@ -392,7 +392,10 @@ export class Orderline extends PosModel {
|
||||
var pack_lot_lines = json.pack_lot_ids;
|
||||
for (var i = 0; i < pack_lot_lines.length; i++) {
|
||||
var packlotline = pack_lot_lines[i][2];
|
||||
var pack_lot_line = new Packlotline({}, { json: { ...packlotline, order_line: this } });
|
||||
var pack_lot_line = new Packlotline(
|
||||
{ env: this.env },
|
||||
{ json: { ...packlotline, order_line: this } }
|
||||
);
|
||||
this.pack_lot_lines.add(pack_lot_line);
|
||||
}
|
||||
this.tax_ids = json.tax_ids && json.tax_ids.length !== 0 ? json.tax_ids[0][2] : undefined;
|
||||
@@ -405,7 +408,7 @@ export class Orderline extends PosModel {
|
||||
}
|
||||
clone() {
|
||||
var orderline = new Orderline(
|
||||
{},
|
||||
{ env: this.env },
|
||||
{
|
||||
pos: this.pos,
|
||||
order: this.order,
|
||||
@@ -467,7 +470,7 @@ export class Orderline extends PosModel {
|
||||
// Create new pack lot lines.
|
||||
let newPackLotLine;
|
||||
for (const newLotLine of newPackLotLines) {
|
||||
newPackLotLine = new Packlotline({}, { order_line: this });
|
||||
newPackLotLine = new Packlotline({ env: this.env }, { order_line: this });
|
||||
newPackLotLine.lot_name = newLotLine.lot_name;
|
||||
this.pack_lot_lines.add(newPackLotLine);
|
||||
}
|
||||
@@ -551,7 +554,7 @@ export class Orderline extends PosModel {
|
||||
const maxQtyToRefund =
|
||||
toRefundDetail.orderline.qty - toRefundDetail.orderline.refundedQty;
|
||||
if (quant > 0) {
|
||||
this.pos.env.services.popup.add(ErrorPopup, {
|
||||
this.env.services.popup.add(ErrorPopup, {
|
||||
title: _t("Positive quantity not allowed"),
|
||||
body: _t(
|
||||
"Only a negative quantity is allowed for this refund line. Click on +/- to modify the quantity to be refunded."
|
||||
@@ -563,13 +566,13 @@ export class Orderline extends PosModel {
|
||||
} else if (-quant <= maxQtyToRefund) {
|
||||
toRefundDetail.qty = -quant;
|
||||
} else {
|
||||
this.pos.env.services.popup.add(ErrorPopup, {
|
||||
this.env.services.popup.add(ErrorPopup, {
|
||||
title: _t("Greater than allowed"),
|
||||
body: sprintf(
|
||||
_t(
|
||||
"The requested quantity to be refunded is higher than the refundable quantity of %s."
|
||||
),
|
||||
this.pos.env.utils.formatProductQty(maxQtyToRefund)
|
||||
this.env.utils.formatProductQty(maxQtyToRefund)
|
||||
),
|
||||
});
|
||||
return false;
|
||||
@@ -1385,7 +1388,10 @@ export class Order extends PosModel {
|
||||
var orderline = orderlines[i][2];
|
||||
if (orderline.product_id && this.pos.db.get_product_by_id(orderline.product_id)) {
|
||||
this.add_orderline(
|
||||
new Orderline({}, { pos: this.pos, order: this, json: orderline })
|
||||
new Orderline(
|
||||
{ env: this.env },
|
||||
{ pos: this.pos, order: this, json: orderline }
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1393,7 +1399,10 @@ export class Order extends PosModel {
|
||||
var paymentlines = json.statement_ids;
|
||||
for (i = 0; i < paymentlines.length; i++) {
|
||||
var paymentline = paymentlines[i][2];
|
||||
var newpaymentline = new Payment({}, { pos: this.pos, order: this, json: paymentline });
|
||||
var newpaymentline = new Payment(
|
||||
{ env: this.env },
|
||||
{ pos: this.pos, order: this, json: paymentline }
|
||||
);
|
||||
this.paymentlines.add(newpaymentline);
|
||||
|
||||
if (i === paymentlines.length - 1) {
|
||||
@@ -1748,7 +1757,7 @@ export class Order extends PosModel {
|
||||
) &&
|
||||
(this.pos.picking_type.use_create_lots || this.pos.picking_type.use_existing_lots)
|
||||
) {
|
||||
const { confirmed } = await this.pos.env.services.popup.add(ConfirmPopup, {
|
||||
const { confirmed } = await this.env.services.popup.add(ConfirmPopup, {
|
||||
title: _t("Some Serial/Lot Numbers are missing"),
|
||||
body: _t(
|
||||
"You are trying to sell products with serial/lot numbers, but some of them are not set.\nWould you like to proceed anyway?"
|
||||
@@ -1758,11 +1767,11 @@ export class Order extends PosModel {
|
||||
});
|
||||
if (confirmed) {
|
||||
this.pos.mobile_pane = "right";
|
||||
this.pos.env.services.pos.showScreen("PaymentScreen");
|
||||
this.env.services.pos.showScreen("PaymentScreen");
|
||||
}
|
||||
} else {
|
||||
this.pos.mobile_pane = "right";
|
||||
this.pos.env.services.pos.showScreen("PaymentScreen");
|
||||
this.env.services.pos.showScreen("PaymentScreen");
|
||||
}
|
||||
}
|
||||
is_empty() {
|
||||
@@ -1979,7 +1988,7 @@ export class Order extends PosModel {
|
||||
options = options || {};
|
||||
const quantity = options.quantity ? options.quantity : 1;
|
||||
const line = new Orderline(
|
||||
{},
|
||||
{ env: this.env },
|
||||
{ pos: this.pos, order: this, product: product, quantity: quantity }
|
||||
);
|
||||
this.fix_tax_included_price(line);
|
||||
@@ -2089,7 +2098,7 @@ export class Order extends PosModel {
|
||||
return false;
|
||||
} else {
|
||||
var newPaymentline = new Payment(
|
||||
{},
|
||||
{ env: this.env },
|
||||
{ order: this, payment_method: payment_method, pos: this.pos }
|
||||
);
|
||||
this.paymentlines.add(newPaymentline);
|
||||
|
||||
@@ -291,6 +291,7 @@ export class PosStore extends Reactive {
|
||||
|
||||
const modelProducts = products.map((product) => {
|
||||
product.pos = this;
|
||||
product.env = this.env;
|
||||
product.applicablePricelistItems = {};
|
||||
productMap[product.id] = product;
|
||||
productTemplateMap[product.product_tmpl_id[0]] = (
|
||||
@@ -501,7 +502,7 @@ export class PosStore extends Reactive {
|
||||
if (json) {
|
||||
options.json = json;
|
||||
}
|
||||
return this.makeOrderReactive(new Order({}, options));
|
||||
return this.makeOrderReactive(new Order({ env: this.env }, options));
|
||||
}
|
||||
makeOrderReactive(order) {
|
||||
const batchedCallback = batched(() => {
|
||||
|
||||
@@ -54,7 +54,7 @@ export class PaymentAdyen extends PaymentInterface {
|
||||
|
||||
_call_adyen(data, operation) {
|
||||
// FIXME POSREF TIMEOUT 10000
|
||||
return this.pos.env.services.orm.silent
|
||||
return this.env.services.orm.silent
|
||||
.call("pos.payment.method", "proxy_adyen_request", [
|
||||
[this.payment_method.id],
|
||||
data,
|
||||
@@ -196,7 +196,7 @@ export class PaymentAdyen extends PaymentInterface {
|
||||
}
|
||||
|
||||
// FIXME POSREF TIMEOUT 5000
|
||||
return this.pos.env.services.orm.silent
|
||||
return this.env.services.orm.silent
|
||||
.call("pos.payment.method", "get_latest_adyen_status", [
|
||||
[this.payment_method.id],
|
||||
this._adyen_get_sale_id(),
|
||||
@@ -345,7 +345,7 @@ export class PaymentAdyen extends PaymentInterface {
|
||||
if (!title) {
|
||||
title = _t("Adyen Error");
|
||||
}
|
||||
this.pos.env.services.popup.add(ErrorPopup, {
|
||||
this.env.services.popup.add(ErrorPopup, {
|
||||
title: title,
|
||||
body: msg,
|
||||
});
|
||||
|
||||
@@ -239,7 +239,7 @@ patch(PosStore.prototype, "pos_loyalty.PosStore", {
|
||||
}
|
||||
const index = this.rewards.indexOf(reward);
|
||||
if (index != -1) {
|
||||
this.pos.env.services.popup.add(ErrorPopup, {
|
||||
this.env.services.popup.add(ErrorPopup, {
|
||||
title: _t("A reward could not be loaded"),
|
||||
body: sprintf(
|
||||
_t(
|
||||
|
||||
@@ -195,13 +195,13 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
(line) => line.getEWalletGiftCardProgramType() === "ewallet"
|
||||
);
|
||||
if (eWalletLine && !this.get_partner()) {
|
||||
const { confirmed } = await this.pos.env.services.popup.add(ConfirmPopup, {
|
||||
const { confirmed } = await this.env.services.popup.add(ConfirmPopup, {
|
||||
title: _t("Customer needed"),
|
||||
body: _t("eWallet requires a customer to be selected"),
|
||||
});
|
||||
if (confirmed) {
|
||||
const { confirmed, payload: newPartner } =
|
||||
await this.pos.env.services.pos.showTempScreen("PartnerListScreen", {
|
||||
await this.env.services.pos.showTempScreen("PartnerListScreen", {
|
||||
partner: null,
|
||||
});
|
||||
if (confirmed) {
|
||||
@@ -1026,7 +1026,10 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
},
|
||||
_createLineFromVals(vals) {
|
||||
vals["lst_price"] = vals["price"];
|
||||
const line = new Orderline({}, { pos: this.pos, order: this, product: vals["product"] });
|
||||
const line = new Orderline(
|
||||
{ env: this.env },
|
||||
{ pos: this.pos, order: this, product: vals["product"] }
|
||||
);
|
||||
this.fix_tax_included_price(line);
|
||||
this.set_orderline_options(line, vals);
|
||||
return line;
|
||||
@@ -1476,7 +1479,7 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
return _t("That coupon code has already been scanned and activated.");
|
||||
}
|
||||
const customer = this.get_partner();
|
||||
const { successful, payload } = await this.pos.env.services.orm.call(
|
||||
const { successful, payload } = await this.env.services.orm.call(
|
||||
"pos.config",
|
||||
"use_coupon_code",
|
||||
[[this.pos.config.id], code, this.creation_date, customer ? customer.id : false]
|
||||
@@ -1485,7 +1488,7 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
// Allow rejecting a gift card that is not yet paid.
|
||||
const program = this.pos.program_by_id[payload.program_id];
|
||||
if (program && program.program_type === "gift_card" && !payload.has_source_order) {
|
||||
const { confirmed } = await this.pos.env.services.popup.add(ConfirmPopup, {
|
||||
const { confirmed } = await this.env.services.popup.add(ConfirmPopup, {
|
||||
title: _t("Unpaid gift card"),
|
||||
body: _t(
|
||||
"This gift card is not linked to any order. Do you really want to apply its reward?"
|
||||
@@ -1523,7 +1526,7 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
return sprintf(
|
||||
_t("Gift Card: %s\nBalance: %s"),
|
||||
code,
|
||||
this.pos.env.utils.formatCurrency(coupon.balance)
|
||||
this.env.utils.formatCurrency(coupon.balance)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
@@ -1531,7 +1534,7 @@ patch(Order.prototype, "pos_loyalty.Order", {
|
||||
async activateCode(code) {
|
||||
const res = await this._activateCode(code);
|
||||
if (res !== true) {
|
||||
this.pos.env.services.pos_notification.add(res, 5000);
|
||||
this.env.services.pos_notification.add(res, 5000);
|
||||
}
|
||||
},
|
||||
isProgramsResettable() {
|
||||
|
||||
@@ -19,7 +19,7 @@ export class SplitBillScreen extends Component {
|
||||
this.newOrder = undefined;
|
||||
this._isFinal = false;
|
||||
this.newOrder = new Order(
|
||||
{},
|
||||
{ env: this.env },
|
||||
{
|
||||
pos: this.pos,
|
||||
temporary: true,
|
||||
|
||||
@@ -207,7 +207,7 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(Component) {
|
||||
}
|
||||
|
||||
const new_line = new Orderline(
|
||||
{},
|
||||
{ env: this.env },
|
||||
{
|
||||
pos: this.pos,
|
||||
order: this.pos.get_order(),
|
||||
@@ -353,7 +353,7 @@ export class SaleOrderManagementScreen extends ControlButtonsMixin(Component) {
|
||||
}
|
||||
|
||||
const new_line = new Orderline(
|
||||
{},
|
||||
{ env: this.env },
|
||||
{
|
||||
pos: this.pos,
|
||||
order: this.pos.get_order(),
|
||||
|
||||
@@ -117,7 +117,7 @@ export class PaymentSix extends PaymentInterface {
|
||||
|
||||
if (event.exception) {
|
||||
if (event.exception.resultCode !== timapi.constants.ResultCode.apiCancelEcr) {
|
||||
this.pos.env.services.popup.add(ErrorPopup, {
|
||||
this.env.services.popup.add(ErrorPopup, {
|
||||
title: _t("Transaction was not processed correctly"),
|
||||
body: event.exception.errorText,
|
||||
});
|
||||
@@ -140,7 +140,7 @@ export class PaymentSix extends PaymentInterface {
|
||||
|
||||
_onBalanceComplete(event, data) {
|
||||
if (event.exception) {
|
||||
this.pos.env.services.popup.add(ErrorPopup, {
|
||||
this.env.services.popup.add(ErrorPopup, {
|
||||
title: _t("Balance Failed"),
|
||||
body: _t("The balance operation failed."),
|
||||
});
|
||||
|
||||
@@ -20,7 +20,7 @@ export class PaymentStripe extends PaymentInterface {
|
||||
async stripeFetchConnectionToken() {
|
||||
// Do not cache or hardcode the ConnectionToken.
|
||||
try {
|
||||
const data = await this.pos.env.services.orm.silent.call(
|
||||
const data = await this.env.services.orm.silent.call(
|
||||
"pos.payment.method",
|
||||
"stripe_connection_token",
|
||||
[]
|
||||
@@ -173,7 +173,7 @@ export class PaymentStripe extends PaymentInterface {
|
||||
|
||||
async capturePayment(paymentIntentId) {
|
||||
try {
|
||||
const data = await this.pos.env.services.orm.silent.call(
|
||||
const data = await this.env.services.orm.silent.call(
|
||||
"pos.payment.method",
|
||||
"stripe_capture_payment",
|
||||
[paymentIntentId]
|
||||
@@ -190,7 +190,7 @@ export class PaymentStripe extends PaymentInterface {
|
||||
|
||||
async fetchPaymentIntentClientSecret(payment_method, amount) {
|
||||
try {
|
||||
const data = await this.pos.env.services.orm.silent.call(
|
||||
const data = await this.env.services.orm.silent.call(
|
||||
"pos.payment.method",
|
||||
"stripe_payment_intent",
|
||||
[[payment_method.id], amount]
|
||||
@@ -259,7 +259,7 @@ export class PaymentStripe extends PaymentInterface {
|
||||
if (!title) {
|
||||
title = _t("Stripe Error");
|
||||
}
|
||||
this.pos.env.services.popup.add(ErrorPopup, {
|
||||
this.env.services.popup.add(ErrorPopup, {
|
||||
title: title,
|
||||
body: msg,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user