[FIX] point_of_sale: stop creating double picking on pos order refund
When you are in anglo saxon accounting with posting stock changes at the end of the session, we get an issue by using the refund feature in backend. If you have an order invoiced, and want to refund it, it'll create the picking of the order immediately, which is not normal as it should only be done when there is an invoice. The problem is that the value of the field 'to_invoice' from the original order is copied to the refund, and so act as the invoice is made for the return. To avoid this behavior, we are avoiding to copy it. OPW-2848356 closes odoo/odoo#93645 X-original-commit: e8ef74397c0b02d051823142c3457413aabfeb21 Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
@@ -281,7 +281,7 @@ class PosOrder(models.Model):
|
||||
)
|
||||
payment_ids = fields.One2many('pos.payment', 'pos_order_id', string='Payments', readonly=True)
|
||||
session_move_id = fields.Many2one('account.move', string='Session Journal Entry', related='session_id.move_id', readonly=True, copy=False)
|
||||
to_invoice = fields.Boolean('To invoice')
|
||||
to_invoice = fields.Boolean('To invoice', copy=False)
|
||||
to_ship = fields.Boolean('To ship')
|
||||
is_invoiced = fields.Boolean('Is Invoiced', compute='_compute_is_invoiced')
|
||||
is_tipped = fields.Boolean('Is this already tipped?', readonly=True)
|
||||
|
||||
@@ -1104,3 +1104,53 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
|
||||
self.assertEqual(len(picking_mls_no_stock), 0)
|
||||
self.assertEqual(len(picking_mls_stock), 1)
|
||||
self.assertEqual(len(pickings.picking_type_id), 2)
|
||||
|
||||
def test_order_refund_picking(self):
|
||||
self.pos_config.open_session_cb()
|
||||
current_session = self.pos_config.current_session_id
|
||||
current_session.update_stock_at_closing = True
|
||||
# I create a new PoS order with 1 line
|
||||
order = self.PosOrder.create({
|
||||
'company_id': self.env.company.id,
|
||||
'session_id': current_session.id,
|
||||
'partner_id': self.partner1.id,
|
||||
'pricelist_id': self.partner1.property_product_pricelist.id,
|
||||
'lines': [(0, 0, {
|
||||
'name': "OL/0001",
|
||||
'product_id': self.product3.id,
|
||||
'price_unit': 450,
|
||||
'discount': 5.0,
|
||||
'qty': 2.0,
|
||||
'tax_ids': [(6, 0, self.product3.taxes_id.ids)],
|
||||
'price_subtotal': 450 * (1 - 5/100.0) * 2,
|
||||
'price_subtotal_incl': 450 * (1 - 5/100.0) * 2,
|
||||
})],
|
||||
'amount_total': 1710.0,
|
||||
'amount_tax': 0.0,
|
||||
'amount_paid': 0.0,
|
||||
'amount_return': 0.0,
|
||||
'to_invoice': True
|
||||
})
|
||||
|
||||
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()
|
||||
|
||||
# I create a refund
|
||||
refund_action = order.refund()
|
||||
refund = self.PosOrder.browse(refund_action['res_id'])
|
||||
|
||||
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()
|
||||
|
||||
refund.action_pos_order_invoice()
|
||||
self.assertEqual(refund.picking_count, 1)
|
||||
|
||||
Reference in New Issue
Block a user