2022-08-12 14:43:49 +00:00
# -*- 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 . tests . test_tryton import ModuleTestCase , with_transaction
from trytond . pool import Pool
from trytond . transaction import Transaction
from trytond . exceptions import UserError
from datetime import date
from decimal import Decimal
class ReconTestCase ( ModuleTestCase ) :
' Test cashbook reconciliation module '
module = ' cashbook '
@with_transaction ( )
def test_recon_check_overlap ( self ) :
""" create, check deny of overlap date
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
category = self . prep_category ( cattype = ' in ' )
company = self . prep_company ( )
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-12 14:43:49 +00:00
} ] )
recon1 , = Reconciliation . create ( [ {
' date ' : date ( 2022 , 5 , 1 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
' cashbook ' : book . id ,
} ] )
self . assertEqual ( recon1 . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
recon2 , = Reconciliation . create ( [ {
' date ' : date ( 2022 , 6 , 1 ) ,
' date_from ' : date ( 2022 , 6 , 1 ) ,
' date_to ' : date ( 2022 , 6 , 30 ) ,
' cashbook ' : book . id ,
} ] )
2022-08-15 15:19:53 +00:00
# updated by create to date_to of predecessor
self . assertEqual ( recon2 . rec_name , ' 05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] ' )
2022-08-12 14:43:49 +00:00
# same day for end of '0' and start of '1'
self . assertEqual ( recon1 . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
self . assertEqual ( recon2 . rec_name , ' 05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] ' )
# 'date_from' inside of other record
self . assertRaisesRegex ( UserError ,
' The date range overlaps with another reconciliation. ' ,
Reconciliation . write ,
* [
[ recon2 ] ,
{
' date_from ' : date ( 2022 , 5 , 30 ) ,
} ,
] )
# 'date_from' inside of other record
self . assertRaisesRegex ( UserError ,
' The date range overlaps with another reconciliation. ' ,
Reconciliation . write ,
* [
[ recon2 ] ,
{
' date_from ' : date ( 2022 , 5 , 2 ) ,
} ,
] )
# 'date_from' same date_from like other record
self . assertRaisesRegex ( UserError ,
' The date range overlaps with another reconciliation. ' ,
Reconciliation . write ,
* [
[ recon2 ] ,
{
' date_from ' : date ( 2022 , 5 , 1 ) ,
} ,
] )
# enclose other record
self . assertRaisesRegex ( UserError ,
' The date range overlaps with another reconciliation. ' ,
Reconciliation . write ,
* [
[ recon2 ] ,
{
' date_from ' : date ( 2022 , 4 , 30 ) ,
} ,
] )
# within other record
self . assertRaisesRegex ( UserError ,
' The date range overlaps with another reconciliation. ' ,
Reconciliation . write ,
* [
[ recon2 ] ,
{
' date_from ' : date ( 2022 , 5 , 2 ) ,
' date_to ' : date ( 2022 , 5 , 12 ) ,
} ,
] )
# from after to
self . assertRaisesRegex ( UserError ,
' The value for field " Start Date " in " Cashbook Reconciliation " is not valid according to its domain. ' ,
Reconciliation . write ,
* [
[ recon2 ] ,
{
' date_from ' : date ( 2022 , 4 , 15 ) ,
' date_to ' : date ( 2022 , 4 , 10 ) ,
} ,
] )
# 'date_to' at 'date_from' of other record - allowed
Reconciliation . write ( * [
[ recon2 ] ,
{
' date_from ' : date ( 2022 , 4 , 15 ) ,
' date_to ' : date ( 2022 , 5 , 1 ) ,
} ] )
# 'date_to' after other date_from
self . assertRaisesRegex ( UserError ,
' The date range overlaps with another reconciliation. ' ,
Reconciliation . write ,
* [
[ recon2 ] ,
{
' date_to ' : date ( 2022 , 5 , 2 ) ,
} ,
] )
2022-08-15 15:19:53 +00:00
# overlap at .create()
2022-08-12 14:43:49 +00:00
self . assertRaisesRegex ( UserError ,
' The date range overlaps with another reconciliation. ' ,
Reconciliation . create ,
[ {
' date ' : date ( 2022 , 5 , 1 ) ,
' date_from ' : date ( 2022 , 4 , 1 ) ,
' date_to ' : date ( 2022 , 4 , 16 ) ,
' cashbook ' : book . id ,
} ] )
recon3 , = Reconciliation . create ( [ {
' date ' : date ( 2022 , 4 , 17 ) ,
2022-08-15 15:19:53 +00:00
' date_from ' : date ( 2022 , 6 , 1 ) ,
' date_to ' : date ( 2022 , 6 , 15 ) ,
2022-08-12 14:43:49 +00:00
' cashbook ' : book . id ,
} ] )
self . assertEqual ( recon1 . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
self . assertEqual ( recon2 . rec_name , ' 04/15/2022 - 05/01/2022 | 0.00 usd - 0.00 usd [0] ' )
2022-08-15 15:19:53 +00:00
self . assertEqual ( recon3 . rec_name , ' 05/31/2022 - 06/15/2022 | 0.00 usd - 0.00 usd [0] ' )
@with_transaction ( )
def test_recon_set_start_amount_by_cashbook ( self ) :
""" set stat-amount from cashbook-setting
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
company = self . prep_company ( )
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
' start_balance ' : Decimal ( ' 12.50 ' ) ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-15 15:19:53 +00:00
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . reconciliations [ 0 ] . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
Reconciliation . wfcheck ( list ( book . reconciliations ) )
self . assertEqual ( book . reconciliations [ 0 ] . rec_name , ' 05/01/2022 - 05/31/2022 | 12.50 usd - 12.50 usd [0] ' )
@with_transaction ( )
def test_recon_set_start_amount_by_predecessor ( self ) :
""" set stat-amount from end_amount of predecessor
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Lines = pool . get ( ' cashbook.line ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
company = self . prep_company ( )
category = self . prep_category ( cattype = ' in ' )
2022-08-16 12:16:14 +00:00
party = self . prep_party ( )
2022-08-15 15:19:53 +00:00
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
' start_balance ' : Decimal ( ' 12.50 ' ) ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-15 15:19:53 +00:00
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
' lines ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 5 ) ,
' bookingtype ' : ' in ' ,
' category ' : category . id ,
' description ' : ' Line 1 ' ,
' amount ' : Decimal ( ' 5.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-15 15:19:53 +00:00
} , {
' date ' : date ( 2022 , 5 , 5 ) ,
' bookingtype ' : ' in ' ,
' category ' : category . id ,
' description ' : ' Line 2 ' ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
' amount ' : Decimal ( ' 7.0 ' ) ,
2022-08-15 15:19:53 +00:00
} , ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( len ( book . reconciliations ) , 1 )
self . assertEqual ( book . reconciliations [ 0 ] . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 0 )
Lines . wfcheck ( list ( book . lines ) )
Reconciliation . wfcheck ( list ( book . reconciliations ) )
self . assertEqual ( book . reconciliations [ 0 ] . state , ' check ' )
self . assertEqual ( book . reconciliations [ 0 ] . rec_name , ' 05/01/2022 - 05/31/2022 | 12.50 usd - 24.50 usd [2] ' )
Reconciliation . wfdone ( list ( book . reconciliations ) )
self . assertEqual ( book . reconciliations [ 0 ] . state , ' done ' )
recons = Reconciliation . create ( [ {
' cashbook ' : book . id ,
' date_from ' : date ( 2022 , 5 , 31 ) ,
' date_to ' : date ( 2022 , 6 , 30 ) ,
} ] )
self . assertEqual ( recons [ 0 ] . rec_name , ' 05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] ' )
Reconciliation . wfcheck ( recons )
self . assertEqual ( recons [ 0 ] . rec_name , ' 05/31/2022 - 06/30/2022 | 24.50 usd - 24.50 usd [0] ' )
@with_transaction ( )
def test_recon_predecessor_done ( self ) :
""" predecessor must be done
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
company = self . prep_company ( )
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-15 15:19:53 +00:00
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . state , ' open ' )
Reconciliation . wfcheck ( list ( book . reconciliations ) )
self . assertEqual ( book . reconciliations [ 0 ] . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
self . assertEqual ( book . reconciliations [ 0 ] . state , ' check ' )
recons = Reconciliation . create ( [ {
' cashbook ' : book . id ,
' date_from ' : date ( 2022 , 5 , 31 ) ,
' date_to ' : date ( 2022 , 6 , 30 ) ,
} ] )
self . assertRaisesRegex ( UserError ,
" The predecessor ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' must be in the ' Done ' state before you can check the current reconciliation ' 05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] ' . " ,
Reconciliation . wfcheck ,
recons )
2022-08-18 09:58:05 +00:00
@with_transaction ( )
def test_recon_autoset_date_to ( self ) :
""" create reconciliation, check: set date_to to last date of checked-line
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Line = pool . get ( ' cashbook.line ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
company = self . prep_company ( )
party = self . prep_party ( )
category = self . prep_category ( cattype = ' in ' )
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
' number_sequ ' : self . prep_sequence ( ) . id ,
' start_date ' : date ( 2022 , 5 , 1 ) ,
' lines ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 5 ) ,
' amount ' : Decimal ( ' 10.0 ' ) ,
' bookingtype ' : ' in ' ,
' party ' : party . id ,
' category ' : category . id ,
} , {
' date ' : date ( 2022 , 5 , 18 ) ,
' amount ' : Decimal ( ' 5.0 ' ) ,
' bookingtype ' : ' in ' ,
' party ' : party . id ,
' category ' : category . id ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . state , ' open ' )
Line . wfcheck ( list ( book . lines ) )
recon , = Reconciliation . create ( [ {
' cashbook ' : book . id ,
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 5 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] )
# dates are updates by .create()
self . assertEqual ( recon . rec_name , ' 05/01/2022 - 05/18/2022 | 0.00 usd - 0.00 usd [0] ' )
Reconciliation . wfcheck ( [ recon ] )
self . assertEqual ( recon . rec_name , ' 05/01/2022 - 05/18/2022 | 0.00 usd - 15.00 usd [2] ' )
2022-08-15 15:19:53 +00:00
@with_transaction ( )
def test_recon_autoset_date_from ( self ) :
""" create reconciliation, check: set date_from to end of predecessor
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
company = self . prep_company ( )
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-15 15:19:53 +00:00
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
2022-08-18 09:58:05 +00:00
' date_from ' : date ( 2022 , 5 , 5 ) ,
2022-08-15 15:19:53 +00:00
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . state , ' open ' )
Reconciliation . wfcheck ( [ book . reconciliations [ 0 ] ] )
Reconciliation . wfdone ( [ book . reconciliations [ 0 ] ] )
2022-08-18 09:58:05 +00:00
# date_from is corrected by .create() to start_date of book
self . assertEqual ( book . reconciliations [ 0 ] . rec_name ,
' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
2022-08-15 15:19:53 +00:00
r2 , = Reconciliation . create ( [ {
' cashbook ' : book . id ,
' date_from ' : date ( 2022 , 6 , 10 ) ,
' date_to ' : date ( 2022 , 6 , 30 ) ,
} ] )
self . assertEqual ( r2 . rec_name , ' 05/31/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] ' )
# update 'date_from' to wrong value
Reconciliation . write ( * [
[ r2 ] ,
{
' date_from ' : date ( 2022 , 6 , 1 ) ,
} ] )
self . assertEqual ( r2 . rec_name , ' 06/01/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] ' )
self . assertRaisesRegex ( UserError ,
" The start date ' 06/01/2022 ' of the current reconciliation ' 06/01/2022 - 06/30/2022 | 0.00 usd - 0.00 usd [0] ' must correspond to the end date ' 05/31/2022 ' of the predecessor. " ,
Reconciliation . wfcheck ,
[ r2 ] )
2022-08-12 14:43:49 +00:00
@with_transaction ( )
def test_recon_create_check_line_add_to_recon ( self ) :
""" create, booklines, add reconciliation
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Lines = pool . get ( ' cashbook.line ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
category = self . prep_category ( cattype = ' in ' )
company = self . prep_company ( )
2022-08-16 12:16:14 +00:00
party = self . prep_party ( )
2022-08-12 14:43:49 +00:00
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-12 14:43:49 +00:00
' lines ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 1 ) ,
' description ' : ' Text 1 ' ,
' category ' : category . id ,
' bookingtype ' : ' in ' ,
' amount ' : Decimal ( ' 1.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-12 14:43:49 +00:00
} , {
' date ' : date ( 2022 , 5 , 5 ) ,
' description ' : ' Text 2 ' ,
' category ' : category . id ,
' bookingtype ' : ' in ' ,
' amount ' : Decimal ( ' 1.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-12 14:43:49 +00:00
} ] ) ] ,
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . state , ' open ' )
self . assertEqual ( len ( book . lines ) , 2 )
2022-08-16 12:16:14 +00:00
self . assertEqual ( book . lines [ 0 ] . rec_name , ' 05/01/2022|Rev|1.00 usd|Text 1 [Cat1] ' )
self . assertEqual ( book . lines [ 1 ] . rec_name , ' 05/05/2022|Rev|1.00 usd|Text 2 [Cat1] ' )
2022-08-12 14:43:49 +00:00
self . assertEqual ( len ( book . reconciliations ) , 1 )
self . assertEqual ( book . reconciliations [ 0 ] . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 0 )
self . assertRaisesRegex ( UserError ,
2022-08-16 12:16:14 +00:00
" For reconciliation, the line ' 05/01/2022|Rev|1.00 usd|Text 1 [Cat1] ' must be in the status ' Check ' or ' Done ' . " ,
2022-08-12 14:43:49 +00:00
Lines . write ,
* [
[ book . lines [ 0 ] ] ,
{
' reconciliation ' : book . reconciliations [ 0 ] . id ,
}
] )
Lines . wfcheck ( book . lines )
Lines . write ( * [
list ( book . lines ) ,
{
' reconciliation ' : book . reconciliations [ 0 ] . id ,
} ] )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 2 )
self . assertRaisesRegex ( UserError ,
" The status cannot be changed to ' Edit ' as long as the line ' 05/01/2022|1.00 usd|Text 1 [Cat1] ' is associated with a reconciliation. " ,
Lines . wfedit ,
[ book . lines [ 0 ] ] )
2022-08-15 15:19:53 +00:00
# unlink lines from reconciliation
self . assertEqual ( book . reconciliations [ 0 ] . state , ' edit ' )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 2 )
Reconciliation . wfcheck ( list ( book . reconciliations ) )
Reconciliation . wfedit ( list ( book . reconciliations ) )
self . assertEqual ( book . reconciliations [ 0 ] . state , ' edit ' )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 0 )
# move date of 2nd line to june 1
# set reconciliation to 'check'
Lines . wfedit ( [ book . lines [ 1 ] ] )
Lines . write ( * [
[ book . lines [ 1 ] ] ,
{
' date ' : date ( 2022 , 6 , 1 ) ,
} ] )
# check reconciliation, this linkes the 1st line by date
Reconciliation . wfcheck ( list ( book . reconciliations ) )
self . assertEqual ( book . reconciliations [ 0 ] . state , ' check ' )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 1 )
2022-08-16 12:16:14 +00:00
self . assertEqual ( book . reconciliations [ 0 ] . lines [ 0 ] . rec_name , ' 05/01/2022|Rev|1.00 usd|Text 1 [Cat1] ' )
self . assertEqual ( book . lines [ 0 ] . rec_name , ' 05/01/2022|Rev|1.00 usd|Text 1 [Cat1] ' )
self . assertEqual ( book . lines [ 1 ] . rec_name , ' 06/01/2022|Rev|1.00 usd|Text 2 [Cat1] ' )
2022-08-15 15:19:53 +00:00
# move 2nd line into date-range of checked-reconciliation, wf-check
Lines . write ( * [
[ book . lines [ 1 ] ] ,
{
' date ' : date ( 2022 , 5 , 20 ) ,
} ] )
self . assertRaisesRegex ( UserError ,
" For the date ' 05/20/2022 ' there is already a completed reconciliation. Use a different date. " ,
Lines . wfcheck ,
[ book . lines [ 1 ] ] )
# set date to end of date-range of reconciliation
# should work
Lines . write ( * [
[ book . lines [ 1 ] ] ,
{
' date ' : date ( 2022 , 5 , 31 ) ,
} ] )
Lines . wfcheck ( [ book . lines [ 1 ] ] ) # ok
Lines . wfedit ( [ book . lines [ 1 ] ] )
Lines . write ( * [
[ book . lines [ 1 ] ] ,
{
' date ' : date ( 2022 , 7 , 1 ) ,
} ] )
# add 2nd reconciliation
recon2 , = Reconciliation . create ( [ {
' cashbook ' : book . id ,
' date_from ' : date ( 2022 , 5 , 31 ) ,
' date_to ' : date ( 2022 , 6 , 30 ) ,
} ] )
Reconciliation . wfdone ( [ book . reconciliations [ 0 ] ] )
Reconciliation . wfcheck ( [ recon2 ] )
Lines . write ( * [
[ book . lines [ 1 ] ] ,
{
' date ' : date ( 2022 , 5 , 31 ) ,
} ] )
self . assertRaisesRegex ( UserError ,
" For the date ' 05/31/2022 ' there is already a completed reconciliation. Use a different date. " ,
Lines . wfcheck ,
[ book . lines [ 1 ] ] )
@with_transaction ( )
def test_recon_check_wfcheck_missing_lines ( self ) :
""" create, booklines, check missing line at wfcheck
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Lines = pool . get ( ' cashbook.line ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
category = self . prep_category ( cattype = ' in ' )
company = self . prep_company ( )
2022-08-16 12:16:14 +00:00
party = self . prep_party ( )
2022-08-15 15:19:53 +00:00
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-15 15:19:53 +00:00
' lines ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 1 ) ,
' description ' : ' Text 1 ' ,
' category ' : category . id ,
' bookingtype ' : ' in ' ,
' amount ' : Decimal ( ' 1.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-15 15:19:53 +00:00
} , {
' date ' : date ( 2022 , 6 , 5 ) ,
' description ' : ' Text 2 ' ,
' category ' : category . id ,
' bookingtype ' : ' in ' ,
' amount ' : Decimal ( ' 1.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-15 15:19:53 +00:00
} ] ) ] ,
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . state , ' open ' )
self . assertEqual ( len ( book . lines ) , 2 )
2022-08-16 12:16:14 +00:00
self . assertEqual ( book . lines [ 0 ] . rec_name , ' 05/01/2022|Rev|1.00 usd|Text 1 [Cat1] ' )
self . assertEqual ( book . lines [ 1 ] . rec_name , ' 06/05/2022|Rev|1.00 usd|Text 2 [Cat1] ' )
2022-08-15 15:19:53 +00:00
Lines . wfcheck ( [ book . lines [ 0 ] ] )
Reconciliation . wfcheck ( [ book . reconciliations [ 0 ] ] )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 1 )
2022-08-16 12:16:14 +00:00
self . assertEqual ( book . reconciliations [ 0 ] . lines [ 0 ] . rec_name , ' 05/01/2022|Rev|1.00 usd|Text 1 [Cat1] ' )
2022-08-15 15:19:53 +00:00
Lines . write ( * [
[ book . lines [ 1 ] ] ,
{
' date ' : date ( 2022 , 5 , 15 ) ,
} ] )
self . assertRaisesRegex ( UserError ,
" In the date range from 05/01/2022 to 05/31/2022, there are still cashbook lines that do not belong to any reconciliation. " ,
Reconciliation . wfdone ,
[ book . reconciliations [ 0 ] ] )
2022-08-12 14:43:49 +00:00
@with_transaction ( )
def test_recon_check_deny_delete ( self ) :
""" create, booklines, reconciliation, try delete
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Lines = pool . get ( ' cashbook.line ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
category = self . prep_category ( cattype = ' in ' )
company = self . prep_company ( )
2022-08-16 12:16:14 +00:00
party = self . prep_party ( )
2022-08-12 14:43:49 +00:00
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-12 14:43:49 +00:00
' lines ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 1 ) ,
' description ' : ' Text 1 ' ,
' category ' : category . id ,
' bookingtype ' : ' in ' ,
' amount ' : Decimal ( ' 1.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-12 14:43:49 +00:00
} ] ) ] ,
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . state , ' open ' )
Lines . wfcheck ( list ( book . lines ) )
Reconciliation . wfcheck ( list ( book . reconciliations ) )
self . assertEqual ( len ( book . reconciliations ) , 1 )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 1 )
self . assertRaisesRegex ( UserError ,
" The reconciliation ' 05/01/2022 - 05/31/2022 | 0.00 - 0.00 usd [0] ' cannot be deleted, its in state ' Check ' . " ,
Reconciliation . delete ,
list ( book . reconciliations ) )
Book . wfclosed ( [ book ] )
self . assertRaisesRegex ( UserError ,
" The cashbook line ' 05/01/2022 - 05/31/2022: 0.00 usd ' cannot be deleted because the Cashbook ' Book 1 | 1.00 usd | Closed ' is in state ' Closed ' . " ,
Reconciliation . delete ,
list ( book . reconciliations ) )
self . assertRaisesRegex ( UserError ,
" The cash book ' Book 1 | 1.00 usd | Closed ' is ' Closed ' and cannot be changed. " ,
Reconciliation . write ,
* [
list ( book . reconciliations ) ,
{
' date ' : date ( 2022 , 5 , 29 ) ,
} ,
] )
@with_transaction ( )
def test_recon_check_wf_edit_to_check ( self ) :
""" create, booklines, add reconciliation
"""
pool = Pool ( )
Book = pool . get ( ' cashbook.book ' )
Lines = pool . get ( ' cashbook.line ' )
Reconciliation = pool . get ( ' cashbook.recon ' )
types = self . prep_type ( )
category = self . prep_category ( cattype = ' in ' )
company = self . prep_company ( )
2022-08-16 12:16:14 +00:00
party = self . prep_party ( )
2022-08-12 14:43:49 +00:00
book , = Book . create ( [ {
' name ' : ' Book 1 ' ,
' btype ' : types . id ,
' company ' : company . id ,
' currency ' : company . currency . id ,
2022-08-16 14:45:32 +00:00
' number_sequ ' : self . prep_sequence ( ) . id ,
2022-08-18 09:58:05 +00:00
' start_date ' : date ( 2022 , 5 , 1 ) ,
2022-08-12 14:43:49 +00:00
' lines ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 1 ) ,
' description ' : ' Text 1 ' ,
' category ' : category . id ,
' bookingtype ' : ' in ' ,
' amount ' : Decimal ( ' 1.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-12 14:43:49 +00:00
} , {
' date ' : date ( 2022 , 5 , 5 ) ,
' description ' : ' Text 2 ' ,
' category ' : category . id ,
' bookingtype ' : ' in ' ,
' amount ' : Decimal ( ' 1.0 ' ) ,
2022-08-16 12:16:14 +00:00
' party ' : party . id ,
2022-08-12 14:43:49 +00:00
} ] ) ] ,
' reconciliations ' : [ ( ' create ' , [ {
' date ' : date ( 2022 , 5 , 28 ) ,
' date_from ' : date ( 2022 , 5 , 1 ) ,
' date_to ' : date ( 2022 , 5 , 31 ) ,
} ] ) ] ,
} ] )
self . assertEqual ( book . name , ' Book 1 ' )
self . assertEqual ( book . state , ' open ' )
self . assertEqual ( len ( book . lines ) , 2 )
2022-08-16 12:16:14 +00:00
self . assertEqual ( book . lines [ 0 ] . rec_name , ' 05/01/2022|Rev|1.00 usd|Text 1 [Cat1] ' )
self . assertEqual ( book . lines [ 1 ] . rec_name , ' 05/05/2022|Rev|1.00 usd|Text 2 [Cat1] ' )
2022-08-12 14:43:49 +00:00
self . assertEqual ( book . lines [ 0 ] . reconciliation , None )
self . assertEqual ( book . lines [ 1 ] . reconciliation , None )
self . assertEqual ( len ( book . reconciliations ) , 1 )
self . assertEqual ( book . reconciliations [ 0 ] . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 0 )
# run wf, fail with lines not 'checked'
self . assertRaisesRegex ( UserError ,
" For the reconciliation ' 05/01/2022 - 05/31/2022 | 0.00 usd - 0.00 usd [0] ' of the cashbook ' Book 1 | 2.00 usd | Open ' , all lines in the date range from ' 05/01/2022 ' to ' 05/31/2022 ' must be in the ' Check ' state. " ,
Reconciliation . wfcheck ,
list ( book . reconciliations ) ,
)
# edit --> check
Lines . wfcheck ( book . lines )
Reconciliation . wfcheck ( list ( book . reconciliations ) )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 2 )
2022-08-15 15:19:53 +00:00
self . assertEqual ( book . lines [ 0 ] . reconciliation . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 2.00 usd [2] ' )
self . assertEqual ( book . lines [ 1 ] . reconciliation . rec_name , ' 05/01/2022 - 05/31/2022 | 0.00 usd - 2.00 usd [2] ' )
2022-08-12 14:43:49 +00:00
# check --> edit
Reconciliation . wfedit ( list ( book . reconciliations ) )
self . assertEqual ( len ( book . reconciliations [ 0 ] . lines ) , 0 )
self . assertEqual ( book . lines [ 0 ] . reconciliation , None )
self . assertEqual ( book . lines [ 1 ] . reconciliation , None )
# end ReconTestCase