@@ -44,15 +44,15 @@ BEGIN;
4444 insert into session (session_id, users_id, token, last_used)
4545 values (-200, -200, md5(random()::text), now());
4646
47- WITH a (accno, description, category) as (
48- values ('00001'::text, 'testing AP'::text, 'L'::text ),
49- ('00002', 'testing AP cost', 'E'),
50- ('00003', 'testing cash', 'A'),
51- ('00004', 'fx gain', 'I'),
52- ('00005', 'fx loss', 'E')
47+ WITH a (accno, description, category, open_item_managed ) as (
48+ values ('00001'::text, 'testing AP'::text, 'L'::text, true ),
49+ ('00002', 'testing AP cost', 'E', false ),
50+ ('00003', 'testing cash', 'A', false ),
51+ ('00004', 'fx gain', 'I', false ),
52+ ('00005', 'fx loss', 'E', false )
5353 )
54- INSERT INTO account (accno, description, category, heading)
55- SELECT a.accno, a.description, a.category, h.id
54+ INSERT INTO account (accno, description, category, heading, open_item_managed )
55+ SELECT a.accno, a.description, a.category, h.id, a.open_item_managed
5656 FROM account_heading h
5757 JOIN a ON h.accno = '000000000000000000000';
5858
8181 VALUES ('inv_test1', 'ap', (select id from account where accno = '00001'));
8282 INSERT INTO ap (id, open_item_id, amount_bc, amount_tc, invnumber, curr, entity_credit_account)
8383 VALUES (-11, currval('open_item_id_seq'), 100, 110, 'inv_test1', 'xts', -101);
84- INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id)
85- VALUES (-11, '1901-01-01', 100, 'xts', 110, 't', (select id from account where accno = '00001')),
86- (-11, '1901-01-01', -100, 'xts', -110, 't', (select id from account where accno = '00002'));
84+ INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id, open_item_id )
85+ VALUES (-11, '1901-01-01', 100, 'xts', 110, 't', (select id from account where accno = '00001'), currval('open_item_id_seq') ),
86+ (-11, '1901-01-01', -100, 'xts', -110, 't', (select id from account where accno = '00002'), null );
8787
8888 -- Pay the invoice in full
8989 SELECT * FROM
9999 ARRAY['cash '], -- source
100100 ARRAY[NULL], -- memo
101101 ARRAY[-11], -- transaction_id
102+ ARRAY[currval('open_item_id_seq')::int],
102103 NULL, -- op_amount
103104 NULL, -- op_cash_account_id
104105 NULL, -- op_source
@@ -135,12 +136,12 @@ BEGIN;
135136 VALUES ('inv_test2', 'ap', (select id from account where accno = '00001'));
136137 INSERT INTO ap (id, open_item_id, amount_bc, amount_tc, invnumber, curr, entity_credit_account)
137138 VALUES (-12, currval('open_item_id_seq'), 100, 110, 'inv_test2', 'xts', -101);
138- INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id)
139- VALUES (-12, '1901-01-02', 100, 'xts', 110, 't', (select id from account where accno = '00001')),
140- (-12, '1901-01-02', -100, 'xts', -110, 't', (select id from account where accno = '00002'));
139+ INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id, open_item_id )
140+ VALUES (-12, '1901-01-02', 100, 'xts', 110, 't', (select id from account where accno = '00001'), currval('open_item_id_seq') ),
141+ (-12, '1901-01-02', -100, 'xts', -110, 't', (select id from account where accno = '00002'), null );
141142
142143
143- SELECT payment_bulk_post(ARRAY[ARRAY[-12,110]],
144+ SELECT payment_bulk_post(ARRAY[ARRAY[-12,currval('open_item_id_seq'), 110]],
144145 batch_create('TestBatch', 'TestBatch',
145146 'payment', -- payment
146147 '1901-01-03'::date), 'source',
@@ -175,9 +176,9 @@ BEGIN;
175176 VALUES ('inv_test1/2', 'ap', (select id from account where accno = '00001'));
176177 INSERT INTO ap (id, open_item_id, amount_bc, amount_tc, invnumber, curr, entity_credit_account)
177178 VALUES (-13, currval('open_item_id_seq'), 100, 110, 'inv_test1', 'xts', -101);
178- INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id)
179- VALUES (-13, '1901-01-01', 100, 'xts', 110, 't', (select id from account where accno = '00001')),
180- (-13, '1901-01-01', -100, 'xts', -110, 't', (select id from account where accno = '00002'));
179+ INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id, open_item_id )
180+ VALUES (-13, '1901-01-01', 100, 'xts', 110, 't', (select id from account where accno = '00001'), currval('open_item_id_seq') ),
181+ (-13, '1901-01-01', -100, 'xts', -110, 't', (select id from account where accno = '00002'), null );
181182
182183
183184 PREPARE test AS
@@ -194,6 +195,7 @@ BEGIN;
194195 ARRAY['cash '], -- source
195196 ARRAY[NULL], -- memo
196197 ARRAY[-13], -- transaction_id
198+ ARRAY[currval('open_item_id_seq')::int], -- open_item_id
197199 NULL, -- op_amount
198200 NULL, -- op_cash_account_id
199201 NULL, -- op_source
@@ -214,13 +216,13 @@ BEGIN;
214216 VALUES ('inv_test2/2', 'ap', (select id from account where accno = '00001'));
215217 INSERT INTO ap (id, open_item_id, amount_bc, amount_tc, invnumber, curr, entity_credit_account)
216218 VALUES (-14, currval('open_item_id_seq'), 100, 110, 'inv_test2', 'xts', -101);
217- INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id)
218- VALUES (-14, '1901-01-02', 100, 'xts', 110, 't', (select id from account where accno = '00001')),
219- (-14, '1901-01-02', -100, 'xts', -110, 't', (select id from account where accno = '00002'));
219+ INSERT INTO acc_trans (trans_id, transdate, amount_bc, curr, amount_tc, approved, chart_id, open_item_id )
220+ VALUES (-14, '1901-01-02', 100, 'xts', 110, 't', (select id from account where accno = '00001'), currval('open_item_id_seq') ),
221+ (-14, '1901-01-02', -100, 'xts', -110, 't', (select id from account where accno = '00002'), null );
220222
221223
222224 PREPARE test AS
223- SELECT payment_bulk_post(ARRAY[ARRAY[-14,110]],
225+ SELECT payment_bulk_post(ARRAY[ARRAY[-14,currval('open_item_id_seq'), 110]],
224226 batch_create('TestBatch', 'TestBatch',
225227 'payment', -- payment
226228 '1901-01-03'::date), 'source',
0 commit comments