[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#75174 X-original-commit: 9dcfae2234b1f45da1837c519b54926522cfa070 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com> Signed-off-by: guva-odoo <guva-odoo@users.noreply.github.com>
This commit is contained in:
@@ -29,6 +29,10 @@ class SaleOrder(models.Model):
|
||||
._for_xml_id('event_sale.action_sale_order_event_registration')
|
||||
return res
|
||||
|
||||
def action_cancel(self):
|
||||
self.order_line._cancel_associated_registrations()
|
||||
return super(SaleOrder, self).action_cancel()
|
||||
|
||||
def action_view_attendee_list(self):
|
||||
action = self.env["ir.actions.actions"]._for_xml_id("event.event_registration_action_tree")
|
||||
action['domain'] = [('sale_order_id', 'in', self.ids)]
|
||||
@@ -128,6 +132,9 @@ class SaleOrderLine(models.Model):
|
||||
self._unlink_associated_registrations()
|
||||
return super(SaleOrderLine, self).unlink()
|
||||
|
||||
def _cancel_associated_registrations(self):
|
||||
self.env['event.registration'].search([('sale_order_line_id', 'in', self.ids)]).action_cancel()
|
||||
|
||||
def _unlink_associated_registrations(self):
|
||||
self.env['event.registration'].search([('sale_order_line_id', 'in', self.ids)]).unlink()
|
||||
|
||||
|
||||
@@ -270,3 +270,13 @@ class TestEventSale(TestEventSaleCommon):
|
||||
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_0.ids)
|
||||
self.register_person.action_make_registration()
|
||||
self.assertEqual(event.seats_expected, 1)
|
||||
self.sale_order.action_cancel()
|
||||
self.assertEqual(event.seats_expected, 0)
|
||||
|
||||
Reference in New Issue
Block a user