forked from Yaltik/golem
[ADD]GOLEM families functional now, with filters, smart button from GOLEM member...
This commit is contained in:
parent
3f860bb095
commit
5f13c7e95e
@ -15,40 +15,63 @@
|
||||
# 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/>.
|
||||
|
||||
from openerp import models, fields
|
||||
from openerp import models, fields, api, _
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
class GolemMember(models.Model):
|
||||
_inherit = 'golem.member'
|
||||
|
||||
family_ids = fields.Many2many('golem.member.family',
|
||||
string='Family member')
|
||||
family_count = fields.Integer('Family', compute='_compute_family_count')
|
||||
|
||||
# @api.multi
|
||||
# def button_family_members(self):
|
||||
# self.ensure_one()
|
||||
# return {'name': _('Family Members'),
|
||||
# 'type': 'ir.actions.act_window',
|
||||
# 'res_model': 'golem.member.family',
|
||||
# 'view_mode': 'tree',
|
||||
# 'domain': [('memberfrom_id', '=', self[0].id)]}
|
||||
@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)
|
||||
|
||||
@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)]}
|
||||
|
||||
|
||||
class GolemFamily(models.Model):
|
||||
_name = 'golem.member.family'
|
||||
_description = 'GOLEM Member Family'
|
||||
|
||||
memberfrom_id = fields.Many2one('golem.member', 'Family member 1')
|
||||
memberto_id = fields.Many2one('golem.member', string='Family member 2')
|
||||
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.onchange('member_id')
|
||||
# def onchange_member_id(self):
|
||||
# mid = self.env.context.get('default_member_id')
|
||||
# member = self.env['golem.member'].browse([mid])
|
||||
# self.member_id = member.partner_id.id
|
||||
# return self
|
||||
@api.depends('partnerfrom_id', 'partnerto_id', 'relation_id')
|
||||
def _compute_fullrelation(self):
|
||||
for r in self:
|
||||
r.fullrelation = '{} -> {} -> {}'.format(r.partnerfrom_id.name,
|
||||
r.relation_id.name,
|
||||
r.partnerto_id.name)
|
||||
|
||||
@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
|
||||
|
||||
|
||||
class GolemFamilyRelation(models.Model):
|
||||
|
@ -25,27 +25,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<field name="model">golem.member</field>
|
||||
<field name="inherit_id" ref="golem_member.view_form" />
|
||||
<field name="arch" type="xml">
|
||||
<!--
|
||||
<div class="oe_title" position="before">
|
||||
<div class="oe_title" position="after">
|
||||
<div class="oe_right oe_button_box">
|
||||
<button
|
||||
class="oe_inline oe_stat_button" type="object"
|
||||
context="{'default_memberfrom_id': partner_id}"
|
||||
name="button_family_members" icon="fa-list">
|
||||
<field string="Family" name="family_count" widget="statinfo"/>
|
||||
name="button_family_members" icon="fa-users">
|
||||
<field string="Family Relations" name="family_count" widget="statinfo" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
<page name="contact_details" position="after">
|
||||
<page name="family" string="Family">
|
||||
<field name="family_ids" widget="one2many"
|
||||
domain="['|',
|
||||
('memberfrom_id', '=', active_id),
|
||||
('memberto_id', '=', active_id)]"
|
||||
context="{'default_memberfrom_id': active_id}" />
|
||||
</page>
|
||||
</page>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@ -55,14 +43,28 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<field name="model">golem.member.family</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="top">
|
||||
<field name="memberfrom_id" string="Family Member From" />
|
||||
<field name="partnerfrom_id" string="Family Member From" />
|
||||
<field name="relation_id" string="is the ... of" />
|
||||
<field name="memberto_id" string="Family Member To" />
|
||||
<field name="partnerto_id" string="Family Member To" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Searches -->
|
||||
<record id="view_filter" model="ir.ui.view">
|
||||
<field name="name">GOLEM Families Filters</field>
|
||||
<field name="model">golem.member.family</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="fullrelation" />
|
||||
<field name="relation_id" widget="many2one" />
|
||||
<group string="Group By">
|
||||
<filter name="group_relation" string="By relation"
|
||||
context="{'group_by': 'relation_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Actions -->
|
||||
<act_window id="family_action_list" name="GOLEM Family Relations List"
|
||||
|
Loading…
Reference in New Issue
Block a user