@@ -11,18 +11,29 @@ class SaleOrderLine(models.Model):
11
11
'event.event' , string = 'Event' ,
12
12
compute = "_compute_event_id" , store = True , readonly = False , precompute = True , index = 'btree_not_null' ,
13
13
help = "Choose an event and it will automatically create a registration for this event." )
14
+ event_slot_id = fields .Many2one (
15
+ 'event.slot' , string = 'Slot' ,
16
+ compute = "_compute_event_slot_id" , store = True , readonly = False , precompute = True ,
17
+ help = "Choose an event slot and it will automatically create a registration for this event slot." )
14
18
event_ticket_id = fields .Many2one (
15
19
'event.event.ticket' , string = 'Ticket Type' ,
16
20
compute = "_compute_event_ticket_id" , store = True , readonly = False , precompute = True ,
17
21
help = "Choose an event ticket and it will automatically create a registration for this event ticket." )
22
+ is_multi_slots = fields .Boolean (related = "event_id.is_multi_slots" )
18
23
registration_ids = fields .One2many ('event.registration' , 'sale_order_line_id' , string = "Registrations" )
19
24
20
- @api .constrains ('event_id' , 'event_ticket_id' , 'product_id' )
25
+ @api .constrains ('event_id' , 'event_slot_id' , ' event_ticket_id' , 'product_id' )
21
26
def _check_event_registration_ticket (self ):
22
27
for so_line in self :
23
- if so_line .product_id .service_tracking == "event" and (not so_line .event_id or not so_line .event_ticket_id ):
24
- raise ValidationError (
25
- _ ("The sale order line with the product %(product_name)s needs an event and a ticket." , product_name = so_line .product_id .name ))
28
+ if so_line .product_id .service_tracking == "event" and (
29
+ not so_line .event_id or
30
+ not so_line .event_ticket_id or
31
+ (so_line .is_multi_slots and not so_line .event_slot_id )
32
+ ):
33
+ raise ValidationError (_ (
34
+ "The sale order line with the product %(product_name)s needs an event,"
35
+ " a ticket and a slot in case the event has multiple time slots." ,
36
+ product_name = so_line .product_id .name ))
26
37
27
38
@api .depends ('state' , 'event_id' )
28
39
def _compute_product_uom_readonly (self ):
@@ -58,6 +69,14 @@ def _compute_event_id(self):
58
69
if line .product_id not in line .event_id .event_ticket_ids .product_id :
59
70
line .event_id = False
60
71
72
+ @api .depends ('event_id' )
73
+ def _compute_event_slot_id (self ):
74
+ event_lines = self .filtered ('event_id' )
75
+ (self - event_lines ).event_slot_id = False
76
+ for line in event_lines :
77
+ if line .event_id != line .event_slot_id .event_id :
78
+ line .event_slot_id = False
79
+
61
80
@api .depends ('event_id' )
62
81
def _compute_event_ticket_id (self ):
63
82
event_lines = self .filtered ('event_id' )
@@ -85,7 +104,9 @@ def _get_sale_order_line_multiline_description_sale(self):
85
104
We need this override to be defined here in sales order line (and not in product) because here is the only place where the event_ticket_id is referenced.
86
105
"""
87
106
if self .event_ticket_id :
88
- return self .event_ticket_id ._get_ticket_multiline_description () + self ._get_sale_order_line_multiline_description_variants ()
107
+ return ('%s\n ' % self .event_slot_id .name if self .event_slot_id else '' ) + \
108
+ self .event_ticket_id ._get_ticket_multiline_description () + \
109
+ self ._get_sale_order_line_multiline_description_variants ()
89
110
else :
90
111
return super ()._get_sale_order_line_multiline_description_sale ()
91
112
0 commit comments