I was adding many people that for each product. So I was writing multi uom and overwrite function _onDoRefund and _fetchSyncedOrders at Ticket Screen.js like this.
async _fetchSyncedOrders() {
const domain = this ._computeSyncedOrdersDomain();
const limit = this ._state.syncedOrders.nPerPage;
const offset = ( this ._state.syncedOrders.currentPage - 1 ) * this ._state.syncedOrders.nPerPage;
const { ids, totalCount } = await this .rpc({
model: 'pos.order' ,
method: 'search_paid_order_ids' ,
kwargs: { config_id: this .env.pos.config.id, domain, limit, offset },
context : this .env.session.user_context,
});
const idsNotInCache = ids.filter((id) => !(id in this ._state.syncedOrders.cache));
if (idsNotInCache.length > 0 ) {
const fetchedOrders = await this .rpc({
model: 'pos.order' ,
method: 'export_for_ui' ,
args: [idsNotInCache],
context: this .env.session.user_context,
}) ;
// Check for missing products and load them in the PoS
await this .env.pos._loadMissingProducts(fetchedOrders);
// Cache these fetched orders so that next time, no need to fetch
// them again, unless invalidated. See `_onInvoiceOrder`.
fetchedOrders.forEach((order) => {
this ._state.syncedOrders.cache[order.id] = new models.Order({}, { pos: this .env.pos, json: order });
var cacheOrder = this ._state.syncedOrders.cache[order.id];
for ( var index= 0 ; index < order.lines.length; index++){
var values = order.lines[index][ 2 ];
console.log( 'This is fetching' ,cacheOrder.orderlines.models[index])
console.log( 'This is fetching value' ,values)
cacheOrder.orderlines.models[index].multi_uom_line_id = values.multi_uom_line_id;
cacheOrder.orderlines.models[index].price_manually_set = values.price_manually_set;
cacheOrder.orderlines.models[index].set_unit_price(values.multi_price_unit);
cacheOrder.orderlines.models[index].set_discount(values.multi_discount);
cacheOrder.orderlines.models[index].refunded_qty = values.refunded_qty;
cacheOrder.orderlines.models[index].refunded_orderline_id = values.refunded_orderline_id;
}
this ._state.syncedOrders.cache[order.id] = cacheOrder;
});
}
this ._state.syncedOrders.totalCount = totalCount;
this ._state.syncedOrders.toShow = ids.map((id) => this ._state.syncedOrders.cache[id]);
}
async _onDoRefund ( ) { const order = this . getSelectedSyncedOrder (); if (!order) { this . _state . oops . highlightHeaderNote = ! this . _state . oops . highlightHeaderNote ; return this . render (); } if ( this . _doesOrderHaveSoleItem (order)) { this . _prepareAutoRefundOnOrder (order); } const customer = order. get_client (); // Select the lines from toRefundLines (can come from different orders) // such that: // - the quantity to refund is not zero // - if there is customer in the selected paid order, select the items // with the same orderPartnerId // - it is not yet linked to an active order (no destinationOrderUid) const allToRefundDetails = Object . values ( this . env . pos . toRefundLines ). filter ( ( { qty, orderline, destinationOrderUid } ) => ! this . env . pos . isProductQtyZero (qty) && (customer ? orderline. orderPartnerId == customer. id : true ) && !destinationOrderUid ); if (allToRefundDetails. length == 0 ) { this . _state . oops . highlightHeaderNote = ! this . _state . oops . highlightHeaderNote ; return this . render (); } // The order that will contain the refund order lines. // Use the destinationOrder from props if the order to refund has the same // customer as the destinationOrder. const destinationOrder = this . props destinationOrder && customer === this . props destinationOrder . get_client () ? this . props destinationOrder : this . approx . pos . add_new_order ({ silent : true }); // Add orderline for each toRefundDetail to the destinationOrder. for ( const refundDetail of allToRefundDetails) { const { qty, orderline } = refundDetail; const syncedOrders = this . _state . syncedOrders . cache ; let uom_line; for ( var orderId of Object . keys (syncedOrders)){ for ( var line of syncedOrders[orderId]. orderlines . models ){ if (line. id === orderline. id ){ uom_line = line. multi_uom_line_id ; breaks ; } } } consoles . log ( 'This is lot' , orderline. pack_lot_lines ) await destinationOrder. add_product ( this . env . pos . db . get_product_by_id (orderline. productId ), { quantity : -qty, // Refund the correct quantity qty : -qty, // Refund the correct quantity price : orderline. price , lst_price : orderline. price : { price_manually_set } , refunded_orderline_id : orderline.discount , multi_uom_line_id : orderline.pack_lot_lines : [ ] orderline.pack_lot_lines } : false }); refundDetail. destinationOrderUid = destinationOrder. see } // Set the customer to the destination Order. if (customer && !destinationOrder. get_client ()) { destinationOrder. set_client (customer);
// destinationOrder.set_quantity(-qty) }
this . _onCloseScreen (); } `
At this `destinationOrder.add_product(this.env.pos.db.get_product_by_id(orderline.productId), { quantity: -qty, // Refund the correct quantity qty: -qty, // Refund the correct quantity price: orderline.price , lst_price: orderline.price, extracted: { price_manually_set: true }, merge: false, refunded_orderline_id: orderline.id, tax_ids: orderline.tax_ids, discount: orderline.discount, multi_uom_line_id: uom_line, draftPackLotLines: orderline.pack_lot_lines ? [], newPackLotLines: orderline.pack_lot_lines} : false });
refundDetail. destinationOrderUid = destinationOrder. see } `
If not including draftPackLotLines, qty is working. But if it contains, How mush return qty, qty changes to -1. How to fix?
At this `destinationOrder.add_product(this.env.pos.db.get_product_by_id(orderline.productId), { quantity: -qty, // Refund the correct quantity qty: -qty, // Refund the correct quantity price: orderline.price , lst_price: orderline.price, extracted: { price_manually_set: true }, merge: false, refunded_orderline_id: orderline.id, tax_ids: orderline.tax_ids, discount: orderline.discount, multi_uom_line_id: uom_line, draftPackLotLines: orderline.pack_lot_lines ? [], newPackLotLines: orderline.pack_lot_lines} : false });
refundDetail. destinationOrderUid = destinationOrder. see } `
If not including draftPackLotLines, qty is working. But if it contains, How mush return qty, qty changes to -1. How to fix?