Skip to content
Snippets Groups Projects
Commit 42478b59 authored by roen-odoo's avatar roen-odoo
Browse files

[FIX] pos_sale: correctly update move qty when settling a pos order


Current behavior:
When settling a pos order containing 2 different product, the qty of the
2 products would be modified even if you only deliver one of them
through the pos order.

Steps to reproduce:
- Create 2 product A and B
- Create a sale order with 1 product A and 1 product B
- Open a PoS session, and settle the order you just created
- Deliver only 1 product A
- Close the PoS session
- Go the the sale order delivery, you will see that the qty are not
  correct

opw-3227053

closes odoo/odoo#120642

X-original-commit: 7dd5e78596718120f4c04b7ce1757ff0bd38d665
Signed-off-by: default avatarJoseph Caburnay (jcb) <jcb@odoo.com>
Signed-off-by: default avatarEngels Robin (roen) <roen@odoo.com>
parent 534f814f
No related branches found
No related tags found
No related merge requests found
......@@ -76,7 +76,8 @@ class PosOrder(models.Model):
# track the waiting pickings
waiting_picking_ids = set()
for so_line in so_lines:
for stock_move in so_line.move_ids.group_id.stock_move_ids:
so_line_stock_move_ids = so_line.move_ids.group_id.stock_move_ids
for stock_move in so_line.move_ids:
picking = stock_move.picking_id
if not picking.state in ['waiting', 'confirmed', 'assigned']:
continue
......@@ -84,6 +85,9 @@ class PosOrder(models.Model):
if float_compare(new_qty, 0, precision_rounding=stock_move.product_uom.rounding) <= 0:
new_qty = 0
stock_move.product_uom_qty = so_line.compute_uom_qty(new_qty, stock_move, False)
#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(picking.id)
def is_product_uom_qty_zero(move):
......
......@@ -4,6 +4,7 @@ odoo.define('pos_sale.tour', function (require) {
const { Chrome } = require('point_of_sale.tour.ChromeTourMethods');
const { PaymentScreen } = require('point_of_sale.tour.PaymentScreenTourMethods');
const { ProductScreen } = require('pos_sale.tour.ProductScreenTourMethods');
const { ReceiptScreen } = require('point_of_sale.tour.ReceiptScreenTourMethods');
const { getSteps, startSteps } = require('point_of_sale.tour.utils');
const Tour = require('web_tour.tour');
......@@ -42,4 +43,22 @@ odoo.define('pos_sale.tour', function (require) {
ProductScreen.check.totalAmountIs("11.00");
Tour.register('PosSettleOrderIncompatiblePartner', { test: true, url: '/pos/ui' }, getSteps());
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.clickOrderline("Product B", "1");
ProductScreen.do.pressNumpad('Qty 0');
ProductScreen.check.selectedOrderlineHas('Product B', '0.00');
ProductScreen.do.clickPayButton();
PaymentScreen.do.clickPaymentMethod('Bank');
PaymentScreen.check.remainingIs('0.0');
PaymentScreen.do.clickValidate();
ReceiptScreen.check.isShown();
Tour.register('PosSettleOrder2', { test: true, url: '/pos/ui' }, getSteps());
});
......@@ -104,3 +104,54 @@ class TestPoSSale(TestPointOfSaleHttpCommon):
})
self.main_pos_config.open_ui()
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PosSettleOrderIncompatiblePartner', login="accountman")
def test_settle_order_with_different_product(self):
"""This test create an order and settle it in the PoS. But only one of the product is delivered.
And we need to make sure the quantity are correctly updated on the sale order.
"""
#create 2 products
product_a = self.env['product.product'].create({
'name': 'Product A',
'available_in_pos': True,
'type': 'product',
'lst_price': 10.0,
})
product_b = self.env['product.product'].create({
'name': 'Product B',
'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,
}), (0, 0, {
'product_id': product_b.id,
'name': product_b.name,
'product_uom_qty': 1,
'product_uom': product_b.uom_id.id,
'price_unit': product_b.lst_price,
})],
})
sale_order.action_confirm()
self.assertEqual(sale_order.order_line[0].qty_delivered, 0)
self.assertEqual(sale_order.order_line[1].qty_delivered, 0)
self.main_pos_config.open_ui()
self.start_tour("/pos/ui?config_id=%d" % self.main_pos_config.id, 'PosSettleOrder2', login="accountman")
self.assertEqual(sale_order.order_line[0].qty_delivered, 1)
self.assertEqual(sale_order.order_line[1].qty_delivered, 0)
orderline_product_a = sale_order.order_line.filtered(lambda l: l.product_id.id == product_a.id)
orderline_product_b = sale_order.order_line.filtered(lambda l: l.product_id.id == product_b.id)
# nothing to deliver for product a because already handled in pos.
self.assertEqual(orderline_product_a.move_ids.product_uom_qty, 0)
# 1 item to deliver for product b.
self.assertEqual(orderline_product_b.move_ids.product_uom_qty, 1)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment