2018-10-22 21:57:17 +02:00
|
|
|
# -*- 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 Families Adaptations"""
|
|
|
|
|
2018-10-26 08:48:53 +02:00
|
|
|
from odoo import models, fields, api
|
2018-10-22 21:57:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GolemFamily(models.Model):
|
|
|
|
""" GOLEM Family Adaptations """
|
|
|
|
_inherit = 'golem.family'
|
|
|
|
|
2018-10-26 08:48:53 +02:00
|
|
|
family_history_ids = fields.One2many('golem.family.history', 'family_id',
|
|
|
|
readonly=True, string='History details')
|
2018-10-22 21:57:17 +02:00
|
|
|
|
2018-10-26 17:47:22 +02:00
|
|
|
@api.constrains('area_id', 'zip', 'city', 'country_id', 'member_ids')
|
2018-10-22 21:57:17 +02:00
|
|
|
def save_family_history(self):
|
2018-10-26 08:48:53 +02:00
|
|
|
""" Saves family history """
|
2018-10-22 22:24:57 +02:00
|
|
|
default_season = self.env['golem.season'].search([('is_default', '=', True)], limit=1)
|
2018-10-22 21:57:17 +02:00
|
|
|
for family in self:
|
2018-10-26 08:48:53 +02:00
|
|
|
history_id = self.env['golem.family.history'].search([
|
2018-10-22 21:57:17 +02:00
|
|
|
('family_id', '=', family.id),
|
2018-10-22 22:24:57 +02:00
|
|
|
('season_id', '=', default_season.id)], limit=1)
|
2018-10-26 08:48:53 +02:00
|
|
|
history_data = {
|
|
|
|
'zip_code': family.zip,
|
2018-10-26 14:19:49 +02:00
|
|
|
'area_id': family.area_id.id,
|
2018-10-26 08:48:53 +02:00
|
|
|
'city': family.city,
|
|
|
|
'country_id': family.country_id.id,
|
|
|
|
'member_ids':[(6, False, family.member_ids.ids)]
|
|
|
|
}
|
|
|
|
if history_id:
|
|
|
|
history_id.write(history_data)
|
2018-10-22 21:57:17 +02:00
|
|
|
else:
|
2018-10-26 08:48:53 +02:00
|
|
|
history_data.update({'family_id': family.id,
|
|
|
|
'season_id': default_season.id})
|
|
|
|
self.env['golem.family.history'].create(history_data)
|