2016-06-26 17:23:23 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com>
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2016-06-27 08:10:54 +02:00
|
|
|
from openerp import models, fields, api, _
|
2016-06-26 17:23:23 +02:00
|
|
|
|
|
|
|
|
2016-07-08 19:28:00 +02:00
|
|
|
class ResPartner(models.Model):
|
|
|
|
_inherit = 'res.partner'
|
|
|
|
_description = 'GOLEM Partner Family'
|
2016-06-26 17:23:23 +02:00
|
|
|
|
2016-07-08 19:28:00 +02:00
|
|
|
family_id = fields.Many2one('golem.family', string='Family', index=True)
|
2016-07-21 16:45:54 +02:00
|
|
|
family_role = fields.Many2one('golem.family.role', string='Role',
|
|
|
|
index=True)
|
2016-07-08 19:28:00 +02:00
|
|
|
family_count = fields.Integer('Family Count', related='family_id.count')
|
2016-06-27 08:10:54 +02:00
|
|
|
|
2016-07-11 20:13:34 +02:00
|
|
|
@api.multi
|
|
|
|
def button_family_members(self):
|
|
|
|
self.ensure_one()
|
|
|
|
return {'name': _('Family Members'),
|
|
|
|
'type': 'ir.actions.act_window',
|
|
|
|
'res_model': 'golem.family',
|
|
|
|
'view_mode': 'form',
|
|
|
|
'res_id': self.family_id.id}
|
|
|
|
|
2016-07-08 22:00:22 +02:00
|
|
|
|
|
|
|
class GolemMember(models.Model):
|
|
|
|
_inherit = 'golem.member'
|
|
|
|
|
2016-07-13 20:11:56 +02:00
|
|
|
@api.onchange('family_id')
|
|
|
|
def onchange_family(self):
|
|
|
|
""" Sets lastname as family name if there was no precedence """
|
|
|
|
for p in self:
|
|
|
|
if not p.lastname:
|
|
|
|
p.lastname = self.family_id.name
|
|
|
|
|
2016-06-27 08:10:54 +02:00
|
|
|
@api.multi
|
|
|
|
def button_family_members(self):
|
|
|
|
self.ensure_one()
|
|
|
|
return {'name': _('Family Members'),
|
|
|
|
'type': 'ir.actions.act_window',
|
2016-07-08 19:28:00 +02:00
|
|
|
'res_model': 'golem.family',
|
|
|
|
'view_mode': 'form',
|
2016-07-08 22:00:22 +02:00
|
|
|
'res_id': self.family_id.id}
|
2016-06-26 17:23:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GolemFamily(models.Model):
|
2016-07-08 19:28:00 +02:00
|
|
|
_name = 'golem.family'
|
|
|
|
_description = 'GOLEM Family Entity'
|
|
|
|
_inherit = 'mail.thread'
|
2016-06-26 17:23:23 +02:00
|
|
|
|
2016-07-08 19:28:00 +02:00
|
|
|
@api.model
|
|
|
|
def _get_default_nationality_id(self):
|
|
|
|
return self.env.ref('base.main_company').country_id
|
2016-06-27 08:10:54 +02:00
|
|
|
|
2016-07-08 19:28:00 +02:00
|
|
|
name = fields.Char('Name', index=True, required=True)
|
|
|
|
street = fields.Char('Street')
|
|
|
|
street2 = fields.Char('Street2')
|
|
|
|
zip = fields.Char('Zip')
|
|
|
|
city = fields.Char('City')
|
|
|
|
state_id = fields.Many2one('res.country.state', 'State',
|
|
|
|
ondelete='restrict')
|
|
|
|
country_id = fields.Many2one('res.country', 'Country',
|
|
|
|
ondelete='restrict',
|
|
|
|
default=_get_default_nationality_id)
|
|
|
|
phone = fields.Char('Phone')
|
|
|
|
mobile = fields.Char('Mobile')
|
|
|
|
email = fields.Char('Email')
|
|
|
|
website = fields.Char('Website')
|
2016-06-26 17:23:23 +02:00
|
|
|
|
2016-07-13 20:06:35 +02:00
|
|
|
member_ids = fields.One2many('res.partner', 'family_id', 'Members',
|
|
|
|
domain=[('is_company', '=', False)])
|
2016-07-08 19:28:00 +02:00
|
|
|
note = fields.Text('Note')
|
|
|
|
count = fields.Integer('Count', compute='_compute_count', store=True)
|
|
|
|
|
|
|
|
@api.one
|
|
|
|
@api.depends('member_ids')
|
|
|
|
def _compute_count(self):
|
|
|
|
self.count = len(self.member_ids)
|
2016-06-26 17:23:23 +02:00
|
|
|
|
|
|
|
|
2016-07-08 19:28:00 +02:00
|
|
|
class GolemFamilyRole(models.Model):
|
2016-07-21 16:45:54 +02:00
|
|
|
_name = 'golem.family.role'
|
|
|
|
_description = 'GOLEM Family Role'
|
|
|
|
_sql_constraints = [('golem_family_role_name_uniq',
|
2016-06-26 17:23:23 +02:00
|
|
|
'UNIQUE (name)',
|
2016-07-08 19:28:00 +02:00
|
|
|
'Family role must be unique.')]
|
2016-06-26 17:23:23 +02:00
|
|
|
|
2016-07-08 19:28:00 +02:00
|
|
|
name = fields.Char('Role')
|