diff --git a/coworking_relation/__manifest__.py b/coworking_relation/__manifest__.py
index bb40c4c..75c49bf 100644
--- a/coworking_relation/__manifest__.py
+++ b/coworking_relation/__manifest__.py
@@ -16,7 +16,7 @@
# along with this program. If not, see .
{
- 'name': 'Coworking coworker relation',
+ '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',
@@ -26,6 +26,7 @@
'application': False,
'installable': True,
'data': ['security/ir.model.access.csv',
- 'views/coworker_relation_views.xml', 'models/coworker_relation.py'],
+ 'views/relation_views.xml',
+ ],
'depends': ['coworking_coworker']
}
diff --git a/coworking_relation/models/__init__.py b/coworking_relation/models/__init__.py
index 494e37c..101cb73 100644
--- a/coworking_relation/models/__init__.py
+++ b/coworking_relation/models/__init__.py
@@ -1,3 +1,3 @@
# -*- coding: utf-8 -*-
"""dd"""
-from . import coworker_relation, coworker
+from . import relation, coworker
diff --git a/coworking_relation/models/coworker.py b/coworking_relation/models/coworker.py
new file mode 100644
index 0000000..f556f3d
--- /dev/null
+++ b/coworking_relation/models/coworker.py
@@ -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)
diff --git a/coworking_relation/models/coworker_relation.py b/coworking_relation/models/coworker_relation.py
deleted file mode 100644
index ccb8a38..0000000
--- a/coworking_relation/models/coworker_relation.py
+++ /dev/null
@@ -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'))
diff --git a/coworking_relation/models/relation.py b/coworking_relation/models/relation.py
new file mode 100644
index 0000000..cec3c3c
--- /dev/null
+++ b/coworking_relation/models/relation.py
@@ -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
diff --git a/coworking_relation/security/ir.model.access.csv b/coworking_relation/security/ir.model.access.csv
new file mode 100644
index 0000000..3c94e5e
--- /dev/null
+++ b/coworking_relation/security/ir.model.access.csv
@@ -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
diff --git a/coworking_relation/views/coworker_views.xml b/coworking_relation/views/coworker_views.xml
new file mode 100644
index 0000000..43261e2
--- /dev/null
+++ b/coworking_relation/views/coworker_views.xml
@@ -0,0 +1,24 @@
+
+
+
+
+
+
+ Coworker Form adaptations
+ coworking.coworker
+
+
+
+
+
+
+
diff --git a/coworking_relation/views/relation_menu.xml b/coworking_relation/views/relation_menu.xml
new file mode 100644
index 0000000..3979a09
--- /dev/null
+++ b/coworking_relation/views/relation_menu.xml
@@ -0,0 +1,12 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/coworking_relation/views/coworker_relation_views.xml b/coworking_relation/views/relation_views.xml
similarity index 52%
rename from coworking_relation/views/coworker_relation_views.xml
rename to coworking_relation/views/relation_views.xml
index 99ec96a..f47ac9c 100644
--- a/coworking_relation/views/coworker_relation_views.xml
+++ b/coworking_relation/views/relation_views.xml
@@ -2,21 +2,19 @@
-
- coworker_relation Form
+
+ Relation Form
coworking.relation
-
+