[NEW] first commit for all modules coming from training-tools
This commit is contained in:
1
survey_event_visibility/__init__.py
Normal file
1
survey_event_visibility/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import models
|
24
survey_event_visibility/__manifest__.py
Normal file
24
survey_event_visibility/__manifest__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# 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 visibility",
|
||||
"version": "16.0.0.0.0",
|
||||
"license": "AGPL-3",
|
||||
"author": "Elabore",
|
||||
'summary': 'Add visibility field in event stage',
|
||||
'description': """
|
||||
Add visibility information in product and events
|
||||
----------------------------------------------------
|
||||
|
||||
The product and event visibility is computed from event stage visibility.
|
||||
""",
|
||||
"website": "https://www.elabore.coop",
|
||||
"category": "",
|
||||
"depends": ["survey"],
|
||||
"data": [
|
||||
'views/event_stage_views.xml',
|
||||
],
|
||||
"installable": True,
|
||||
}
|
3
survey_event_visibility/models/__init__.py
Normal file
3
survey_event_visibility/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import event_stage
|
||||
from . import event_event
|
||||
from . import product_product
|
28
survey_event_visibility/models/event_event.py
Normal file
28
survey_event_visibility/models/event_event.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class EventEvent(models.Model):
|
||||
_inherit = 'event.event'
|
||||
|
||||
visible_in_survey = fields.Boolean('Visible in survey', related='stage_id.visible_in_survey', readonly=True,
|
||||
help="""Events in step configured as 'visible in survey'.""")
|
||||
|
||||
def get_events_from_event_products(self, product_ids=None, only_visible_in_survey=False):
|
||||
"""Search events in stage filtered by product present in ticket..
|
||||
|
||||
Args:
|
||||
product_ids (list[product.product ids], optional): to filter only events with tickets using product in this list. Defaults to None.
|
||||
|
||||
Returns:
|
||||
event.event: Events
|
||||
"""
|
||||
event_search = []
|
||||
if product_ids:
|
||||
event_tickets = self.env['event.event.ticket'].search([('product_id','in',product_ids)])
|
||||
event_search.append(('event_ticket_ids','in',event_tickets.ids))
|
||||
|
||||
if only_visible_in_survey:
|
||||
event_search.append(('visible_in_survey','=',True))
|
||||
|
||||
return self.env['event.event'].search(event_search)
|
||||
|
7
survey_event_visibility/models/event_stage.py
Normal file
7
survey_event_visibility/models/event_stage.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class EventStage(models.Model):
|
||||
_inherit = 'event.stage'
|
||||
|
||||
visible_in_survey = fields.Boolean('Visible in surveys') #if checked, only events on this stage are visible in surveys
|
23
survey_event_visibility/models/product_product.py
Normal file
23
survey_event_visibility/models/product_product.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class ProductProduct(models.Model):
|
||||
_inherit = 'product.product'
|
||||
|
||||
visible_in_survey = fields.Boolean('Visible in survey', compute='_compute_visible_in_survey', readonly=True,
|
||||
help="""Events in step configured as 'visible in survey'.""")
|
||||
|
||||
|
||||
def _compute_visible_in_survey(self):
|
||||
#get all events in step 'visible in survey'
|
||||
product_ids = set()
|
||||
events = self.env['event.event'].search([('visible_in_survey','=',True)])
|
||||
for event in events:
|
||||
for ticket in event.event_ticket_ids:
|
||||
product_ids.add(ticket.product_id.id)
|
||||
for event_product in self:
|
||||
if event_product.id in product_ids:
|
||||
event_product.visible_in_survey = True
|
||||
else:
|
||||
event_product.visible_in_survey = False
|
||||
|
31
survey_event_visibility/views/event_stage_views.xml
Normal file
31
survey_event_visibility/views/event_stage_views.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0"?>
|
||||
<odoo>
|
||||
<data>
|
||||
<!-- Event stage view form -->
|
||||
<!-- * Add field visible_in_survey -->
|
||||
<record id="event_stage_view_form_survey_event_registration_generation" model="ir.ui.view">
|
||||
<field name="name">event.stage.view.form.survey.event.registration.generation</field>
|
||||
<field name="model">event.stage</field>
|
||||
<field name="inherit_id" ref="event.event_stage_view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="pipe_end" position="after">
|
||||
<field name="visible_in_survey" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Event stage view tree -->
|
||||
<!-- * Add field visible_in_survey -->
|
||||
<record id="event_stage_view_tree_survey_event_registration_generation" model="ir.ui.view">
|
||||
<field name="name">event.stage.view.tree.survey.event.registration.generation</field>
|
||||
<field name="model">event.stage</field>
|
||||
<field name="inherit_id" ref="event.event_stage_view_tree" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="name" position="after">
|
||||
<field name="visible_in_survey" />
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
Reference in New Issue
Block a user