[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

@@ -19,7 +19,7 @@ Customize lead creation from survey according to trainings
"category": "",
"depends": ["event","survey_crm_generation","survey_event_registration_generation","survey_event_base"],
"data": [
"views/crm_lead_views.xml"
"views/crm_lead_views.xml",
],
"installable": True,
"auto_install":True

View File

@@ -26,11 +26,7 @@ msgstr ""
" Réponses\n"
" </span>"
#. module: survey_crm_generation_training
#: model:ir.model.fields,field_description:survey_crm_generation_training.field_crm_lead__event_products_ids
#: model_terms:ir.ui.view,arch_db:survey_crm_generation_training.view_crm_case_opportunities_filter_survey_crm_generation_training
msgid "Event product"
msgstr "Produit de formation"
#. module: survey_crm_generation_training
#: model:ir.model,name:survey_crm_generation_training.model_crm_lead

View File

@@ -6,7 +6,7 @@ from odoo import fields, models
class CrmLead(models.Model):
_inherit = "crm.lead"
event_products_ids = fields.Many2many('product.product', string='Event product')
event_type_ids = fields.Many2many('event.type', string='Formation')
def action_view_survey_user_input_id(self):

View File

@@ -8,8 +8,8 @@ class SurveyUserInput(models.Model):
def _create_opportunity_post_process(self):
"""After lead creation from survey answer (module survey_crm_generation),
if answer (survey_user_input) contains event_products_ids, copy it in lead.
if answer (survey_user_input) contains event_type_ids, copy it in lead.
"""
self.opportunity_id.event_products_ids = self.event_products_ids.ids
self.opportunity_id.event_type_ids = self.event_type_ids.ids
return super(SurveyUserInput, self)._create_opportunity_post_process()

View File

@@ -6,10 +6,10 @@
<field name="model">crm.lead</field>
<field name="arch" type="xml">
<filter name="salesperson" position="before">
<filter string="Event product" name="event_product" context="{'group_by':'event_products_ids'}" />
<filter string="Event type" name="event_type" context="{'group_by':'event_type_ids'}" />
</filter>
<field name="tag_ids" position="before">
<field name="event_products_ids" />
<field name="event_type_ids" />
</field>
</field>
</record>
@@ -37,9 +37,7 @@
</div>
<field name="survey_user_input_id" position="after">
<field
name="event_products_ids"
readonly="1"
attrs="{'invisible': [('event_products_ids', '=', False)]}"
name="event_type_ids"
widget="many2many_tags"
/>
</field>
@@ -54,8 +52,10 @@
<field name="inherit_id" ref="crm.crm_case_tree_view_oppor" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="event_products_ids" widget="many2many_tags" />
<field name="event_type_ids" widget="many2many_tags" />
</field>
</field>
</record>
</odoo>

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

View File

@@ -33,7 +33,7 @@ class SurveyUserInput(models.Model):
for user_input in self.filtered(lambda r: r.survey_id.generate_speaker and not r.speaker_id and r.partner_id):
user_input.update({"speaker_id": user_input.partner_id.id})
for event in user_input.events_ids:
event.speakers = [Command.link(user_input.speaker_id.id)]
event.speaker_ids = [Command.link(user_input.speaker_id.id)]
user_input._create_speaker_post_process(user_input.speaker_id)