[FIX] point_of_sale: correctly link credit notes and invoice from PoS

Current behavior:
When creating a credit note from a PoS order, the credit note is not
linked to the invoice of the orginal order.

Steps to reproduce:
- Make an order in the PoS, validate it and invoice it
- Make a refund of this order and invoice it too.
- Go to the credit note, the original invoice is not mentionned in the
  reference field.

opw-3150637

closes odoo/odoo#123976

X-original-commit: d3ff97f498e0fcc97ec32194988268a7e2afc631
Signed-off-by: Engels Robin (roen) <roen@odoo.com>
This commit is contained in:
roen-odoo
2023-06-06 19:19:48 +02:00
parent 9f8d4dd12a
commit ba8d431704
3 changed files with 66 additions and 0 deletions
@@ -5372,6 +5372,14 @@ msgstr ""
#. module: point_of_sale
#. odoo-javascript
#: code:addons/point_of_sale/static/src/xml/Screens/PaymentScreen/PaymentScreenPaymentLines.xml:0
#: code:addons/point_of_sale/models/pos_order.py:0
#, python-format
msgid "Reversal of: %s"
msgstr ""
#. module: point_of_sale
#. openerp-web
#: code:addons/point_of_sale/static/src/xml/Screens/PaymentScreen/PaymentScreenElectronicPayment.xml:0
#, python-format
msgid "Reversal request sent to terminal"
msgstr ""
+3
View File
@@ -603,6 +603,9 @@ class PosOrder(models.Model):
if self.config_id.cash_rounding and (not self.config_id.only_round_cash_method or any(p.payment_method_id.is_cash_count for p in self.payment_ids))
else False
}
if self.refunded_order_ids.account_move:
vals['ref'] = _('Reversal of: %s', self.refunded_order_ids.account_move.name)
vals['reversed_entry_id'] = self.refunded_order_ids.account_move.id
if self.note:
vals.update({'narration': self.note})
return vals
@@ -1471,3 +1471,58 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon):
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)
def test_order_refund_with_invoice(self):
"""This test make sure that credit notes of pos orders are correctly
linked to the original invoice."""
self.pos_config.open_ui()
current_session = self.pos_config.current_session_id
order_data = {'data':
{'amount_paid': 450,
'amount_tax': 0,
'amount_return': 0,
'amount_total': 450,
'creation_date': fields.Datetime.to_string(fields.Datetime.now()),
'fiscal_position_id': False,
'lines': [[0, 0, {
'discount': 0,
'pack_lot_ids': [],
'price_unit': 450.0,
'product_id': self.product3.id,
'price_subtotal': 450.0,
'price_subtotal_incl': 450.0,
'tax_ids': [[6, False, []]],
'qty': 1,
}]],
'name': 'Order 12345-123-1234',
'partner_id': self.partner1.id,
'pos_session_id': current_session.id,
'sequence_number': 2,
'statement_ids': [[0, 0, {
'amount': 450,
'name': fields.Datetime.now(),
'payment_method_id': self.cash_payment_method.id
}]],
'uid': '12345-123-1234',
'user_id': self.env.uid,
'to_invoice': True, }
}
order = self.PosOrder.create_from_ui([order_data])
order = self.PosOrder.browse(order[0]['id'])
refund_id = order.refund()['res_id']
refund = self.PosOrder.browse(refund_id)
context_payment = {"active_ids": refund.ids, "active_id": refund.id}
refund_payment = self.PosMakePayment.with_context(**context_payment).create({
'amount': refund.amount_total,
'payment_method_id': self.cash_payment_method.id
})
refund_payment.with_context(**context_payment).check()
refund.action_pos_order_invoice()
#get last invoice created
current_session.action_pos_session_closing_control()
invoices = self.env['account.move'].search([('move_type', '=', 'out_invoice')], order='id desc', limit=1)
credit_notes = self.env['account.move'].search([('move_type', '=', 'out_refund')], order='id desc', limit=1)
self.assertEqual(credit_notes.ref, "Reversal of: "+invoices.name)
self.assertEqual(credit_notes.reversed_entry_id.id, invoices.id)