2022-08-17 15:16:23 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2023-01-15 10:03:50 +00:00
|
|
|
# This file is part of the cashbook-module from m-ds.de for Tryton.
|
2022-08-17 15:16:23 +00:00
|
|
|
# The COPYRIGHT file at the top level of this repository contains the
|
|
|
|
# full copyright notices and license terms.
|
|
|
|
|
|
|
|
from trytond.model import ModelView, fields
|
2023-01-15 10:03:50 +00:00
|
|
|
from trytond.wizard import Wizard, StateView, StateReport, Button
|
2022-08-17 15:16:23 +00:00
|
|
|
from trytond.pool import Pool
|
|
|
|
from trytond.pyson import Eval, Bool
|
|
|
|
from trytond.transaction import Transaction
|
|
|
|
|
|
|
|
|
|
|
|
class RunCbReportStart(ModelView):
|
|
|
|
'Cashbook Report'
|
|
|
|
__name__ = 'cashbook.runrepbook.start'
|
|
|
|
|
2023-05-18 10:15:53 +00:00
|
|
|
cashbook = fields.Many2One(
|
|
|
|
string='Cashbook', required=True,
|
2022-08-17 15:16:23 +00:00
|
|
|
model_name='cashbook.book', depends=['cashbooks'],
|
|
|
|
domain=[('id', 'in', Eval('cashbooks', []))])
|
2023-05-18 10:15:53 +00:00
|
|
|
cashbooks = fields.One2Many(
|
|
|
|
string='Cashbooks', model_name='cashbook.book',
|
2022-08-17 15:16:23 +00:00
|
|
|
field=None, readonly=True, states={'invisible': True})
|
2023-05-18 10:15:53 +00:00
|
|
|
reconciliation = fields.Many2One(
|
|
|
|
string='Reconciliation', required=True,
|
2022-08-17 15:16:23 +00:00
|
|
|
model_name='cashbook.recon', depends=['reconciliations'],
|
|
|
|
states={
|
|
|
|
'readonly': ~Bool(Eval('reconciliations')),
|
|
|
|
}, domain=[('id', 'in', Eval('reconciliations', []))])
|
2023-05-18 10:15:53 +00:00
|
|
|
reconciliations = fields.Function(fields.One2Many(
|
|
|
|
string='Reconciliations',
|
2022-08-17 15:16:23 +00:00
|
|
|
model_name='cashbook.recon', field=None, readonly=True,
|
|
|
|
states={'invisible': True}),
|
|
|
|
'on_change_with_reconciliations')
|
|
|
|
|
|
|
|
@fields.depends('cashbook', 'reconciliations', 'reconciliation')
|
|
|
|
def on_change_cashbook(self):
|
|
|
|
""" update reconciliations
|
|
|
|
"""
|
|
|
|
if self.cashbook:
|
|
|
|
self.reconciliations = self.on_change_with_reconciliations()
|
|
|
|
if len(self.reconciliations or []) > 0:
|
|
|
|
self.reconciliation = self.reconciliations[0]
|
2023-05-18 10:15:53 +00:00
|
|
|
else:
|
2022-08-23 13:45:07 +00:00
|
|
|
self.reconciliation = None
|
2023-05-18 10:15:53 +00:00
|
|
|
else:
|
2022-08-17 15:16:23 +00:00
|
|
|
self.reconciliations = []
|
|
|
|
self.reconciliation = None
|
|
|
|
|
|
|
|
@fields.depends('cashbook')
|
|
|
|
def on_change_with_reconciliations(self, name=None):
|
|
|
|
""" get reconciliations of current cashbook
|
|
|
|
"""
|
|
|
|
Recon2 = Pool().get('cashbook.recon')
|
|
|
|
|
|
|
|
if self.cashbook:
|
|
|
|
recons = Recon2.search([
|
|
|
|
('cashbook.id', '=', self.cashbook.id),
|
|
|
|
], order=[('date_from', 'DESC')])
|
|
|
|
return [x.id for x in recons]
|
|
|
|
|
|
|
|
# end RunCbReportStart
|
|
|
|
|
|
|
|
|
|
|
|
class RunCbReport(Wizard):
|
|
|
|
'Cashbook Report'
|
|
|
|
__name__ = 'cashbook.runrepbook'
|
|
|
|
|
|
|
|
start_state = 'selrecon'
|
2023-05-18 10:15:53 +00:00
|
|
|
selrecon = StateView(
|
|
|
|
'cashbook.runrepbook.start',
|
2022-08-17 15:16:23 +00:00
|
|
|
'cashbook.runrepbook_view_form', [
|
|
|
|
Button(string='Cancel', state='end', icon='tryton-cancel'),
|
2023-05-18 10:15:53 +00:00
|
|
|
Button(
|
|
|
|
string='Report', state='report_', icon='tryton-ok',
|
|
|
|
default=True,
|
|
|
|
states={'readonly': ~Bool(Eval('reconciliation'))})])
|
2022-08-17 15:16:23 +00:00
|
|
|
report_ = StateReport('cashbook.reprecon')
|
|
|
|
|
|
|
|
def default_selrecon(self, fields):
|
|
|
|
""" setup form
|
|
|
|
"""
|
|
|
|
pool = Pool()
|
|
|
|
Book = pool.get('cashbook.book')
|
|
|
|
Recon2 = pool.get('cashbook.recon')
|
|
|
|
context = Transaction().context
|
|
|
|
|
|
|
|
result = {}
|
|
|
|
if context.get('active_model', '') == 'cashbook.book':
|
|
|
|
result['cashbook'] = context.get('active_id', None)
|
|
|
|
elif context.get('active_model', '') == 'cashbook.line':
|
|
|
|
result['cashbook'] = context.get('cashbook', None)
|
2023-05-18 10:15:53 +00:00
|
|
|
else:
|
2022-08-17 15:16:23 +00:00
|
|
|
raise ValueError('invalid model')
|
|
|
|
|
|
|
|
with Transaction().set_context({
|
2023-05-18 10:15:53 +00:00
|
|
|
'_check_access': True}):
|
2022-08-17 15:16:23 +00:00
|
|
|
books = Book.search([])
|
|
|
|
result['cashbooks'] = [x.id for x in books]
|
|
|
|
|
|
|
|
if len(result['cashbooks']) > 0:
|
|
|
|
if result['cashbook'] is None:
|
|
|
|
result['cashbook'] = result['cashbooks'][0]
|
|
|
|
|
|
|
|
recons = Recon2.search([
|
|
|
|
('cashbook.id', '=', result['cashbook']),
|
|
|
|
], order=[('date_from', 'DESC')])
|
|
|
|
if len(recons) > 0:
|
|
|
|
result['reconciliations'] = [x.id for x in recons]
|
|
|
|
result['reconciliation'] = recons[0].id
|
|
|
|
return result
|
|
|
|
|
|
|
|
def do_report_(self, action):
|
|
|
|
""" run report
|
|
|
|
"""
|
|
|
|
# values for 'data' in report
|
2022-08-23 13:45:07 +00:00
|
|
|
if self.selrecon.reconciliation:
|
|
|
|
r1 = {
|
|
|
|
'model': self.selrecon.reconciliation.__name__,
|
|
|
|
'id': self.selrecon.reconciliation.id,
|
|
|
|
'ids': [self.selrecon.reconciliation.id],
|
|
|
|
}
|
2023-05-18 10:15:53 +00:00
|
|
|
else:
|
2022-08-23 13:45:07 +00:00
|
|
|
r1 = {'model': '', 'id': None, 'ids': []}
|
2022-08-17 15:16:23 +00:00
|
|
|
return action, r1
|
|
|
|
|
|
|
|
def transition_report_(self):
|
|
|
|
return 'end'
|
|
|
|
|
|
|
|
# end RunCbReport
|