_compute_coworker_relation_ids

This commit is contained in:
michel 2017-11-21 12:47:42 +01:00
parent 78ff3e754f
commit 16758eec6d
2 changed files with 17 additions and 12 deletions

View File

@ -2,7 +2,9 @@
""" Coworker adaptations """ """ Coworker adaptations """
import logging
from odoo import models, fields, api from odoo import models, fields, api
_LOGGER = logging.getLogger(__name__)
class Coworker(models.Model): class Coworker(models.Model):
""" Coworker adaptations """ """ Coworker adaptations """
@ -16,19 +18,23 @@ class Coworker(models.Model):
compute='_compute_events_coworker_count') compute='_compute_events_coworker_count')
#Relation fields #Relation fields
coworker1_relation_ids = fields.One2many( coworker_relation_ids = fields.One2many(
string="Relation", string="Relations",
comodel_name="coworking.relation", comodel_name="coworking.relation",
inverse_name="coworker1" inverse_name="coworker2",
) compute="_compute_coworker_relation_ids")
coworker2_relation_ids = fields.One2many(
string="Relation with you",
comodel_name="coworking.relation",
inverse_name="coworker2"
)
@api.depends('event_ids') @api.depends('event_ids')
def _compute_events_coworker_count(self): def _compute_events_coworker_count(self):
""" Computes number of event coworker """ """ Computes number of event coworker """
for event in self: for event in self:
event.events_coworker_count = len(event.event_ids) 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)

View File

@ -11,8 +11,7 @@
<notebook position="inside"> <notebook position="inside">
<page string="Relation" name="Relation"> <page string="Relation" name="Relation">
<group name="relation"> <group name="relation">
<field name="coworker1_relation_ids" context="{'default_coworker1': active_id}" /> <field name="coworker_relation_ids" />
<field name="coworker2_relation_ids" context="{'default_coworker2': active_id}" />
</group> </group>
</page> </page>
</notebook> </notebook>