assistant
This commit is contained in:
parent
5e0cd006d5
commit
00ecfada76
@ -7,6 +7,8 @@
|
||||
res_model="coworking.event" view_mode="tree,form,calendar"
|
||||
context="{'search_default_status_confirmed': True, 'search_default_status_draft': True}" />
|
||||
<!-- Menu item to open Event list -->
|
||||
<menuitem id="event_menu" name="Event" action="event_action" />
|
||||
<menuitem id="event_topmenu" name="Event" />
|
||||
<menuitem id="event_menu" name="Events" action="event_action"
|
||||
parent="event_topmenu" sequence="1" />
|
||||
|
||||
</odoo>
|
||||
|
@ -2,9 +2,62 @@
|
||||
|
||||
""" Weekly massive event creation module """
|
||||
|
||||
from odoo import models, fields, api
|
||||
import logging
|
||||
from datetime import timedelta
|
||||
from odoo import models, fields, api, _
|
||||
from odoo.exceptions import ValidationError
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
class CoworkingEventWeekly(models.TransientModel):
|
||||
""" Weekly massive event creation """
|
||||
_name = 'coworking.event.weekly'
|
||||
_description = 'Weekly massive event creation'
|
||||
|
||||
title = fields.Char(required=True)
|
||||
manager_id = fields.Many2one('coworking.coworker', string='Manager',
|
||||
required=True)
|
||||
date_start_recurence = fields.Datetime('Date start', required=True)
|
||||
date_stop_recurence = fields.Datetime('Date stop', required=True)
|
||||
duration = fields.Float(required=True)
|
||||
|
||||
@api.constrains('date_start_recurence', 'date_stop_recurence')
|
||||
def _check_dates(self):
|
||||
""" Check date coherence """
|
||||
for weekly in self:
|
||||
if weekly.date_start_recurence > weekly.date_stop_recurence:
|
||||
raise ValidationError(_('Please check you dates.'))
|
||||
|
||||
@api.multi
|
||||
def weekly_create(self):
|
||||
""" Create multiple events repeated weekly, according to dates """
|
||||
self.ensure_one()
|
||||
# 5 - Rediriger vers la liste des événements (en automatique)
|
||||
# _LOGGER.warning()
|
||||
date_start_py = fields.Datetime.from_string(self.date_start_recurence)
|
||||
delta = timedelta(hours=self.duration)
|
||||
|
||||
date_stop_py = fields.Datetime.from_string(self.date_stop_recurence)
|
||||
week_start = date_start_py.isocalendar()[1]
|
||||
week_stop = date_stop_py.isocalendar()[1]
|
||||
week_count = week_stop - week_start + 1
|
||||
wdelta = timedelta(days=7)
|
||||
|
||||
for week_number in xrange(week_count):
|
||||
if week_number == 0:
|
||||
date_start = self.date_start_recurence
|
||||
date_stop = fields.Datetime.to_string(date_start_py + delta)
|
||||
else:
|
||||
date_start = fields.Datetime.from_string(self.date_start_recurence) +\
|
||||
wdelta * week_number
|
||||
date_stop = fields.Datetime.to_string(date_start + delta)
|
||||
date_start = fields.Datetime.to_string(date_start)
|
||||
self.env['coworking.event'].create({
|
||||
'title': self.title,
|
||||
'date_start': date_start,
|
||||
'date_end': date_stop,
|
||||
'manager_id': self.manager_id.id
|
||||
})
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'coworking.event',
|
||||
'view_mode': 'tree'}
|
||||
|
@ -1,4 +1,38 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<odoo>
|
||||
|
||||
<!-- Form -->
|
||||
<record id="view_form_weekly_event" model="ir.ui.view">
|
||||
<field name="name">Event Weekly Form</field>
|
||||
<field name="model">coworking.event.weekly</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="event">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="title" />
|
||||
<field name="manager_id" />
|
||||
<field name="date_start_recurence" />
|
||||
<field name="date_stop_recurence" />
|
||||
<field name="duration" widget="float_time" />
|
||||
</group>
|
||||
</sheet>
|
||||
<footer>
|
||||
<button type="object" name="weekly_create" string="Create"
|
||||
class="oe_highlight" />
|
||||
<button string="Close" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Action -->
|
||||
<act_window id="weekly_event_action" name="Weekly event"
|
||||
res_model="coworking.event.weekly" view_mode="form"
|
||||
target="new" />
|
||||
|
||||
<!-- Menu -->
|
||||
<menuitem id="weekly_event_menu" name="Weekly events" action="weekly_event_action"
|
||||
parent="event_topmenu" sequence="5" />
|
||||
|
||||
</odoo>
|
||||
|
Loading…
Reference in New Issue
Block a user