68 lines
2.1 KiB
Python
68 lines
2.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# This file is part of the cashbook-planner from m-ds for Tryton.
|
|
# The COPYRIGHT file at the top level of this repository contains the
|
|
# full copyright notices and license terms.
|
|
|
|
from trytond.model import ModelSQL, ModelView, fields, Index, DeactivableMixin
|
|
from trytond.transaction import Transaction
|
|
from trytond.pool import Pool
|
|
from trytond.pyson import Eval, Bool
|
|
|
|
DEF_NONE = None
|
|
|
|
|
|
class ScheduledBooking(DeactivableMixin, ModelSQL, ModelView):
|
|
'Scheduled Booking'
|
|
__name__ = 'cashbook.planner'
|
|
|
|
company = fields.Many2One(
|
|
string='Company', model_name='company.company',
|
|
required=True, ondelete="RESTRICT")
|
|
name = fields.Char(string='Name', required=True)
|
|
description = fields.Text(string='Description')
|
|
cashbook = fields.Many2One(
|
|
string='Cashbook', required=True,
|
|
help='Cash book for which the planned posting is to be executed.',
|
|
model_name='cashbook.book', ondelete='CASCADE',
|
|
domain=[('btype', '!=', None)])
|
|
start_date = fields.Date(string='Start Date', required=True)
|
|
end_date = fields.Date(
|
|
string='End Date', depends=['start_date'],
|
|
states={'readonly': ~Bool(Eval('start_date'))},
|
|
domain=[
|
|
'OR',
|
|
('end_date', '>', Eval('start_date')),
|
|
('end_date', '=', DEF_NONE)])
|
|
|
|
@classmethod
|
|
def __setup__(cls):
|
|
super(ScheduledBooking, cls).__setup__()
|
|
t = cls.__table__()
|
|
cls._sql_indexes.update({
|
|
Index(
|
|
t,
|
|
(t.company, Index.Equality())),
|
|
Index(
|
|
t,
|
|
(t.start_date, Index.Range(order='ASC'))),
|
|
Index(
|
|
t,
|
|
(t.end_date, Index.Range(order='ASC')),
|
|
where=t.end_date != DEF_NONE),
|
|
})
|
|
|
|
@staticmethod
|
|
def default_company():
|
|
return Transaction().context.get('company') or None
|
|
|
|
@classmethod
|
|
def default_start_date(cls):
|
|
""" get today as start-date
|
|
|
|
Returns:
|
|
date: date of today
|
|
"""
|
|
IrDate = Pool().get('ir.date')
|
|
return IrDate.today()
|
|
|
|
# ens ScheduledBooking
|