forked from Yaltik/golem
[REF][IMP]Huge refactoring and small enhanceme GOLEM Member Precreation Search
This commit is contained in:
parent
ffa453d2c8
commit
5e557edf22
@ -19,7 +19,7 @@
|
||||
{
|
||||
'name': 'GOLEM Pre-creation search member',
|
||||
'summary': 'Pre-creation search member',
|
||||
'version': '10.0.0.1.0',
|
||||
'version': '10.0.0.2.0',
|
||||
'category': 'GOLEM',
|
||||
'author': 'Fabien Bourgeois, Youssef El ouahby',
|
||||
'license': 'AGPL-3',
|
||||
@ -27,6 +27,5 @@
|
||||
'installable': True,
|
||||
'depends': ['golem_member'],
|
||||
'data': ['views/golem_member_precreation_search_menu.xml',
|
||||
'wizard/golem_member_precreation_search_views.xml',
|
||||
'wizard/golem_precreation_member_result_wizard_views.xml']
|
||||
'wizard/golem_member_precreation_search_views.xml']
|
||||
}
|
||||
|
@ -16,4 +16,4 @@
|
||||
# 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 . import res_partner
|
||||
from . import res_partner, golem_member
|
||||
|
40
golem_member_precreation_search/models/golem_member.py
Normal file
40
golem_member_precreation_search/models/golem_member.py
Normal file
@ -0,0 +1,40 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2018 Youssef El Ouahby <youssef@yaltik.com>
|
||||
# Copyright 2018 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/>.
|
||||
|
||||
""" GOLEM Member adaptations """
|
||||
|
||||
from odoo import models, api, _
|
||||
|
||||
class GolemMember(models.Model):
|
||||
""" GOLEM Member extention """
|
||||
_inherit = 'golem.member'
|
||||
|
||||
@api.multi
|
||||
def navigate_to_contact(self):
|
||||
""" Navigates to member form, in edit mode """
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'name': 'Member',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': self._name,
|
||||
'res_id': self[0].id,
|
||||
'flags': {'initial_mode': 'edit'},
|
||||
'target': 'current'
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
# 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/>.
|
||||
|
||||
""" GOLEM Contact """
|
||||
""" Partner adaptations """
|
||||
|
||||
from odoo import models, api, _
|
||||
|
||||
|
@ -21,16 +21,16 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
<data>
|
||||
|
||||
<!-- Actions -->
|
||||
<act_window id="golem_precreation_member_request_action"
|
||||
<act_window id="golem_member_precreation_search_action"
|
||||
name="Pre-creation contact search"
|
||||
res_model="golem.precreation.member.request.wizard"
|
||||
res_model="golem.member.precreation.search"
|
||||
view_mode="form" target="new" />
|
||||
|
||||
<!-- Menus -->
|
||||
<menuitem id="golem_precreation_member_request_menu"
|
||||
name="Pre-creation contact search"
|
||||
<menuitem id="golem_member_precreation_search_menu"
|
||||
name="Search for contact before create"
|
||||
parent="golem_member.golem_member_tool_menu" sequence="10"
|
||||
action="golem_precreation_member_request_action"
|
||||
action="golem_member_precreation_search_action"
|
||||
groups="golem_base.group_golem_user" />
|
||||
|
||||
</data>
|
||||
|
@ -16,4 +16,4 @@
|
||||
# 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 . import golem_member_precreation_search, golem_precreation_member_result_wizard
|
||||
from . import golem_member_precreation_search
|
||||
|
@ -17,40 +17,50 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
""" GOLEM Precreation Member Request wizard"""
|
||||
|
||||
from odoo import models, fields, api
|
||||
import logging
|
||||
from odoo import models, fields, api, _
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
class GolemPrecreationMemberRequestWizard(models.TransientModel):
|
||||
"""GOLEM Precreation Request Member Wizard """
|
||||
_name = "golem.precreation.member.request.wizard"
|
||||
_name = 'golem.member.precreation.search'
|
||||
|
||||
name = fields.Char()
|
||||
is_member = fields.Boolean()
|
||||
state = fields.Selection([('init', 'Init'), ('final', 'Final')],
|
||||
default='init')
|
||||
keyword = fields.Char(required=True)
|
||||
member_ids = fields.Many2many('golem.member', string='Members')
|
||||
contact_ids = fields.Many2many('res.partner', string='Contacts')
|
||||
|
||||
@api.multi
|
||||
def search_members(self):
|
||||
""" Search members """
|
||||
def action(self):
|
||||
""" Return same wizard window """
|
||||
self.ensure_one()
|
||||
model = self._context.get('model')
|
||||
domain = ['|',
|
||||
('name', 'ilike', self.name),
|
||||
('email', 'ilike', self.name)]
|
||||
members = self.env[model].search(domain)
|
||||
ids = []
|
||||
if members:
|
||||
ids = members.mapped('id')
|
||||
title = ""
|
||||
context = {}
|
||||
if self.is_member:
|
||||
title = 'Member search result "{}"'.format(self.name)
|
||||
context = {'default_member_ids': ids}
|
||||
else:
|
||||
title = 'Contact search result "{}"'.format(self.name)
|
||||
context = {'default_contact_ids': ids}
|
||||
|
||||
return {'name' : (title),
|
||||
_LOGGER.warning(self[0].contact_ids)
|
||||
_LOGGER.warning(self[0].member_ids)
|
||||
return {'name' : _('Search results'),
|
||||
'type' : 'ir.actions.act_window',
|
||||
'res_model' : 'golem.precreation.member.result.wizard',
|
||||
'context': context,
|
||||
'res_model' : self._name,
|
||||
'res_id': self[0].id,
|
||||
'view_mode': 'form',
|
||||
'flags': {'initial_mode': 'view'},
|
||||
'target': 'new'}
|
||||
|
||||
@api.multi
|
||||
def new_search(self):
|
||||
""" New search """
|
||||
self[0].write({'member_ids': [(6, False, [])],
|
||||
'contact_ids': [(6, False, [])],
|
||||
'state': 'init'})
|
||||
return self[0].action()
|
||||
|
||||
@api.multi
|
||||
def search_partners(self):
|
||||
""" Search partners """
|
||||
self.ensure_one()
|
||||
domain = ['|',
|
||||
('name', 'ilike', self[0].keyword),
|
||||
('email', 'ilike', self[0].keyword)]
|
||||
partner_ids = self.env['res.partner'].search(domain)
|
||||
self[0].write({'contact_ids': [(6, False, partner_ids.ids)],
|
||||
'member_ids': [(6, False, partner_ids.mapped('member_id').ids)],
|
||||
'state': 'final'})
|
||||
return self[0].action()
|
||||
|
@ -18,26 +18,57 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<odoo>
|
||||
<data>
|
||||
<record model="ir.ui.view" id="golem_precreation_member_request_wizard">
|
||||
<field name="name">Golem Precreation Member Request Wizard Form</field>
|
||||
<field name="model">golem.precreation.member.request.wizard</field>
|
||||
|
||||
<record model="ir.ui.view" id="golem_member_precreation_search_view_form">
|
||||
<field name="name">GOLEM Member Precreation Search Form</field>
|
||||
<field name="model">golem.member.precreation.search</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Member Searching">
|
||||
<form>
|
||||
<field name="state" invisible="1" />
|
||||
<group>
|
||||
<field name="name" />
|
||||
<field name="is_member" invisible="1"/>
|
||||
<p colspan="2" states="init">
|
||||
Please enter a keyword. It will be searched, as case-insensitive, into firstname, lastname and emails.
|
||||
</p>
|
||||
<field name="keyword" attrs="{'readonly': [('state', '=', 'final')]}" />
|
||||
</group>
|
||||
<group states="final">
|
||||
<p colspan="2" attrs="{'invisible': [('member_ids', '!=', [])]}">
|
||||
No member found for the current search.
|
||||
</p>
|
||||
<field name="member_ids" readonly="1"
|
||||
attrs="{'invisible': [('member_ids', '=', [])]}">
|
||||
<tree>
|
||||
<field name="id" invisible="1"/>
|
||||
<field name="firstname"/>
|
||||
<field name="lastname"/>
|
||||
<field name="email"/>
|
||||
<button name="navigate_to_contact" type="object" icon="fa fa-external-link" />
|
||||
</tree>
|
||||
</field>
|
||||
<p colspan="2" attrs="{'invisible': [('contact_ids', '!=', [])]}">
|
||||
No contact found for the current search.
|
||||
</p>
|
||||
<field name="contact_ids" readonly="1"
|
||||
attrs="{'invisible': [('contact_ids', '=', [])]}">
|
||||
<tree>
|
||||
<field name="id" invisible="1"/>
|
||||
<field name="firstname"/>
|
||||
<field name="lastname"/>
|
||||
<field name="email"/>
|
||||
<button name="navigate_to_contact" type="object" icon="fa fa-external-link" />
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="search_members" string="Search Member" type="object"
|
||||
context="{'model': 'golem.member'}" class="oe_link"
|
||||
attrs="{'invisible': [('is_member', '=', False)]}"/>
|
||||
<button name="search_members" string="Search Contact" type="object"
|
||||
context="{'model': 'res.partner'}" class="oe_link"
|
||||
attrs="{'invisible': [('is_member', '=', True)]}" />
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
<button name="search_partners" string="Search Members and Contacts"
|
||||
type="object" class="oe_highlight" states="init" />
|
||||
<button name="new_search" string="New search"
|
||||
type="object" states="final" />
|
||||
<button string="Close" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
@ -18,6 +18,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<record model="ir.ui.view" id="golem_precreation_member_result_wizard">
|
||||
<field name="name">Golem Precreation Member result Wizard Form</field>
|
||||
<field name="model">golem.precreation.member.result.wizard</field>
|
||||
@ -51,5 +52,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
|
Loading…
Reference in New Issue
Block a user