This commit is contained in:
michel 2017-11-14 17:19:02 +01:00
parent c47575ce45
commit 168f28d0c9
3 changed files with 45 additions and 20 deletions

View File

@ -2,6 +2,7 @@
""" Event module """ """ Event module """
from datetime import datetime
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
@ -15,17 +16,39 @@ class Event(models.Model):
manager_id = fields.Many2one('coworking.coworker', 'Manager', index=True, manager_id = fields.Many2one('coworking.coworker', 'Manager', index=True,
domain="[('coworker_type', 'in', ['staffer', 'member'])]") domain="[('coworker_type', 'in', ['staffer', 'member'])]")
date_start = fields.Datetime(default=fields.Date.context_today, required=True) date_start = fields.Datetime(default=fields.Date.context_today, required=True)
starts_this_week = fields.Integer(compute='_compute_starts_this_week',
search='_search_starts_this_week')
date_end = fields.Datetime(required=True) date_end = fields.Datetime(required=True)
duration = fields.Float(compute='_compute_duration') duration = fields.Float(compute='_compute_duration')
description = fields.Text() description = fields.Text()
statut = fields.Selection([('draft', 'Draft'), statut = fields.Selection([('draft', 'Draft'),
('confirmed', 'Confirmed'), ('confirmed', 'Confirmed'),
('canceled', 'Canceled')], default='draft') ('canceled', 'Canceled')], default='canceled')
participants_ids = fields.Many2many('coworking.coworker', string='Subscribers') participants_ids = fields.Many2many('coworking.coworker', string='Subscribers')
participants_count = fields.Integer('Number of participants', participants_count = fields.Integer('Number of participants',
compute='_compute_participants_count') compute='_compute_participants_count')
participants_count2 = fields.Integer('Number of participants #2',
compute='_compute_participants_count')
@api.depends('date_start')
def _compute_starts_this_week(self):
""" Computes is event starts this week """
for event in self:
date_start = fields.Datetime.from_string(event.date_start)
week_start = date_start.isocalendar()[1]
event.starts_this_week = (datetime.now().isocalendar()[1] == week_start)
def _search_starts_this_week(self, operator, value):
""" Searches function for starts_this_week """
res_ids = []
for event in self.search([]):
date_start = fields.Datetime.from_string(event.date_start)
week_start = date_start.isocalendar()[1]
if datetime.now().isocalendar()[1] == week_start:
res_ids.append(event.id)
return [('id', 'in', res_ids)]
@api.depends('participants_ids') @api.depends('participants_ids')
def _compute_participants_count(self): def _compute_participants_count(self):

View File

@ -4,7 +4,8 @@
<!-- Action to open Coworkers list --> <!-- Action to open Coworkers list -->
<act_window id="event_action" name="Event" <act_window id="event_action" name="Event"
res_model="coworking.event" view_mode="tree,form" /> res_model="coworking.event" view_mode="tree,form"
context="{'search_default_status_confirmed': True, 'search_default_status_draft': True}" />
<!-- Menu item to open Event list --> <!-- Menu item to open Event list -->
<menuitem id="event_menu" name="Event" action="event_action" /> <menuitem id="event_menu" name="Event" action="event_action" />

View File

@ -16,6 +16,7 @@
<field name="title" /> <field name="title" />
<field name="manager_id" /> <field name="manager_id" />
<field name="date_start" /> <field name="date_start" />
<field name="starts_this_week" attrs="{'invisible': [('date_start', '=', True)]}" />
<field name="date_end" /> <field name="date_end" />
<field name="duration" /> <field name="duration" />
<field name="description" /> <field name="description" />
@ -50,30 +51,30 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<search> <search>
<field name="title" /> <field name="title" />
<field name="manager" /> <field name="manager_id" />
<filter name="Satut" string="confirmed" <filter name="status_confirmed" string="Confirmed"
domain="[('statut','!=',False)]" /> domain="[('statut','=','confirmed')]" />
<filter name="status_draft" string="Draft"
<filter name="in_compagny" string="in_compagny" domain="[('statut','=','draft')]" />
domain="[('company_name','!=',False)]" /> <filter name="canceled" string="Canceled"
domain="[('statut','=','canceled')]" />
<separator /> <separator />
<filter name="this_week" string="Starts this week"
domain="[('starts_this_week','=', True)]" />
<filter name="is_savoyar" string="Is_savoyar" <filter name="this_30_month" string="Starts 30 month"
domain="[('contact_zip','=like','73___')]" /> domain="[('date_start','&lt;=', datetime.datetime.combine(context_today() + datetime.timedelta(days=30), datetime.time(23,59,59))),
('date_start','&gt;=', datetime.datetime.combine(context_today(), datetime.time(0,0,0)))]" />
<filter name="meet_of_2017" string="Meet_of_2017" <filter name="group_status" string="Group status"
domain="[('contact_date','like','2017')]" /> context="{'group_by': 'statut'}" />
<filter name="group_manager_id" string="Group manager"
context="{'group_by': 'manager_id'}" />
<filter name="group_years_start" string="Group years start"
context="{'group_by': 'date_start:years'}" />
<filter name="group_city" string="Group city"
context="{'group_by': 'city'}" />
<filter name="group_month" string="Group month"
context="{'group_by': 'contact_date'}" />
<filter name="group_years" string="Group years"
context="{'group_by': 'contact_date:year'}" />
</search> </search>
</field> </field>