Base relation module

This commit is contained in:
michel 2017-11-16 14:53:35 +01:00
parent d652ceaccd
commit 640ac54867
7 changed files with 0 additions and 201 deletions

View File

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
from . import models

View File

@ -1,32 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2017 Firstname Lastname <firstname.lastname@company.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
'name': 'Coworking relation',
'summary': 'yaltik coworking module simplify your coworking gerance',
'description': """ yaltik coworking module simplify your coworking gerance """,
'version': '10.0.0.0.1',
'category': 'Coworking',
'author': 'Yaltik',
'license': 'AGPL-3',
'application': False,
'installable': True,
'data': ['security/ir.model.access.csv',
'views/relation_views.xml',
],
'depends': ['coworking_coworker']
}

View File

@ -1,22 +0,0 @@
# -*- coding: utf-8 -*-
""" Coworker adaptations """
from odoo import models, fields, api
class Coworker(models.Model):
""" Coworker adaptations """
_inherit = 'coworking.coworker'
manager_event_ids = fields.One2many('coworking.event', 'manager_id',
string='Events managed')
event_ids = fields.Many2many('coworking.event', string='Events visited')
events_coworker_count = fields.Integer('Number of event have participe',
compute='_compute_events_coworker_count')
@api.depends('event_ids')
def _compute_events_coworker_count(self):
""" Computes number of event coworker """
for event in self:
event.events_coworker_count = len(event.event_ids)

View File

@ -1,88 +0,0 @@
# -*- coding: utf-8 -*-
""" relation module """
from datetime import datetime
from odoo import models, fields, api, _
from odoo.exceptions import ValidationError
class relation(models.Model):
""" relation model """
_name = 'coworking.relation'
_description = 'relation model definition'
_rec_name = 'title'
_order = 'id asc'
title = fields.Char(required=True)
manager_id = fields.Many2one('coworking.coworker', 'Manager', index=True, required=True,
domain="[('coworker_type', 'in', ['staffer', 'member'])]")
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)
duration = fields.Float(compute='_compute_duration')
description = fields.Text()
statut = fields.Selection([('draft', 'Draft'),
('confirmed', 'Confirmed'),
('canceled', 'Canceled')], default='draft')
participants_ids = fields.Many2many('coworking.coworker', string='Subscribers')
participants_count = fields.Integer('Number of participants',
compute='_compute_participants_count')
@api.depends('date_start')
def _compute_starts_this_week(self):
""" Computes is relation starts this week """
for relation in self:
date_start = fields.Datetime.from_string(relation.date_start)
week_start = date_start.isocalendar()[1]
relation.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 relation in self.search([]):
date_start = fields.Datetime.from_string(relation.date_start)
week_start = date_start.isocalendar()[1]
if datetime.now().isocalendar()[1] == week_start:
res_ids.append(relation.id)
if operator == '=':
operator = 'in'if value else 'not in'
else:
operator = 'not in'if value else 'in'
return [('id', operator, res_ids)]
@api.depends('participants_ids')
def _compute_participants_count(self):
""" Computes number of participants """
for relation in self:
relation.participants_count = len(relation.participants_ids)
@api.constrains('statut', 'participants_ids')
def _check_if_confirmed(self):
"""Test si participants_ids est confirmed"""
for relation in self:
if relation.participants_ids and relation.statut == 'draft':
raise models.ValidationError(_('You can have subscribed people '
'if relation is not confirmed yet'))
@api.constrains('date_start', 'date_end')
def _check_dates(self):
"""Test si la modification de la date de début est infnérieure à la date de fin"""
if self.date_start > self.date_end:
raise ValidationError(_('End date most be supperior to to start date'))
@api.depends('date_start', 'date_end')
def _compute_duration(self):
for relation in self:
if relation.date_start and relation.date_end:
date_end_py = fields.Datetime.from_string(relation.date_end)
date_start_py = fields.Datetime.from_string(relation.date_start)
delta = date_end_py - date_start_py
relation.duration = delta.days * 24.0 + round(float(delta.seconds) / 3600.0)
else:
relation.duration = 0.0

View File

@ -1,24 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Form -->
<record id="view_form_coworker" model="ir.ui.view">
<field name="name">Coworker Form adaptations</field>
<field name="model">coworking.coworker</field>
<field name="inherit_id" ref ="coworking_coworker.view_form_coworker" />
<field name="arch" type="xml">
<!-- <notebook position="inside">
<page string="Relations" name="Relations">
<group name="relation">
<field name="manager_relation_ids"
context="{'default_manager_id': active_id}" />
<field name="relation_ids" />
<field name="relation_coworker_count" />
</group>
</page>
</notebook> -->
</field>
</record>
</odoo>

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Action to open Coworkers list -->
<act_window id="relation_action" name="Relation"
res_model="coworking.relation" view_mode="tree,form,calendar"
context="{'search_default_status_confirmed': True, 'search_default_status_draft': True}" />
<!-- Menu item to open Relation list -->
<menuitem id="relation_menu" name="Relation" action="relation_action" />
</odoo>

View File

@ -1,20 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Form -->
<record id="view_form_relation" model="ir.ui.view">
<field name="name">Relation Form</field>
<field name="model">coworking.relation</field>
<field name="arch" type="xml">
<form string="relation">
<sheet>
<group name="group_top">
<group name="group_left">
</group>
</group>
</sheet>
</form>
</field>
</record>
</odoo>