[IMP] big refactoring :

use event_type instead of product_product
This commit is contained in:
clementthomas
2024-01-09 11:55:20 +01:00
parent a47ac870c1
commit c3acf2065e
7 changed files with 22 additions and 26 deletions

View File

@@ -16,7 +16,7 @@ class SurveyUserInput(models.Model):
_inherit = 'survey.user_input'
events_ids = fields.Many2many('event.event', string='Events', compute="compute_events_ids", search="search_events_ids") #related events
event_products_ids = fields.Many2many('product.product', string='Event products', compute="compute_event_products_ids", search="search_event_products_ids") #related event products
event_type_ids = fields.Many2many('event.type', string='Formations', compute="compute_event_type_ids", search="search_event_type_ids") #related event products
def search_events_ids(self, operator, value):
user_input_ids = set()
@@ -27,7 +27,7 @@ class SurveyUserInput(models.Model):
@api.depends('user_input_line_ids')
def compute_events_ids(self):
"""set events_ids as answer of "event" question
"""get all answers of type "event.event"
"""
for user_input in self:
event_ids = []
@@ -38,9 +38,9 @@ class SurveyUserInput(models.Model):
user_input.events_ids = event_ids
def search_event_products_ids(self, operator, value):
def search_event_type_ids(self, operator, value):
user_input_ids = set()
user_input_lines = self.env['survey.user_input.line'].search([('record_reference_model','=','product.product'),('record_reference','=', value)])
user_input_lines = self.env['survey.user_input.line'].search([('record_reference_model','=','event.type'),('record_reference','=', value)])
for user_input_line in user_input_lines:
user_input_ids.add(user_input_line.user_input_id.id)
return [('id',operator,list(user_input_ids))]
@@ -48,14 +48,14 @@ class SurveyUserInput(models.Model):
@api.depends('user_input_line_ids')
def compute_event_products_ids(self):
"""set event_products_ids as answer of "event product" or "multiple event products" question
def compute_event_type_ids(self):
"""get all answers of type "event.type"
"""
for user_input in self:
event_products_ids = []
event_type_ids = []
for user_input in self:
for user_input_line in user_input.user_input_line_ids:
if user_input_line.record_reference_model == 'product.product':
event_products_ids.append(user_input_line.record_reference)
user_input.event_products_ids = event_products_ids
if user_input_line.record_reference_model == 'event.type':
event_type_ids.append(user_input_line.record_reference)
user_input.event_type_ids = event_type_ids