41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
|
|
""" Coworker adaptations """
|
|
|
|
import logging
|
|
from odoo import models, fields, api
|
|
_LOGGER = logging.getLogger(__name__)
|
|
|
|
class ResPartner(models.Model):
|
|
""" Coworker adaptations """
|
|
_inherit = 'res.partner'
|
|
|
|
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')
|
|
#Relation fields
|
|
|
|
coworker_relation_ids = fields.One2many(
|
|
string="Relations",
|
|
comodel_name="coworking.relation",
|
|
inverse_name="coworker2",
|
|
compute="_compute_coworker_relation_ids")
|
|
|
|
|
|
@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)
|
|
|
|
def _compute_coworker_relation_ids(self):
|
|
""" Computes coworker1_relation_ids and coworker2_relation_ids """
|
|
for coworker in self:
|
|
relation_model = self.env['coworking.relation']
|
|
domain = ('|', ['coworker1', '=', coworker.id],
|
|
['coworker2', '=', coworker.id])
|
|
coworker.coworker_relation_ids = relation_model.search(domain)
|