[ADD][FIX]GOLEM Member Minor enhancements

* add can leave boolean ;
* do not store is minor / adult and create efficient search function.
This commit is contained in:
Fabien BOURGEOIS 2018-08-26 18:16:50 +02:00
parent 063da04cf0
commit 150cb1ac39
6 changed files with 77 additions and 31 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2017 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2017-2018 Fabien Bourgeois <fabien@yaltik.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -18,7 +18,7 @@
{ {
'name': 'GOLEM members minor', 'name': 'GOLEM members minor',
'summary': 'GOLEM non-profit members minor management', 'summary': 'GOLEM non-profit members minor management',
'version': '10.0.1.0.0', 'version': '10.0.1.1.0',
'category': 'GOLEM', 'category': 'GOLEM',
'author': 'Fabien Bourgeois', 'author': 'Fabien Bourgeois',
'license': 'AGPL-3', 'license': 'AGPL-3',

View File

@ -6,25 +6,29 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 10.0\n" "Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-01 20:16+0000\n" "POT-Creation-Date: 2018-08-26 16:15+0000\n"
"PO-Revision-Date: 2017-05-01 20:16+0000\n" "PO-Revision-Date: 2018-08-26 18:15+0200\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n" "Content-Transfer-Encoding: \n"
"Language: fr\n" "Plural-Forms: \n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#. module: golem_member_minor #. module: golem_member_minor
#: model:ir.model.fields,field_description:golem_member_minor.field_golem_member_activities_participation #: model:ir.model.fields,field_description:golem_member_minor.field_golem_member_activities_participation
msgid "Activities participation?" msgid "Activities participation?"
msgstr "Participation aux activités?" msgstr "Participation aux activités?"
#. module: golem_member_minor
#: model:ir.model.fields,field_description:golem_member_minor.field_golem_member_leave_alone
msgid "Can leave alone?"
msgstr "Peut quitter la structure seul?"
#. module: golem_member_minor #. module: golem_member_minor
#: model:ir.model,name:golem_member_minor.model_golem_member #: model:ir.model,name:golem_member_minor.model_golem_member
msgid "GOLEM Member" msgid "GOLEM Member"
msgstr "GOLEM : Adhérent" msgstr "Usager"
#. module: golem_member_minor #. module: golem_member_minor
#: model:ir.ui.view,arch_db:golem_member_minor.golem_member_search_inherit_minor #: model:ir.ui.view,arch_db:golem_member_minor.golem_member_search_inherit_minor

View File

@ -6,8 +6,8 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: Odoo Server 10.0\n" "Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-01 20:16+0000\n" "POT-Creation-Date: 2018-08-26 16:15+0000\n"
"PO-Revision-Date: 2017-05-01 20:16+0000\n" "PO-Revision-Date: 2018-08-26 16:15+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -20,6 +20,11 @@ msgstr ""
msgid "Activities participation?" msgid "Activities participation?"
msgstr "" msgstr ""
#. module: golem_member_minor
#: model:ir.model.fields,field_description:golem_member_minor.field_golem_member_leave_alone
msgid "Can leave alone?"
msgstr ""
#. module: golem_member_minor #. module: golem_member_minor
#: model:ir.model,name:golem_member_minor.model_golem_member #: model:ir.model,name:golem_member_minor.model_golem_member
msgid "GOLEM Member" msgid "GOLEM Member"

View File

@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# 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/>.
""" Post-migration script """
from openupgradelib import openupgrade
@openupgrade.migrate(use_env=False)
def migrate(cursor, version):
""" Remove is_minor obsolete column """
cursor.execute('ALTER TABLE golem_member DROP COLUMN IF EXISTS is_minor')

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2017 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2017-2018 Fabien Bourgeois <fabien@yaltik.com>
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as # it under the terms of the GNU Affero General Public License as
@ -17,27 +17,38 @@
""" GOLEM Member Minor management """ """ GOLEM Member Minor management """
from datetime import datetime, timedelta from datetime import date, timedelta
from odoo import models, fields, api from odoo import models, fields, api
ADULT_DURATION = timedelta(days=365.25*18)
class GolemMember(models.Model): class GolemMember(models.Model):
""" GOLEM Member adaptations """ """ GOLEM Member adaptations """
_inherit = 'golem.member' _inherit = 'golem.member'
ADULT_DURATION = timedelta(days=365*18)
legal_guardian_ids = fields.Many2many( legal_guardian_ids = fields.Many2many(
'res.partner', string='Legal guardians', index=True, 'res.partner', string='Legal guardians', index=True, auto_join=True,
domain="['&', ('is_company', '=', False), ('id', '!=', partner_id)]") domain="['&', ('is_company', '=', False), ('id', '!=', partner_id)]")
activities_participation = fields.Boolean('Activities participation?') activities_participation = fields.Boolean('Activities participation?')
leave_alone = fields.Boolean('Can leave alone?')
is_minor = fields.Boolean('Is minor?', compute='_compute_is_minor', is_minor = fields.Boolean('Is minor?', compute='_compute_is_minor',
store=True, default=False) search='_search_is_minor', default=False)
@api.multi
@api.depends('birthdate_date') @api.depends('birthdate_date')
def _compute_is_minor(self): def _compute_is_minor(self):
for member in self: for member in self:
if member.birthdate_date: if member.birthdate_date:
member.is_minor = ((datetime.now() - self.ADULT_DURATION) < member.is_minor = ((date.today() - ADULT_DURATION) <
fields.Datetime.from_string(member.birthdate_date)) fields.Date.from_string(member.birthdate_date))
else: else:
member.is_minor = False member.is_minor = False
def _search_is_minor(self, operator, value):
""" Search function for is minor """
today = date.today()
adult_date = today - ADULT_DURATION
if operator == '=':
operator = '>' if value else '<='
else:
operator = '<=' if value else '>'
return [('birthdate_date', operator, adult_date)]

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<!-- <!--
Copyright 2017 Fabien Bourgeois <fabien@yaltik.com> Copyright 2017-2018 Fabien Bourgeois <fabien@yaltik.com>
This program is free software: you can redistribute it and/or modify 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 it under the terms of the GNU Affero General Public License as published by
@ -26,23 +26,24 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<field name="model">golem.member</field> <field name="model">golem.member</field>
<field name="inherit_id" ref="golem_member.golem_member_form" /> <field name="inherit_id" ref="golem_member.golem_member_form" />
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="pictures_agreement" position="replace" />
<page name="contact_details" position="after"> <page name="contact_details" position="after">
<page name="minor_page" string="Minor" <page name="minor_page" string="Minor"
attrs="{'invisible': [('is_minor', '=', False)]}"> attrs="{'invisible': [('is_minor', '=', False)]}">
<group name="minor_group"> <group name="minor_group">
<field name="activities_participation"/> <field name="activities_participation"/>
<field name="partner_id" invisible="True" required="False" /> <field name="leave_alone"/>
<field name="is_minor" invisible="True" /> <field name="partner_id" invisible="True" required="False" />
<field name="legal_guardian_ids"> <field name="is_minor" invisible="True" />
<tree name="legal_guardian_ids_tree"> <field name="legal_guardian_ids"
<field name="name" /> context="{'search_default_type_person': 1}">
<field name="contact_address" /> <tree>
<field name="phone" /> <field name="name" />
<field name="mobile" /> <field name="contact_address" />
<field name="email" widget="email" /> <field name="phone" />
</tree> <field name="mobile" />
</field> <field name="email" widget="email" />
</tree>
</field>
</group> </group>
</page> </page>
</page> </page>