forked from Yaltik/golem
[CHG][WIP]Major change to GOLEM Family : a family has now its own entity and members are qualified upon this
This commit is contained in:
parent
78021f62bd
commit
eabb116aa7
@ -19,12 +19,12 @@
|
||||
'name': 'GOLEM families',
|
||||
'summary': 'GOLEM Members Families',
|
||||
'description': ''' Non-profit french MJC members families management ''',
|
||||
'version': '0.1',
|
||||
'version': '0.2',
|
||||
'category': 'Non-profit management',
|
||||
'author': 'Fabien Bourgeois',
|
||||
'license': 'AGPL-3',
|
||||
'application': False,
|
||||
'installable': True,
|
||||
'depends': ['golem_member'],
|
||||
'data': ['views/golem_member_view.xml']
|
||||
'data': ['views/golem_family_view.xml']
|
||||
}
|
||||
|
@ -18,67 +18,64 @@
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
|
||||
class GolemMember(models.Model):
|
||||
_inherit = 'golem.member'
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
_description = 'GOLEM Partner Family'
|
||||
|
||||
family_count = fields.Integer('Family', compute='_compute_family_count')
|
||||
|
||||
@api.one
|
||||
def _compute_family_count(self):
|
||||
pid = self.partner_id.id
|
||||
dmn = ['|', ('partnerfrom_id', '=', pid), ('partnerto_id', '=', pid)]
|
||||
self.family_count = self.env['golem.member.family'].search_count(dmn)
|
||||
family_id = fields.Many2one('golem.family', string='Family', index=True)
|
||||
family_role = fields.Many2one('golem.member.family.role',
|
||||
string='Role', index=True)
|
||||
family_count = fields.Integer('Family Count', related='family_id.count')
|
||||
|
||||
@api.multi
|
||||
def button_family_members(self):
|
||||
self.ensure_one()
|
||||
pid = self.partner_id.id
|
||||
return {'name': _('Family Members'),
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': 'golem.member.family',
|
||||
'view_mode': 'tree',
|
||||
'context': {'default_partnerfrom_id': pid},
|
||||
'domain': ['|',
|
||||
('partnerfrom_id', '=', pid),
|
||||
('partnerto_id', '=', pid)]}
|
||||
'res_model': 'golem.family',
|
||||
'view_mode': 'form',
|
||||
'domain': [('id', '=', self.family_id.id)]}
|
||||
|
||||
|
||||
class GolemFamily(models.Model):
|
||||
_name = 'golem.member.family'
|
||||
_description = 'GOLEM Member Family'
|
||||
_name = 'golem.family'
|
||||
_description = 'GOLEM Family Entity'
|
||||
_inherit = 'mail.thread'
|
||||
|
||||
partnerfrom_id = fields.Many2one('res.partner', 'Family member from',
|
||||
required=True, index=True,
|
||||
domain=[('is_company', '=', False)])
|
||||
partnerto_id = fields.Many2one('res.partner', 'Family member to',
|
||||
required=True, index=True,
|
||||
domain=[('is_company', '=', False)])
|
||||
relation_id = fields.Many2one('golem.member.family.relation',
|
||||
required=True, index=True,
|
||||
string='Family relation')
|
||||
fullrelation = fields.Char('Full relation string',
|
||||
compute='_compute_fullrelation', store=True)
|
||||
@api.model
|
||||
def _get_default_nationality_id(self):
|
||||
return self.env.ref('base.main_company').country_id
|
||||
|
||||
@api.depends('partnerfrom_id', 'partnerto_id', 'relation_id')
|
||||
def _compute_fullrelation(self):
|
||||
for r in self:
|
||||
r.fullrelation = u'{} -> {} -> {}'.format(r.partnerfrom_id.name,
|
||||
r.relation_id.name,
|
||||
r.partnerto_id.name)
|
||||
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')
|
||||
|
||||
@api.onchange('partnerfrom_id')
|
||||
def onchange_partnerfrom_id(self):
|
||||
""" If tree from member, use ctx default partner to populate from """
|
||||
default_pid = self.env.context.get('default_partnerfrom_id')
|
||||
if default_pid:
|
||||
self.partnerfrom_id = default_pid
|
||||
member_ids = fields.One2many('res.partner', 'family_id', 'Members')
|
||||
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)
|
||||
|
||||
|
||||
class GolemFamilyRelation(models.Model):
|
||||
_name = 'golem.member.family.relation'
|
||||
_description = 'GOLEM Member Family Relation'
|
||||
_sql_constraints = [('golem_member_family_relation_name_uniq',
|
||||
class GolemFamilyRole(models.Model):
|
||||
_name = 'golem.member.family.role'
|
||||
_description = 'GOLEM Member Family Role'
|
||||
_sql_constraints = [('golem_member_family_role_name_uniq',
|
||||
'UNIQUE (name)',
|
||||
'Family relation must be unique.')]
|
||||
'Family role must be unique.')]
|
||||
|
||||
name = fields.Char('Relation')
|
||||
name = fields.Char('Role')
|
||||
|
131
golem_family/views/golem_family_view.xml
Normal file
131
golem_family/views/golem_family_view.xml
Normal file
@ -0,0 +1,131 @@
|
||||
<?xml version="1.0" encoding="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/>.
|
||||
-->
|
||||
|
||||
<openerp>
|
||||
<data>
|
||||
<!-- Forms -->
|
||||
<record id="view_form" model="ir.ui.view">
|
||||
<field name="name">GOLEM Family Form</field>
|
||||
<field name="model">golem.family</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<div class="oe_title">
|
||||
<h1>
|
||||
<field name="name" class="oe_inline" placeholder="Name" />
|
||||
</h1>
|
||||
</div>
|
||||
</group>
|
||||
<group string="Address">
|
||||
<group>
|
||||
<field name="street" placeholder="Street..." />
|
||||
<field name="street2" />
|
||||
<field name="zip" placeholder="ZIP" />
|
||||
<field name="city" placeholder="City" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="state_id" class="oe_no_button"
|
||||
placeholder="State" />
|
||||
<field name="country_id" placeholder="Country"
|
||||
class="oe_no_button" />
|
||||
</group>
|
||||
</group>
|
||||
<group string="Communication">
|
||||
<group>
|
||||
<field name="phone" placeholder="0000000000"
|
||||
widget="phonefr" />
|
||||
<field name="mobile" placeholder="0000000000"
|
||||
widget="phonefr" />
|
||||
</group>
|
||||
<group>
|
||||
<field name="email" widget="email"
|
||||
placeholder="name@example.org" />
|
||||
<field name="website" widget="url"
|
||||
placeholder="e.g. www.odoo.com"/>
|
||||
</group>
|
||||
</group>
|
||||
<notebook>
|
||||
<page string="Family members">
|
||||
<field name="member_ids" widget="many2many">
|
||||
<tree>
|
||||
<field name="name" />
|
||||
<field name="family_role" />
|
||||
<field name="phone" />
|
||||
<field name="mobile" />
|
||||
<field name="email" widget="email" />
|
||||
</tree>
|
||||
</field>
|
||||
</page>
|
||||
<page string="Others">
|
||||
<group>
|
||||
<field name="note" placeholder="Put an internal note..." />
|
||||
</group>
|
||||
</page>
|
||||
</notebook>
|
||||
</sheet>
|
||||
<div class="oe_chatter">
|
||||
<field name="message_follower_ids" widget="mail_followers" />
|
||||
<field name="message_ids" widget="mail_thread" />
|
||||
</div>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Trees -->
|
||||
<record id="family_tree" model="ir.ui.view">
|
||||
<field name="name">Family list</field>
|
||||
<field name="model">golem.family</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="count" string="# Members" />
|
||||
<field name="name" />
|
||||
<field name="city" />
|
||||
<field name="email" />
|
||||
<field name="phone" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
<record id="family_role_tree" model="ir.ui.view">
|
||||
<field name="name">Family Role List</field>
|
||||
<field name="model">golem.member.family.role</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="top">
|
||||
<field name="name" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Searches -->
|
||||
|
||||
<!-- Actions -->
|
||||
<act_window id="family_action_list" name="GOLEM Family List"
|
||||
res_model="golem.family" view_mode="tree,form" />
|
||||
<act_window id="family_role_action" name="GOLEM Family Role List"
|
||||
res_model="golem.member.family.role" view_mode="tree" />
|
||||
<!-- Menus -->
|
||||
<menuitem id="family_menu_list" name="Families"
|
||||
parent="membership.menu_membership" action="family_action_list"
|
||||
sequence="10" />
|
||||
<menuitem id="family_role_menu_list" name="Family Roles"
|
||||
parent="base.menu_marketing_config_association"
|
||||
action="family_role_action" sequence="3" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
Loading…
Reference in New Issue
Block a user