/
This commit is contained in:
parent
5b7ac167cb
commit
d652ceaccd
@ -16,7 +16,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Coworking coworker relation',
|
'name': 'Coworking relation',
|
||||||
'summary': 'yaltik coworking module simplify your coworking gerance',
|
'summary': 'yaltik coworking module simplify your coworking gerance',
|
||||||
'description': """ yaltik coworking module simplify your coworking gerance """,
|
'description': """ yaltik coworking module simplify your coworking gerance """,
|
||||||
'version': '10.0.0.0.1',
|
'version': '10.0.0.0.1',
|
||||||
@ -26,6 +26,7 @@
|
|||||||
'application': False,
|
'application': False,
|
||||||
'installable': True,
|
'installable': True,
|
||||||
'data': ['security/ir.model.access.csv',
|
'data': ['security/ir.model.access.csv',
|
||||||
'views/coworker_relation_views.xml', 'models/coworker_relation.py'],
|
'views/relation_views.xml',
|
||||||
|
],
|
||||||
'depends': ['coworking_coworker']
|
'depends': ['coworking_coworker']
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
"""dd"""
|
"""dd"""
|
||||||
from . import coworker_relation, coworker
|
from . import relation, coworker
|
||||||
|
22
coworking_relation/models/coworker.py
Normal file
22
coworking_relation/models/coworker.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
# -*- 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)
|
@ -1,43 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
""" Coworker relation """
|
|
||||||
|
|
||||||
from odoo import models, fields, api, _
|
|
||||||
|
|
||||||
class coworker_relation(models.Model):
|
|
||||||
""" Coworker relation """
|
|
||||||
inherit = 'coworking.coworker'
|
|
||||||
_name = 'coworking.coworker_relation'
|
|
||||||
_description = 'coworker_relation model definition'
|
|
||||||
|
|
||||||
# coworker1 = fields.Many2one(
|
|
||||||
# string="coworker1",
|
|
||||||
# # comodel_name="res.partner",
|
|
||||||
# # domain="[('field', '=', other)]",
|
|
||||||
# # context={"key": "value"},
|
|
||||||
# # ondelete="set null",
|
|
||||||
# # help="Explain your field.",
|
|
||||||
# index=True,
|
|
||||||
# requiered=True
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# coworker2 = fields.Many2one(
|
|
||||||
# string="coworker2",
|
|
||||||
# # comodel_name="res.partner",
|
|
||||||
# # domain="[('field', '=', other)]",
|
|
||||||
# # context={"key": "value"},
|
|
||||||
# # ondelete="set null",
|
|
||||||
# # help="Explain your field.",
|
|
||||||
# index=True,
|
|
||||||
# requiered=True
|
|
||||||
# )
|
|
||||||
#
|
|
||||||
# relation = fields.Char(requiered=True, index=True)
|
|
||||||
#
|
|
||||||
#
|
|
||||||
# @api.constrains('coworker1', 'coworker2')
|
|
||||||
# def _check_coworker_is_same(self):
|
|
||||||
# """test si les coworkers ne sont pas identiques"""
|
|
||||||
# for coworker_relation in self:
|
|
||||||
# if self.coworker1 == self.coworker2:
|
|
||||||
# raise models.ValidationError(_('coworker1 is the same of coworker2'))
|
|
88
coworking_relation/models/relation.py
Normal file
88
coworking_relation/models/relation.py
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
# -*- 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
|
2
coworking_relation/security/ir.model.access.csv
Normal file
2
coworking_relation/security/ir.model.access.csv
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||||
|
acess_coworker_group_user,Access COWORKER Member User,model_coworking_relation,base.group_user,1,1,1,1
|
|
24
coworking_relation/views/coworker_views.xml
Normal file
24
coworking_relation/views/coworker_views.xml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?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>
|
12
coworking_relation/views/relation_menu.xml
Normal file
12
coworking_relation/views/relation_menu.xml
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?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>
|
@ -2,21 +2,19 @@
|
|||||||
|
|
||||||
<odoo>
|
<odoo>
|
||||||
<!-- Form -->
|
<!-- Form -->
|
||||||
<record id="view_form_coworker_relation" model="ir.ui.view">
|
<record id="view_form_relation" model="ir.ui.view">
|
||||||
<field name="name">coworker_relation Form</field>
|
<field name="name">Relation Form</field>
|
||||||
<field name="model">coworking.relation</field>
|
<field name="model">coworking.relation</field>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form string="coworker_relation">
|
<form string="relation">
|
||||||
<sheet>
|
<sheet>
|
||||||
<group name="group_top">
|
<group name="group_top">
|
||||||
<group name="group_left">
|
<group name="group_left">
|
||||||
<field name="coworker1" />
|
|
||||||
<field name="coworker2" />
|
|
||||||
<field name="relation" />
|
|
||||||
</group>
|
</group>
|
||||||
</group>
|
</group>
|
||||||
</sheet>
|
</sheet>
|
||||||
</form>
|
</form>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
Loading…
Reference in New Issue
Block a user