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)