[FIX] point_of_sale: add serial number on refund

Install POS, create a product available in POS, tracked by Serial
Number.
Add some product to the inventory.
Open the POS session, sell the demo item, close the session (do not end
the session, just close the interface).
Go to POS orders, select the last order and click on "Return Products",
the refund will be created.

The user will be unable to process payment for the refund order because
Serial Number is missing. Adding a copy of the lot from the original
order line fix the issue

opw-2152776

closes odoo/odoo#41762

X-original-commit: 886dee9efc3bd743ca1b9353872021c1f81efa9a
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
Andrea Grazioso (agr-odoo)
2019-12-12 07:25:08 +00:00
parent 40fa388b5b
commit 14e87b9783
2 changed files with 108 additions and 0 deletions
+4
View File
@@ -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
@@ -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,