# -*- coding: utf-8 -*- # This file is part of the cashbook-module 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 Workflow, ModelView, ModelSQL, fields, Unique from trytond.transaction import Transaction from trytond.pyson import Eval, If, Or from trytond.pool import Pool from trytond.report import Report from decimal import Decimal from .book import sel_state_book sel_reconstate = [ ('edit', 'Edit'), ('check', 'Check'), ('done', 'Done'), ] STATES = { 'readonly': Or( Eval('state', '') != 'edit', Eval('state_cashbook', '') != 'open', ), } DEPENDS=['state', 'state_cashbook'] class Reconciliation(Workflow, ModelSQL, ModelView): 'Cashbook Reconciliation' __name__ = 'cashbook.recon' cashbook = fields.Many2One(string='Cashbook', required=True, select=True, model_name='cashbook.book', ondelete='CASCADE', readonly=True) date = fields.Date(string='Date', required=True, select=True, states=STATES, depends=DEPENDS) date_from = fields.Date(string='Start Date', required=True, domain=[ If(Eval('date_to') & Eval('date_from'), ('date_from', '<=', Eval('date_to')), ()), ], states=STATES, depends=DEPENDS+['date_to']) date_to = fields.Date(string='End Date', required=True, domain=[ If(Eval('date_to') & Eval('date_from'), ('date_from', '<=', Eval('date_to')), ()), ], states=STATES, depends=DEPENDS+['date_from']) lines = fields.One2Many(string='Lines', field='reconciliation', model_name='cashbook.line', states=STATES, depends=DEPENDS+['date_from', 'date_to', 'cashbook'], add_remove=[ ('cashbook', '=', Eval('cashbook')), ('date', '>=', Eval('date_from')), ('date', '<=', Eval('date_to')), ], domain=[ ('date', '>=', Eval('date_from')), ('date', '<=', Eval('date_to')), ]) state = fields.Selection(string='State', required=True, readonly=True, select=True, selection=sel_reconstate) state_string = state.translated('state') state_cashbook = fields.Function(fields.Selection(string='State of Cashbook', readonly=True, states={'invisible': True}, selection=sel_state_book), 'on_change_with_state_cashbook') @classmethod def __setup__(cls): super(Reconciliation, cls).__setup__() cls._order.insert(0, ('date_from', 'ASC')) cls._transitions |= set(( ('edit', 'check'), ('check', 'done'), ('check', 'edit'), )) cls._buttons.update({ 'wfedit': { 'invisible': Eval('state', '') != 'check', 'depends': ['state'], }, 'wfcheck': { 'invisible': Eval('state') != 'edit', 'depends': ['state'], }, 'wfdone': { 'invisible': Eval('state') != 'check', 'depends': ['state'], }, }) @classmethod @ModelView.button @Workflow.transition('edit') def wfedit(cls, lines): """ edit """ pass @classmethod @ModelView.button @Workflow.transition('check') def wfcheck(cls, lines): """ is checked """ pass @classmethod @ModelView.button @Workflow.transition('done') def wfdone(cls, lines): """ is done """ pass def get_rec_name(self, name): """ short + name """ return '%(from)s - %(to)s: %(amount)s %(symbol)s' % { 'from': Report.format_date(self.date_from, None) if self.date_from is not None else '-', 'to': Report.format_date(self.date_to, None) if self.date_to is not None else '-', 'amount': Decimal('0.0'), 'symbol': getattr(getattr(self.cashbook, 'currency', None), 'symbol', '-'), } @classmethod def default_state(cls): return 'edit' @classmethod def default_date(cls): """ today """ IrDate = Pool().get('ir.date') return IrDate.today() @fields.depends('cashbook', '_parent_cashbook.state') def on_change_with_state_cashbook(self, name=None): """ get state of cashbook """ if self.cashbook: return self.cashbook.state # end Type