[IMP]GOLEM Season : inverse link with membership products (many products for 1 season)

This commit is contained in:
Fabien BOURGEOIS 2018-02-28 08:40:28 +01:00
parent 209013864e
commit 0e7e33bada
9 changed files with 161 additions and 39 deletions

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2016-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,12 +18,18 @@
{ {
'name': 'GOLEM seasons', 'name': 'GOLEM seasons',
'summary': 'GOLEM non-profit seasons management', 'summary': 'GOLEM non-profit seasons management',
'version': '10.0.1.0.1', 'description': '''GOLEM non-profit seasons management :
- add season with name and period ;
- choose on per default season ;
- link optionnally one or many memberships types''',
'version': '10.0.1.1.0',
'category': 'GOLEM', 'category': 'GOLEM',
'author': 'Fabien Bourgeois', 'author': 'Fabien Bourgeois',
'license': 'AGPL-3', 'license': 'AGPL-3',
'application': False, 'application': False,
'installable': True, 'installable': True,
'depends': ['golem_base'], 'depends': ['golem_base'],
'data': ['security/ir.model.access.csv', 'views/golem_season_views.xml'] 'data': ['security/ir.model.access.csv',
'views/golem_season_views.xml',
'views/membership_views.xml']
} }

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: 2018-01-18 14:18+0000\n" "POT-Creation-Date: 2018-02-28 07:38+0000\n"
"PO-Revision-Date: 2018-01-18 14:18+0000\n" "PO-Revision-Date: 2018-02-28 07:38+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -31,7 +31,7 @@ msgid "Created on"
msgstr "Créé le" msgstr "Créé le"
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:75 #: code:addons/golem_season/models/golem_season.py:73
#, python-format #, python-format
msgid "Current period cannot be included into another existing period." msgid "Current period cannot be included into another existing period."
msgstr "La période actuelle est en conflit avec une période existante." msgstr "La période actuelle est en conflit avec une période existante."
@ -57,7 +57,7 @@ msgid "Display Name"
msgstr "Nom affiché" msgstr "Nom affiché"
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:71 #: code:addons/golem_season/models/golem_season.py:69
#, python-format #, python-format
msgid "End of the period is in range of an existing period." msgid "End of the period is in range of an existing period."
msgstr "La fin de la période est en conflit avec une période existante." msgstr "La fin de la période est en conflit avec une période existante."
@ -93,15 +93,21 @@ msgstr "Dernière mise à jour par"
msgid "Last Updated on" msgid "Last Updated on"
msgstr "Dernière mise à jour le" msgstr "Dernière mise à jour le"
#. module: golem_season
#: model:ir.model.fields,field_description:golem_season.field_product_product_season_id
#: model:ir.model.fields,field_description:golem_season.field_product_template_season_id
msgid "Linked season"
msgstr "Saison liée"
#. module: golem_season #. module: golem_season
#: model:ir.ui.view,arch_db:golem_season.golem_season_view_form #: model:ir.ui.view,arch_db:golem_season.golem_season_view_form
msgid "Make this season as default" msgid "Make this season as default"
msgstr "Activer cette saison par défaut" msgstr "Activer cette saison par défaut"
#. module: golem_season #. module: golem_season
#: model:ir.model.fields,field_description:golem_season.field_golem_season_membership_id #: model:ir.model.fields,field_description:golem_season.field_golem_season_membership_ids
msgid "Membership type" msgid "Membership types"
msgstr "Type d'adhésion" msgstr "Types d'adhésion"
#. module: golem_season #. module: golem_season
#: model:ir.model.fields,field_description:golem_season.field_golem_season_date_end #: model:ir.model.fields,field_description:golem_season.field_golem_season_date_end
@ -113,8 +119,14 @@ msgstr "Fin de la période"
msgid "Period start" msgid "Period start"
msgstr "Début de la période" msgstr "Début de la période"
#. module: golem_season
#: model:ir.model,name:golem_season.model_product_template
msgid "Product Template"
msgstr "Modèle d'article"
#. module: golem_season #. module: golem_season
#: model:ir.ui.view,arch_db:golem_season.golem_season_view_form #: model:ir.ui.view,arch_db:golem_season.golem_season_view_form
#: model:ir.ui.view,arch_db:golem_season.membership_product_search_form_view_inherit_golem_season
msgid "Season" msgid "Season"
msgstr "Saison" msgstr "Saison"
@ -129,25 +141,25 @@ msgid "Seasons"
msgstr "Saisons" msgstr "Saisons"
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:62 #: code:addons/golem_season/models/golem_season.py:60
#, python-format #, python-format
msgid "Start of the period cannot be after end of the period." msgid "Start of the period cannot be after end of the period."
msgstr "Le début de la période ne peut être postérieur à sa fin." msgstr "Le début de la période ne peut être postérieur à sa fin."
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:67 #: code:addons/golem_season/models/golem_season.py:65
#, python-format #, python-format
msgid "Start of the period is in range of an existing period." msgid "Start of the period is in range of an existing period."
msgstr "Le début de la période est en conflit avec une période existante." msgstr "Le début de la période est en conflit avec une période existante."
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:58 #: code:addons/golem_season/models/golem_season.py:56
#, python-format #, python-format
msgid "The date end is required" msgid "The date end is required"
msgstr "The date end is required" msgstr "The date end is required"
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:60 #: code:addons/golem_season/models/golem_season.py:58
#, python-format #, python-format
msgid "The date start is required" msgid "The date start is required"
msgstr "The date start is required" msgstr "The date start is required"
@ -160,8 +172,7 @@ msgid "This season name has already been used."
msgstr "Ce nom pour la saison a déjà été utilisé. Merci d'en choisir un autre." msgstr "Ce nom pour la saison a déjà été utilisé. Merci d'en choisir un autre."
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:114 #: code:addons/golem_season/models/golem_season.py:112
#, python-format #, python-format
msgid "You can't delete the default season" msgid "You can't delete the default season"
msgstr "Vous ne pouvez pas supprimer la saison par défaut" msgstr "Vous ne pouvez pas supprimer la saison par défaut"

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: 2018-01-18 14:18+0000\n" "POT-Creation-Date: 2018-02-28 07:38+0000\n"
"PO-Revision-Date: 2018-01-18 14:18+0000\n" "PO-Revision-Date: 2018-02-28 07:38+0000\n"
"Last-Translator: <>\n" "Last-Translator: <>\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -31,7 +31,7 @@ msgid "Created on"
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:75 #: code:addons/golem_season/models/golem_season.py:73
#, python-format #, python-format
msgid "Current period cannot be included into another existing period." msgid "Current period cannot be included into another existing period."
msgstr "" msgstr ""
@ -57,7 +57,7 @@ msgid "Display Name"
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:71 #: code:addons/golem_season/models/golem_season.py:69
#, python-format #, python-format
msgid "End of the period is in range of an existing period." msgid "End of the period is in range of an existing period."
msgstr "" msgstr ""
@ -93,14 +93,20 @@ msgstr ""
msgid "Last Updated on" msgid "Last Updated on"
msgstr "" msgstr ""
#. module: golem_season
#: model:ir.model.fields,field_description:golem_season.field_product_product_season_id
#: model:ir.model.fields,field_description:golem_season.field_product_template_season_id
msgid "Linked season"
msgstr ""
#. module: golem_season #. module: golem_season
#: model:ir.ui.view,arch_db:golem_season.golem_season_view_form #: model:ir.ui.view,arch_db:golem_season.golem_season_view_form
msgid "Make this season as default" msgid "Make this season as default"
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: model:ir.model.fields,field_description:golem_season.field_golem_season_membership_id #: model:ir.model.fields,field_description:golem_season.field_golem_season_membership_ids
msgid "Membership type" msgid "Membership types"
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
@ -113,8 +119,14 @@ msgstr ""
msgid "Period start" msgid "Period start"
msgstr "" msgstr ""
#. module: golem_season
#: model:ir.model,name:golem_season.model_product_template
msgid "Product Template"
msgstr ""
#. module: golem_season #. module: golem_season
#: model:ir.ui.view,arch_db:golem_season.golem_season_view_form #: model:ir.ui.view,arch_db:golem_season.golem_season_view_form
#: model:ir.ui.view,arch_db:golem_season.membership_product_search_form_view_inherit_golem_season
msgid "Season" msgid "Season"
msgstr "" msgstr ""
@ -129,25 +141,25 @@ msgid "Seasons"
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:62 #: code:addons/golem_season/models/golem_season.py:60
#, python-format #, python-format
msgid "Start of the period cannot be after end of the period." msgid "Start of the period cannot be after end of the period."
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:67 #: code:addons/golem_season/models/golem_season.py:65
#, python-format #, python-format
msgid "Start of the period is in range of an existing period." msgid "Start of the period is in range of an existing period."
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:58 #: code:addons/golem_season/models/golem_season.py:56
#, python-format #, python-format
msgid "The date end is required" msgid "The date end is required"
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:60 #: code:addons/golem_season/models/golem_season.py:58
#, python-format #, python-format
msgid "The date start is required" msgid "The date start is required"
msgstr "" msgstr ""
@ -160,7 +172,7 @@ msgid "This season name has already been used."
msgstr "" msgstr ""
#. module: golem_season #. module: golem_season
#: code:addons/golem_season/models/golem_season.py:114 #: code:addons/golem_season/models/golem_season.py:112
#, python-format #, python-format
msgid "You can't delete the default season" msgid "You can't delete the default season"
msgstr "" msgstr ""

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2016-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
@ -15,4 +15,4 @@
# You should have received a copy of the GNU Affero General Public License # 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/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from . import golem_season from . import product_template, golem_season

View File

@ -1,6 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright 2016 Fabien Bourgeois <fabien@yaltik.com> # Copyright 2016-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
@ -28,21 +28,22 @@ class GolemSeason(models.Model):
_('This season name has already been used.'))] _('This season name has already been used.'))]
name = fields.Char('Season name', copy=False, required=True) name = fields.Char('Season name', copy=False, required=True)
membership_id = fields.Many2one('product.template', 'Membership type', membership_ids = fields.One2many('product.template', 'season_id',
domain=[('membership', '=', True)]) string='Membership types',
domain=[('membership', '=', True)])
member_counter = fields.Integer('Counter for member number generation', member_counter = fields.Integer('Counter for member number generation',
readonly=True, default=1) readonly=True, default=1)
date_start = fields.Date('Period start') date_start = fields.Date('Period start')
date_end = fields.Date('Period end') date_end = fields.Date('Period end')
@api.onchange('membership_id') @api.onchange('membership_ids')
def _onchange_season_dates(self): def _onchange_season_dates(self):
""" Sets defaults dates according to membership type """ """ Sets defaults dates according to membership type """
for season in self: for season in self:
if season.membership_id and not season.date_start: if season.membership_ids and not season.date_start:
season.update({ season.update({
'date_start': season.membership_id.membership_date_from, 'date_start': season.membership_ids[0].membership_date_from,
'date_end': season.membership_id.membership_date_to 'date_end': season.membership_ids[0].membership_date_to
}) })
@api.constrains('date_start', 'date_end') @api.constrains('date_start', 'date_end')

View File

@ -0,0 +1,37 @@
# -*- 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/>.
""" Product adaptations """
from odoo import models, fields, api
class ProductTemplate(models.Model):
""" Product Template adaptations """
_inherit = 'product.template'
season_id = fields.Many2one('golem.season', 'Linked season', index=True)
@api.onchange('season_id')
def onchange_season(self):
""" Adapts period to selected season if needed """
for product in self:
if product.membership and product.season_id \
and not product.membership_date_from:
product.update({
'membership_date_from': product.season_id.date_start,
'membership_date_to': product.season_id.date_end
})

View File

@ -74,5 +74,5 @@ class TestGolemSeason(TransactionCase):
'membership_date_to': '2018-11-01'}) 'membership_date_to': '2018-11-01'})
new_season = self.env['golem.season'].create({'name': 'Name', new_season = self.env['golem.season'].create({'name': 'Name',
'membership_id': membership.id}) 'membership_ids': [(4, membership.id, 0)]})
self.assertEqual(new_season.membership_id, membership) self.assertEqual(new_season.membership_ids[0], membership)

View File

@ -36,7 +36,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<group string="Season"> <group string="Season">
<field name="is_default" invisible="True" /> <field name="is_default" invisible="True" />
<field name="name" attrs="{'required': True}" /> <field name="name" attrs="{'required': True}" />
<field name="membership_id" options="{'no_create': true}"/> <field name="membership_ids" widget="many2many_tags"
options="{'no_create': True}" />
<field name="date_start" <field name="date_start"
attrs="{'required': [('date_end', '!=', False)]}" /> attrs="{'required': [('date_end', '!=', False)]}" />
<field name="date_end" <field name="date_end"

View File

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="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/>.
-->
<odoo>
<data>
<!-- Forms -->
<record id="membership_products_view_form_inherit_golem_season"
model="ir.ui.view">
<field name="name">Membership Product Form adaptations</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="membership.membership_products_form" />
<field name="arch" type="xml">
<field name="default_code" position="before">
<field name="season_id" options="{'no_create': True}" />
</field>
</field>
</record>
<!-- Searches -->
<record id="membership_product_search_form_view_inherit_golem_season"
model="ir.ui.view">
<field name="name">Membership Product Search adaptations</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="membership.membership_product_search_form_view" />
<field name="arch" type="xml">
<field name="name" position="after">
<field name="season_id" />
</field>
<xpath expr="//group/filter[1]" position="after">
<filter name="group_season" string="Season"
context="{'group_by': 'season_id'}" />
</xpath>
</field>
</record>
</data>
</odoo>