[FIX] pos_sale: correctly cancel all moves with 0 qty

Current behavior:
When you settle an order in the PoS and completely validate it, the
remaining moves from the original sales should be cancelled.
However, it was not the case because we were not adding all the picking
in the `waiting_picking_ids` list. And so when we were checking this
list we were not cancelling all the moves.

Steps to reproduce:
- Setup multi-step routes (Inventory > Settings > Multi-Step Routes)
- Change the configuration of the warehouse to use the multi-step routes
- Create a sale order for any product and confirm it
- Open the PoS, and settle the order you just created
- Validate the order
- Go back to the sale order, and check the state of the delivery
- Only one picking has been cancelled

opw-3390529

closes odoo/odoo#133547

X-original-commit: c57b8286e3dedb75db68f27fc514224f6ba8d1c1
Signed-off-by: Joseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: Robin Engels (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2023-08-30 07:04:01 +00:00
parent 6e57324aff
commit 97c7d387a7
3 changed files with 60 additions and 0 deletions
+1
View File
@@ -89,6 +89,7 @@ class PosOrder(models.Model):
#If the product is delivered with more than one step, we need to update the quantity of the other steps
for move in so_line_stock_move_ids.filtered(lambda m: m.state in ['waiting', 'confirmed'] and m.product_id == stock_move.product_id):
move.product_uom_qty = stock_move.product_uom_qty
waiting_picking_ids.add(move.picking_id.id)
waiting_picking_ids.add(picking.id)
def is_product_uom_qty_zero(move):
@@ -138,3 +138,26 @@ registry
return getSteps();
}
});
registry
.category("web_tour.tours")
.add('PosSettleOrder3', {
test: true,
url: '/pos/ui',
steps: () => {
startSteps();
ProductScreen.do.confirmOpeningPopup();
ProductScreen.do.clickQuotationButton();
ProductScreen.do.selectFirstOrder();
ProductScreen.do.clickOrderline("Product A", "1");
ProductScreen.check.selectedOrderlineHas('Product A', '1.00');
ProductScreen.do.clickPayButton();
PaymentScreen.do.clickPaymentMethod('Bank');
PaymentScreen.check.remainingIs('0.0');
PaymentScreen.do.clickValidate();
ReceiptScreen.check.isShown();
return getSteps();
}
});
@@ -255,3 +255,39 @@ class TestPoSSale(TestPointOfSaleHttpCommon):
self.assertEqual(pos_order.picking_ids.move_line_ids[1].qty_done, 2)
self.assertEqual(pos_order.picking_ids.move_line_ids[1].location_id.id, self.shelf_2.id)
self.assertEqual(sale_order.order_line.move_ids.move_lines_count, 0)
def test_settle_order_with_multistep_delivery(self):
"""This test create an order and settle it in the PoS. It also uses multistep delivery
and we need to make sure that all the picking are cancelled if the order is fully delivered.
"""
#get the warehouse
warehouse = self.env['stock.warehouse'].search([('company_id', '=', self.env.company.id)], limit=1)
warehouse.delivery_steps = 'pick_pack_ship'
product_a = self.env['product.product'].create({
'name': 'Product A',
'available_in_pos': True,
'type': 'product',
'lst_price': 10.0,
})
#create a sale order with 2 lines
sale_order = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_2').id,
'order_line': [(0, 0, {
'product_id': product_a.id,
'name': product_a.name,
'product_uom_qty': 1,
'product_uom': product_a.uom_id.id,
'price_unit': product_a.lst_price,
})],
})
sale_order.action_confirm()
self.assertEqual(sale_order.order_line[0].qty_delivered, 0)
self.main_pos_config.open_ui()
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PosSettleOrder3', login="accountman")
self.assertEqual(sale_order.order_line[0].qty_delivered, 1)
self.assertEqual(sale_order.picking_ids.mapped('state'), ['cancel', 'cancel', 'cancel'])