Ajout du fonctionnement pour contact

This commit is contained in:
eloyoussef 2018-03-23 17:31:04 +01:00
parent 79c8d501a0
commit 991e5bc39a
12 changed files with 138 additions and 234 deletions

View File

@ -27,6 +27,7 @@
'installable': True,
'depends': ['golem_member', 'golem_family'],
'data': ['views/golem_member_views.xml',
'views/partner_views.xml',
'wizard/golem_precreation_member_request_wizard_views.xml',
'wizard/golem_precreation_member_result_wizard_views.xml']
}

View File

@ -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
from . import golem_member, res_partner

View File

@ -31,11 +31,14 @@ class GolemMember(models.Model):
def precreation_search(self):
""" Precreation member search """
self.ensure_one()
return {'name' : _('Please enter member searched'),
'type' : 'ir.actions.act_window',
'res_model' : 'golem.precreation.member.request.wizard',
'view_mode': 'form',
'target': 'new'}
return {
'name' : _('Please enter member searched'),
'type' : 'ir.actions.act_window',
'res_model' : 'golem.precreation.member.request.wizard',
'context' : {'default_is_member' : True},
'view_mode': 'form',
'target': 'new'
}
@api.multi
def open_line(self):
""" open member form """

View File

@ -0,0 +1,53 @@
# -*- 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 Contact """
from odoo import models, api, _
class GolemMember(models.Model):
""" Res Partner extention """
_inherit = 'res.partner'
@api.multi
def precreation_search(self):
""" Precreation contact search """
self.ensure_one()
return {
'name' : _('Please enter contact searched'),
'type' : 'ir.actions.act_window',
'res_model' : 'golem.precreation.member.request.wizard',
'view_mode': 'form',
'target': 'new'
}
@api.multi
def open_line(self):
""" open contact form """
self.ensure_one()
return {
'type': 'ir.actions.act_window',
'name': 'Member',
'view_type': 'form',
'view_mode': 'form',
'res_model': self._name,
'res_id': self.id,
'flags': {'initial_mode': 'edit'},
'target': 'current',
}

View File

@ -1,18 +0,0 @@
# -*- 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/>.
from . import test_golem_member

View File

@ -1,180 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2017 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 testing """
from odoo import exceptions
from odoo.tests.common import TransactionCase
# from psycopg2 import IntegrityError
class GolemMemberTestCase(TransactionCase):
""" GOLEM member testing """
def setUp(self, *args, **kwargs):
""" Bootstrap season and members """
super(GolemMemberTestCase, self).setUp(*args, **kwargs)
self.member_numberconfig_model = self.env['golem.member.numberconfig']
season_mdl = self.env['golem.season'].sudo()
self.season_current = season_mdl.create({'name': u'Current'})
self.season_current.do_default_season()
self.season_next = season_mdl.create({'name': u'Next'})
self.member_model = self.env['golem.member'].sudo()
mcrt = self.member_model.create
self.member1 = mcrt({'lastname': u'LAST', 'firstname': u'First'})
self.member2 = mcrt({'lastname': u'LAST', 'firstname': u'Young',
'birthdate_date': '2016-01-01'})
def test_member_creation_noname(self):
""" Test creation of member without needed parameters """
with self.assertRaises(exceptions.ValidationError) as exc_cm:
self.member_model.create({})
self.assertIn('Error(s) with partner', exc_cm.exception.args[0])
self.assertEqual('No name is set.', exc_cm.exception.args[1])
def test_current_season(self):
""" Test if default season if fixed according to setUp and if users
are correctly seen """
self.assertEqual(self.member_model._default_season(),
self.season_current)
self.assertTrue(self.member1.is_current)
self.assertTrue(self.member2.is_current)
self.season_next.do_default_season()
self.assertFalse(self.member1.is_current)
self.assertFalse(self.member2.is_current)
def test_member_numbers_manual(self):
""" Tests manual member number generation """
conf = self.member_numberconfig_model.create({'is_automatic': '0'})
conf.apply_recompute()
self.assertFalse(self.member1.number)
self.member1.number_manual = u'M01'
self.assertEqual(self.member1.number_manual, self.member1.number)
# **Can not test IntegrityError without Odoo ERROR...**
# with self.assertRaises(IntegrityError) as cm:
# self.member2.number_manual = u'M01'
# self.assertIn('duplicate key value violates unique constraint',
# cm.exception.args[0])
def test_member_numbers_auto_season(self):
""" Tests per season automatic member number generation + prefix """
conf = self.member_numberconfig_model.create({'is_automatic': '1',
'is_per_season': '1',
'prefix': u'M'})
conf.apply_recompute()
self.assertEqual(self.member1.number, u'M1')
self.assertEqual(self.member2.number, u'M2')
self.member2.season_ids += self.season_next
self.assertEqual(self.member2.number, u'M2')
self.season_next.do_default_season()
self.assertTrue(self.member2.is_current)
self.assertEqual(self.member2.number, u'M1')
self.assertFalse(self.member1.is_current)
self.assertFalse(self.member1.number)
def test_mnumbers_auto_season_from(self):
""" Tests per season automatic member number + number_from """
conf = self.member_numberconfig_model.create({'is_automatic': '1',
'is_per_season': '1',
'prefix': False,
'number_from': 100})
conf.apply_recompute()
self.assertEqual(self.member1.number, u'100')
self.assertEqual(self.member2.number, u'101')
self.member2.season_ids += self.season_next
self.assertEqual(self.member2.number, u'101')
self.season_next.do_default_season()
self.assertTrue(self.member2.is_current)
self.assertEqual(self.member2.number, u'100')
self.assertFalse(self.member1.is_current)
self.assertFalse(self.member1.number)
def test_member_numbers_auto_global(self):
""" Tests global automatic member number generation """
conf = self.member_numberconfig_model.create({'is_automatic': '1',
'is_per_season': '0'})
conf.apply_recompute()
self.assertEqual(self.member1.number, u'1')
self.assertEqual(self.member2.number, u'2')
new_m = self.member_model.create({'lastname': 'NEW',
'firstname': 'Buddy',
'season_ids': [self.season_next]})
self.assertEqual(new_m.number, u'3')
def test_mnumbers_auto_global_from(self):
""" Tests global automatic member number generation + number_from """
conf = self.member_numberconfig_model.create({'is_automatic': '1',
'is_per_season': '0',
'number_from': 50})
conf.apply_recompute()
self.assertEqual(self.member1.number, u'50')
self.assertEqual(self.member2.number, u'51')
new_m = self.member_model.create({'lastname': 'NEW',
'firstname': 'Buddy',
'season_ids': [self.season_next]})
self.assertEqual(new_m.number, u'52')
def test_mnumbers_manual_to_auto(self):
""" Tests generation change withtout whole recompute """
conf = self.member_numberconfig_model.create({'is_automatic': '0'})
conf.apply_recompute()
self.assertFalse(self.member1.number)
self.member1.number_manual = u'M01'
self.assertEqual(self.member1.number_manual, self.member1.number)
# Without number_from
conf = self.member_numberconfig_model.create({'is_automatic': '1',
'is_per_season': '0',
'prefix': False})
conf.apply_nocompute()
self.assertEqual(self.member1.number, u'M01')
new_m = self.member_model.create({'lastname': 'NEW',
'firstname': 'Dewie',
'season_ids': [self.season_current]})
new_m2 = self.member_model.create({'lastname': 'NEW',
'firstname': 'Dowa',
'season_ids': [self.season_current]})
self.assertEqual(new_m.number, u'1')
self.assertEqual(new_m2.number, u'2')
# With number_from
conf = self.member_numberconfig_model.create({'is_automatic': '1',
'is_per_season': '0',
'prefix': False,
'number_from': 50})
conf.apply_nocompute()
self.assertEqual(self.member1.number, u'M01')
new_m = self.member_model.create({'lastname': 'NEW',
'firstname': 'Buddy',
'season_ids': [self.season_current]})
new_m2 = self.member_model.create({'lastname': 'NEW',
'firstname': 'Bobby',
'season_ids': [self.season_current]})
self.assertEqual(new_m.number, u'50')
self.assertEqual(new_m2.number, u'51')
# After season changing
self.season_next.do_default_season()
self.assertEqual(self.member1.number, u'M01')
self.assertEqual(new_m.number, u'50')
self.member1.season_ids += self.season_next
self.assertEqual(self.member1.number, u'M01')
new_m3 = self.member_model.create({'lastname': 'NEW',
'firstname': 'Barny',
'season_ids': [self.season_current]})
self.assertEqual(new_m3.number, u'52')

View File

@ -32,6 +32,5 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</xpath>
</field>
</record>
</data>
</odoo>

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="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/>.
-->
<odoo>
<data>
<!-- Forms -->
<record id="res_partner_precreation_extention_form" model="ir.ui.view">
<field name="name">Res Partner Precreation extention Form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//sheet" position="before">
<header>
<button name="precreation_search" type="object" string="Pre-creation search" class="oe_highlight"/>
</header>
</xpath>
</field>
</record>
</data>
</odoo>

View File

@ -24,23 +24,33 @@ class GolemPrecreationMemberRequestWizard(models.TransientModel):
_name = "golem.precreation.member.request.wizard"
name = fields.Char()
is_member = fields.Boolean()
@api.multi
def search_members(self):
""" Search members """
self.ensure_one()
model = self._context.get('model')
domain = ['|',
('name', 'ilike', self.name),
('email', 'ilike', self.name)]
members = self.env['golem.member'].search(domain)
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' : ('Member search result "{}"'.format(self.name)),
return {'name' : (title),
'type' : 'ir.actions.act_window',
'res_model' : 'golem.precreation.member.result.wizard',
'context': {'default_member_ids': ids},
'context': context,
'view_mode': 'form',
'flags': {'initial_mode': 'view'},
'target': 'new'}

View File

@ -25,9 +25,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<form string="Member Searching">
<group>
<field name="name" />
<field name="is_member" invisible="1"/>
</group>
<footer>
<button name="search_members" string="Search" type="object" class="oe_link" />
<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" />
</footer>
</form>

View File

@ -24,4 +24,4 @@ class GolemPrecreationMemberResultWizard(models.TransientModel):
_name = "golem.precreation.member.result.wizard"
member_ids = fields.Many2many('golem.member')
name_searched = fields.Char(default="test")
contact_ids = fields.Many2many('res.partner')

View File

@ -18,44 +18,38 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<odoo>
<data>
<!--<record id="golem_precreation_member_wizard" type="ir.ui.view" >
<field name="name">Golem Precreation Member Wizard</field>
<field name="model">golem.precreation.member.wizard</field>
<field name="arch" type="xml">
<form>
<group>
<field name="name"/>
</group>
</form>
</field>
</record>-->
<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>
<field name="arch" type="xml">
<form string="list">
<label string="No member found for the current search"
attrs="{'invisible': [('member_ids', '!=', [])]}"/>
<field name="member_ids" readonly="1"
<label string="No member found for the current search"
attrs="{'invisible': ['|',('member_ids', '!=', []),('contact_ids', '!=', [])]}"/>
<field name="member_ids" readonly="1"
attrs="{'invisible': [('member_ids', '=', [])]}">
<tree readonly="1">
<tree readonly="1">
<field name="id" invisible="1"/>
<field name="firstname"/>
<field name="lastname"/>
<field name="email"/>
<button name="open_line" type="object"
string="details" />
</tree>
</field>
<button name="open_line" type="object" icon="fa fa-external-link" />
</tree>
</field>
<field name="contact_ids" readonly="1"
attrs="{'invisible': [('contact_ids', '=', [])]}">
<tree readonly="1">
<field name="id" invisible="1"/>
<field name="firstname"/>
<field name="lastname"/>
<field name="email"/>
<button name="open_line" type="object" icon="fa fa-external-link" />
</tree>
</field>
<footer>
<button string="Close" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
</data>
</odoo>