Skip to content
Snippets Groups Projects
Commit 2fcc8a71 authored by Guillaume (guva)'s avatar Guillaume (guva)
Browse files

[FIX] event_sale : compute attendees on cancel SO


Steps to reproduce:

- create a sale order with an event registration,
- on the event, the number of attendees is well computed
- cancel the sale order
- on the event, the number of attendees is still the same as before

Cause of the issue

There was no specific action for canceling a sale order linked
to an event registration

Solution

Add a action_cancel method which cancel also the sale order lines when
canceling the sale order

Also add a test to ensure the flow will not break in the future

opw-2576790

closes odoo/odoo#74481

Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent 6453a03e
Branches
Tags
No related merge requests found
......@@ -23,10 +23,14 @@ class SaleOrder(models.Model):
.with_context(default_sale_order_id=so.id) \
.for_xml_id('event_sale', 'action_sale_order_event_registration')
return res
def action_cancel(self):
self.mapped('order_line')._cancel_associated_registrations()
return super(SaleOrder, self).action_cancel()
def unlink(self):
self.mapped('order_line')._unlink_associated_registrations()
super(SaleOrder, self).unlink()
return super(SaleOrder, self).unlink()
class SaleOrderLine(models.Model):
......@@ -91,6 +95,9 @@ class SaleOrderLine(models.Model):
self._unlink_associated_registrations()
super(SaleOrderLine, self).unlink()
def _cancel_associated_registrations(self):
self.env['event.registration'].search([('sale_order_line_id', 'in', self.ids)]).button_reg_cancel()
def _unlink_associated_registrations(self):
self.env['event.registration'].search([('sale_order_line_id', 'in', self.ids)]).unlink()
......
......@@ -145,3 +145,13 @@ class EventSaleTest(TransactionCase):
self.assertEqual(event.seats_expected, 1)
self.sale_order.order_line.unlink()
self.assertEqual(event.seats_expected, 0)
@users('user_salesman')
def test_cancel_so(self):
""" This test ensures that when canceling a sale order, if the latter is linked to an event registration,
the number of expected seats will be correctly updated """
event = self.env['event.event'].browse(self.event.ids)
self.register_person.action_make_registration()
self.assertEqual(event.seats_expected, 1)
self.sale_order.action_cancel()
self.assertEqual(event.seats_expected, 0)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment