# -*- 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 ModelView, ModelSQL, Workflow, fields, Check from trytond.pool import Pool from trytond.pyson import Eval, If from .line import sel_linetype, sel_bookingtype, STATES, DEPENDS from .book import sel_state_book class SplitLine(ModelSQL, ModelView): 'Split booking line' __name__ = 'cashbook.split' line = fields.Many2One(string='Line', required=True, select=True, ondelete='CASCADE', model_name='cashbook.line', readonly=True) description = fields.Text(string='Description', states=STATES, depends=DEPENDS) category = fields.Many2One(string='Category', model_name='cashbook.category', ondelete='RESTRICT', states=STATES, depends=DEPENDS+['bookingtype'], required=True, domain=[ If( Eval('bookingtype', '').in_(['in', 'mvin']), ('cattype', '=', 'in'), ('cattype', '=', 'out'), )]) amount = fields.Numeric(string='Amount', digits=(16, Eval('currency_digits', 2)), required=True, states=STATES, depends=DEPENDS+['currency_digits']) currency = fields.Function(fields.Many2One(model_name='currency.currency', string="Currency"), 'on_change_with_currency') currency_digits = fields.Function(fields.Integer(string='Currency Digits'), 'on_change_with_currency_digits') bookingtype = fields.Function(fields.Selection(string='Type', readonly=True, selection=sel_bookingtype), 'on_change_with_bookingtype') state = fields.Function(fields.Selection(string='State', readonly=True, selection=sel_linetype), 'on_change_with_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', searcher='search_state_cashbook') @fields.depends('line', '_parent_line.state') def on_change_with_state(self, name=None): """ get state """ if self.line: return self.line.state @fields.depends('line', '_parent_line.cashbook') def on_change_with_state_cashbook(self, name=None): """ get state of cashbook """ if self.line: return self.line.cashbook.state @fields.depends('line', '_parent_line.bookingtype') def on_change_with_bookingtype(self, name=None): """ get type """ if self.line: return self.line.bookingtype @fields.depends('line', '_parent_line.cashbook') def on_change_with_currency(self, name=None): """ currency of cashbook """ if self.line: return self.line.cashbook.currency.id @fields.depends('line', '_parent_line.cashbook') def on_change_with_currency_digits(self, name=None): """ currency-digits of cashbook """ if self.line: return self.line.cashbook.currency.digits else: return 2 # end SplitLine