Coworking/coworking_relation/models/res_partner.py

41 lines
1.4 KiB
Python
Raw Normal View History

2017-11-16 15:47:18 +01:00
# -*- coding: utf-8 -*-
""" Coworker adaptations """
2017-11-21 12:47:42 +01:00
import logging
2017-11-16 15:47:18 +01:00
from odoo import models, fields, api
2017-11-21 12:47:42 +01:00
_LOGGER = logging.getLogger(__name__)
2017-11-16 15:47:18 +01:00
2017-11-24 17:16:20 +01:00
class ResPartner(models.Model):
2017-11-16 15:47:18 +01:00
""" Coworker adaptations """
2017-11-24 17:16:20 +01:00
_inherit = 'res.partner'
2017-11-16 15:47:18 +01:00
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')
2017-11-20 14:48:26 +01:00
#Relation fields
2017-11-20 15:24:48 +01:00
2017-11-21 12:47:42 +01:00
coworker_relation_ids = fields.One2many(
string="Relations",
2017-11-20 15:21:38 +01:00
comodel_name="coworking.relation",
2017-11-21 12:47:42 +01:00
inverse_name="coworker2",
compute="_compute_coworker_relation_ids")
2017-11-16 15:47:18 +01:00
@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)
2017-11-21 12:47:42 +01:00
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)