i have module for delivery boys and i can assign the order to one of delivery boys and his name but i want to extend it to add delivery fees which is 10SAR
i have created new product and named i Delivery Fee with barcode delivery12345 and the price and i was trying to extend the delivery boy assignment logic to add the product to the cart automatically when the delivery boy is chosen
import { usePos } from "@point_of_sale/app/store/pos_hook";
import { ProductScreen } from "@point_of_sale/app/screens/product_screen/product_screen";
import { Component } from "@odoo/owl";
import { _t } from "@web/core/l10n/translation";
import { AlertDialog } from "@web/core/confirmation_dialog/confirmation_dialog";
import { SelectionPopup } from "@point_of_sale/app/utils/input_popups/selection_popup";
import { Dialog } from "@web/core/dialog/dialog";
import { ControlButtons } from "@point_of_sale/app/screens/product_screen/control_buttons/control_buttons";
import { patch } from "@web/core/utils/patch";
import { useService } from "@web/core/utils/hooks";
import { makeAwaitable } from "@point_of_sale/app/store/make_awaitable_dialog";
patch(ControlButtons.prototype, {
setup() {
this.dialog = useService("dialog");
super.setup();
},
async confirmdelivery() {
const order = this.pos.get_order();
// Validate the order is not empty
if (order.get_orderlines().length === 0) {
this.dialog.add(AlertDialog, {
title: _t("Empty Order"),
body: _t("Please add at least one product to the order."),
});
return;
}
// Dynamically create the delivery fee product data
const deliveryFeeProduct = {
id: "delivery_fee_product", // Unique ID for virtual product
display_name: "Delivery fee", // Product name
list_price: 10, // Product price
taxes_id: [], // No tax
to_weight: false, // Not a weighted product
uom_id: [1, "Units"], // Unit of measure
};
// Create a new order line with the delivery fee product
const deliveryLine = new this.pos.models.Orderline(
{
product_id: deliveryFeeProduct,
price_unit: deliveryFeeProduct.list_price,
quantity: 1,
taxes_id: deliveryFeeProduct.taxes_id,
},
{ pos: this.pos, order: order }
);
// Add the order line to the current order
order.orderlines.add(deliveryLine);
console.log("Delivery Fee product added successfully.");
// Show delivery boy selection popup
const deliveryBoys = this.pos.pos_custom_delivery_boy || [];
if (deliveryBoys.length === 0) {
this.dialog.add(AlertDialog, {
title: _t("No Delivery Boys"),
body: _t("No delivery boys are configured. Please configure them first."),
});
return;
}
const selectionList = deliveryBoys.map((boy) => ({
id: boy.id,
label: boy.delivery_boy_name,
isSelected: false,
}));
this.dialog.add(SelectionPopup, {
title: _t("Select Delivery Boy"),
list: selectionList,
getPayload: async (value) => {
console.log("Selected Delivery Boy:", value);
order.set_delivery_boy(value.delivery_boy_name);
order.update({ delivery_boy_id: value.id });
},
});
},
});