From 467a788302249639c5cc0afff3106ec5da2dd7ca Mon Sep 17 00:00:00 2001 From: "Guillaume (guva)" Date: Fri, 30 Jul 2021 10:08:02 +0000 Subject: [PATCH] [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) Signed-off-by: guva-odoo --- addons/event_sale/models/sale_order.py | 7 +++++++ addons/event_sale/tests/test_event_sale.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/addons/event_sale/models/sale_order.py b/addons/event_sale/models/sale_order.py index fd589e41e8a..60b84a2eaf0 100644 --- a/addons/event_sale/models/sale_order.py +++ b/addons/event_sale/models/sale_order.py @@ -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() diff --git a/addons/event_sale/tests/test_event_sale.py b/addons/event_sale/tests/test_event_sale.py index 65a777ef6b0..b4d5bd9e23e 100644 --- a/addons/event_sale/tests/test_event_sale.py +++ b/addons/event_sale/tests/test_event_sale.py @@ -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)