From 37edaca7af129f7945c32ee9340d2128b0dcefe5 Mon Sep 17 00:00:00 2001 From: roen-odoo Date: Tue, 14 Mar 2023 13:17:22 +0000 Subject: [PATCH] [FIX] point_of_sale: Correctly set owner on picking create from POS Current behavior: If you create a product tracked by serial number and set an owner on the product. If you make an order from the PoS with this product, the owner wouldn't be set correctly on the picking created from the PoS. Steps to reproduce: - Create product A, tracked by serial number, storable, and available in the PoS. - Add some quantity of product A with an owner (e.g. "Owner A"). - Create a PoS order with product A. - Validate the order. - Close the PoS session, go to the picking created from the PoS order there will not be any owner set on the picking. opw-3206618 closes odoo/odoo#116919 X-original-commit: d6c44280eb8a86925392e87cf1a35bfe8b00177e Signed-off-by: Engels Robin (roen) --- addons/point_of_sale/models/stock_picking.py | 3 +- .../tests/test_point_of_sale_flow.py | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/models/stock_picking.py b/addons/point_of_sale/models/stock_picking.py index f6e8f487191..3585c9f4a16 100644 --- a/addons/point_of_sale/models/stock_picking.py +++ b/addons/point_of_sale/models/stock_picking.py @@ -261,7 +261,8 @@ class StockMove(models.Model): ) ml_vals.update({ 'lot_id': existing_lot.id, - 'location_id': quant.location_id.id or move.location_id.id + 'location_id': quant.location_id.id or move.location_id.id, + 'owner_id': quant.owner_id.id or False, }) else: ml_vals.update({'lot_name': lot.lot_name}) diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index 06514203e53..383209cebb1 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -1412,3 +1412,62 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): order_payment.with_context(**payment_context).check() current_session.action_pos_session_closing_control() self.assertEqual(current_session.move_id.line_ids[0].account_id.id, account.id) + + def test_tracked_product_with_owner(self): + # open pos session + self.pos_config.open_ui() + current_session = self.pos_config.current_session_id + + # set up product iwith SN tracing and create two lots (1001, 1002) + self.stock_location = self.company_data['default_warehouse'].lot_stock_id + self.product2 = self.env['product.product'].create({ + 'name': 'Product A', + 'type': 'product', + 'tracking': 'serial', + 'categ_id': self.env.ref('product.product_category_all').id, + }) + + lot1 = self.env['stock.lot'].create({ + 'name': '1001', + 'product_id': self.product2.id, + 'company_id': self.env.company.id, + }) + + self.env['stock.quant']._update_available_quantity(self.product2, self.stock_location, 1, lot_id=lot1, owner_id=self.partner1) + + + # create pos order with the two SN created before + + order = self.PosOrder.create({ + 'company_id': self.env.company.id, + 'session_id': current_session.id, + 'partner_id': self.partner1.id, + 'lines': [(0, 0, { + 'name': "OL/0001", + 'id': 1, + 'product_id': self.product2.id, + 'price_unit': 6, + 'discount': 0, + 'qty': 1, + 'tax_ids': [[6, False, []]], + 'price_subtotal': 6, + 'price_subtotal_incl': 6, + 'pack_lot_ids': [ + [0, 0, {'lot_name': '1001'}], + ] + })], + 'amount_paid': 6.0, + 'amount_total': 6.0, + 'amount_tax': 0.0, + 'amount_return': 0.0, + 'to_invoice': False, + }) + + payment_context = {"active_ids": order.ids, "active_id": order.id} + order_payment = self.PosMakePayment.with_context(**payment_context).create({ + 'amount': order.amount_total, + 'payment_method_id': self.cash_payment_method.id + }) + order_payment.with_context(**payment_context).check() + current_session.action_pos_session_closing_control() + self.assertEqual(current_session.picking_ids.move_line_ids.owner_id.id, self.partner1.id)