[NEW] first commit for all modules coming from training-tools
This commit is contained in:
1
survey_event_base/__init__.py
Normal file
1
survey_event_base/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
23
survey_event_base/__manifest__.py
Normal file
23
survey_event_base/__manifest__.py
Normal file
@@ -0,0 +1,23 @@
|
||||
# Copyright 2016-2020 Akretion France (<https://www.akretion.com>)
|
||||
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
{
|
||||
"name": "Survey event base",
|
||||
'summary': 'Add field to reference events and product events in servey answers (survey.user_input)',
|
||||
'description': """
|
||||
Add field to reference events and product events in servey answers (survey.user_input)
|
||||
----------------------------------------------------
|
||||
*
|
||||
""",
|
||||
"version": "16.0.1.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
"website": "https://www.elabore.coop",
|
||||
"category": "",
|
||||
"depends": ["event","survey_base"],
|
||||
"data": [
|
||||
|
||||
],
|
||||
"installable": True,
|
||||
}
|
1
survey_event_base/models/__init__.py
Normal file
1
survey_event_base/models/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import survey_user_input
|
61
survey_event_base/models/survey_user_input.py
Normal file
61
survey_event_base/models/survey_user_input.py
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
import logging
|
||||
import textwrap
|
||||
import uuid
|
||||
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools import float_is_zero
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
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
|
||||
|
||||
def search_events_ids(self, operator, value):
|
||||
user_input_ids = set()
|
||||
user_input_lines = self.env['survey.user_input.line'].search([('record_reference_model','=','event.event'),('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))]
|
||||
|
||||
@api.depends('user_input_line_ids')
|
||||
def compute_events_ids(self):
|
||||
"""set events_ids as answer of "event" question
|
||||
"""
|
||||
for user_input in self:
|
||||
event_ids = []
|
||||
for user_input in self:
|
||||
for user_input_line in user_input.user_input_line_ids:
|
||||
if user_input_line.record_reference_model == 'event.event':
|
||||
event_ids.append(user_input_line.record_reference)
|
||||
user_input.events_ids = event_ids
|
||||
|
||||
|
||||
def search_event_products_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)])
|
||||
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))]
|
||||
|
||||
|
||||
|
||||
@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
|
||||
"""
|
||||
for user_input in self:
|
||||
event_products_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
|
||||
|
Reference in New Issue
Block a user