2017-06-14 23:48:18 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2018-08-01 18:10:20 +02:00
|
|
|
# Copyright 2017-2018 Fabien Bourgeois <fabien@yaltik.com>
|
2017-06-14 23:48:18 +02:00
|
|
|
#
|
|
|
|
# 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 Payment models """
|
|
|
|
|
|
|
|
from odoo import models, fields, api, _
|
2018-08-01 18:10:20 +02:00
|
|
|
from odoo.exceptions import ValidationError
|
|
|
|
from odoo.tools import formatLang
|
2017-06-14 23:48:18 +02:00
|
|
|
|
2018-02-02 13:58:36 +01:00
|
|
|
class AccountPayment(models.Model):
|
|
|
|
""" Add number bank check"""
|
|
|
|
_inherit = 'account.payment'
|
2018-02-02 18:29:10 +01:00
|
|
|
reference = fields.Char(string='Payment reference')
|
2018-02-02 13:58:36 +01:00
|
|
|
|
2017-06-14 23:48:18 +02:00
|
|
|
class GolemPaymentScheduleDay(models.Model):
|
|
|
|
""" Schedule day simple model """
|
|
|
|
_name = 'golem.payment.schedule.day'
|
|
|
|
_rec_name = 'day'
|
2018-08-01 18:10:20 +02:00
|
|
|
_order = 'schedule_id asc,day asc'
|
|
|
|
_sql_constraints = [('golem_payment_schedule_day_uniq',
|
|
|
|
'UNIQUE (day, schedule_id)',
|
2017-06-14 23:48:18 +02:00
|
|
|
_('Day must be unique.'))]
|
|
|
|
|
2018-08-01 18:10:20 +02:00
|
|
|
day = fields.Date(required=True)
|
|
|
|
schedule_id = fields.Many2one('golem.payment.schedule', required=True,
|
|
|
|
auto_join=True)
|
2017-06-14 23:48:18 +02:00
|
|
|
|
|
|
|
|
|
|
|
class GolemPaymentSchedule(models.Model):
|
|
|
|
""" GOLEM Payment Schedule """
|
|
|
|
_name = 'golem.payment.schedule'
|
|
|
|
_description = 'GOLEM Payment Schedule'
|
|
|
|
_order = 'season_id desc'
|
|
|
|
|
|
|
|
name = fields.Char(required=True)
|
2018-08-01 18:10:20 +02:00
|
|
|
day_ids = fields.One2many('golem.payment.schedule.day', 'schedule_id',
|
|
|
|
string='Days')
|
|
|
|
day_display = fields.Char(compute='_compute_day_display', string='Days')
|
2017-06-14 23:48:18 +02:00
|
|
|
occurences = fields.Integer(compute='_compute_occurences')
|
2018-02-15 10:15:54 +01:00
|
|
|
season_id = fields.Many2one('golem.season', 'Season', required=True)
|
2018-02-13 16:30:15 +01:00
|
|
|
|
2018-08-01 18:10:20 +02:00
|
|
|
@api.depends('day_ids')
|
|
|
|
def _compute_day_display(self):
|
|
|
|
""" Computes day display """
|
|
|
|
for schedule in self:
|
|
|
|
days = [fields.Date.from_string(d.day).strftime('%d/%m/%Y')
|
|
|
|
for d in schedule.day_ids]
|
|
|
|
schedule.day_display = u', '.join(days)
|
|
|
|
|
2017-06-14 23:48:18 +02:00
|
|
|
@api.depends('day_ids')
|
|
|
|
def _compute_occurences(self):
|
|
|
|
""" Computes number of occurences """
|
|
|
|
for schedule in self:
|
2017-06-19 18:14:00 +02:00
|
|
|
schedule.occurences = len(schedule.day_ids)
|
2018-08-01 18:10:20 +02:00
|
|
|
|
|
|
|
@api.constrains('day_ids', 'season_id')
|
|
|
|
def check_dates(self):
|
|
|
|
""" Check date coherence """
|
|
|
|
for schedule in self:
|
|
|
|
if schedule.season_id.date_start:
|
|
|
|
days = schedule.day_ids.mapped('day')
|
|
|
|
for day in days:
|
|
|
|
season = schedule.season_id
|
|
|
|
if (day < season.date_start or day > season.date_end):
|
|
|
|
verr = _('Day %s is out of season period (%s-%s)'% \
|
|
|
|
(day, season.date_start, season.date_end))
|
|
|
|
raise ValidationError(verr)
|