summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--addons/point_of_sale/models/pos_order.py4
-rw-r--r--addons/point_of_sale/tests/test_point_of_sale_flow.py104
2 files changed, 108 insertions, 0 deletions
diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py
index 84df3b47579..dc0455b6191 100644
--- a/addons/point_of_sale/models/pos_order.py
+++ b/addons/point_of_sale/models/pos_order.py
@@ -489,12 +489,16 @@ class PosOrder(models.Model):
'amount_paid': 0,
})
for line in order.lines:
+ PosOrderLineLot = self.env['pos.pack.operation.lot']
+ for pack_lot in line.pack_lot_ids:
+ PosOrderLineLot += pack_lot.copy()
line.copy({
'name': line.name + _(' REFUND'),
'qty': -line.qty,
'order_id': refund_order.id,
'price_subtotal': -line.price_subtotal,
'price_subtotal_incl': -line.price_subtotal_incl,
+ 'pack_lot_ids': PosOrderLineLot,
})
refund_orders |= refund_order
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 c433ebf7b53..6d9a96eed9b 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
@@ -78,6 +78,110 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
current_session.action_pos_session_closing_control()
self.assertEqual(current_session.state, 'closed', msg='State of current session should be closed.')
+ def test_order_refund_lots(self):
+ # open pos session
+ self.pos_config.open_session_cb()
+ current_session = self.pos_config.current_session_id
+
+ # set up product iwith SN tracing and create two lots (1001, 1002)
+ self.stock_location = self.env.ref('stock.stock_location_stock')
+ self.product2 = self.env['product.product'].create({
+ 'name': 'Product A',
+ 'type': 'product',
+ 'tracking': 'serial',
+ 'categ_id': self.env.ref('product.product_category_all').id,
+ })
+
+ inventory = self.env['stock.inventory'].create({
+ 'name': 'add product2',
+ 'location_ids': [(4, self.stock_location.id)],
+ 'product_ids': [(4, self.product2.id)],
+ })
+ inventory.action_start()
+
+ lot1 = self.env['stock.production.lot'].create({
+ 'name': '1001',
+ 'product_id': self.product2.id,
+ 'company_id': self.env.company.id,
+ })
+ lot2 = self.env['stock.production.lot'].create({
+ 'name': '1002',
+ 'product_id': self.product2.id,
+ 'company_id': self.env.company.id,
+ })
+
+ self.env['stock.inventory.line'].create([
+ {
+ 'inventory_id': inventory.id,
+ 'location_id': self.stock_location.id,
+ 'product_id': self.product2.id,
+ 'prod_lot_id': lot1.id,
+ 'product_qty': 1
+ },
+ {
+ 'inventory_id': inventory.id,
+ 'location_id': self.stock_location.id,
+ 'product_id': self.product2.id,
+ 'prod_lot_id': lot2.id,
+ 'product_qty': 1
+ },
+ ])
+
+ inventory.action_validate()
+
+ # create pos order with the two SN created before
+
+ order = self.PosOrder.create({
+ 'company_id': self.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': 2,
+ 'tax_ids': [[6, False, [1]]],
+ 'price_subtotal': 12,
+ 'price_subtotal_incl': 13.8,
+ 'pack_lot_ids': [
+ [0, 0, {'lot_name': '1001'}],
+ [0, 0, {'lot_name': '1002'}],
+ ]
+ })],
+ 'pricelist_id': 1,
+ 'amount_paid': 13.8,
+ 'amount_total': 13.8,
+ 'amount_tax': 1.8,
+ 'amount_return': 6.2,
+ 'to_invoice': False,
+ })
+
+ order.action_pos_order_paid()
+
+ # I create a refund
+ refund_action = order.refund()
+ refund = self.PosOrder.browse(refund_action['res_id'])
+
+ order_lot_id = [lot_id.lot_name for lot_id in order.lines.pack_lot_ids]
+ refund_lot_id = [lot_id.lot_name for lot_id in refund.lines.pack_lot_ids]
+ self.assertEqual(
+ order_lot_id,
+ refund_lot_id,
+ "In the refund we should find the same lot as in the original order")
+
+ payment_context = {"active_ids": refund.ids, "active_id": refund.id}
+ refund_payment = self.PosMakePayment.with_context(**payment_context).create({
+ 'amount': refund.amount_total,
+ 'payment_method_id': self.cash_payment_method.id,
+ })
+
+ # I click on the validate button to register the payment.
+ refund_payment.with_context(**payment_context).check()
+
+ self.assertEqual(refund.state, 'paid', "The refund is not marked as paid")
+
def test_order_to_picking(self):
"""
In order to test the Point of Sale in module, I will do three orders from the sale to the payment,