From 37c795d589bd4939c83002e18e624460c6e22ad4 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 21 Jun 2021 15:43:04 +0100 Subject: [PATCH] Bug 22435: (follow-up) Update POS for reduced offset types This patch updates the Koha::Charges::Sales class to use the 'CREATE' and 'APPLY' offset types. Test plan 1/ Run t/db_dependent/Koha/Charges/Sales.t Signed-off-by: Tomas Cohen Arazi Signed-off-by: Jonathan Druart --- Koha/Charges/Sales.pm | 34 +++++++++++------------------ t/db_dependent/Koha/Charges/Sales.t | 4 ++-- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/Koha/Charges/Sales.pm b/Koha/Charges/Sales.pm index 5d99474868..20ea3fcb3d 100644 --- a/Koha/Charges/Sales.pm +++ b/Koha/Charges/Sales.pm @@ -196,7 +196,7 @@ sub purchase { my $schema = Koha::Database->new->schema; my $dt = dt_from_string(); my $total_owed = 0; - my $credit; + my $payment; $schema->txn_do( sub { @@ -213,7 +213,7 @@ sub purchase { { amount => $amount, debit_type_code => $item->{code}, - amountoutstanding => 0, + amountoutstanding => $amount, note => $item->{quantity}, manager_id => $self->{staff_id}, interface => 'intranet', @@ -227,19 +227,19 @@ sub purchase { my $account_offset = Koha::Account::Offset->new( { debit_id => $debit->id, - type => 'Purchase', + type => 'CREATE', amount => $amount } )->store(); } # Add accountline for payment - $credit = Koha::Account::Line->new( + $payment = Koha::Account::Line->new( { amount => 0 - $total_owed, credit_type_code => 'PURCHASE', payment_type => $self->{payment_type}, - amountoutstanding => 0, + amountoutstanding => 0 - $total_owed, manager_id => $self->{staff_id}, interface => 'intranet', branchcode => $self->{cash_register}->branch, @@ -250,29 +250,21 @@ sub purchase { )->store(); # Record the account offset - my $credit_offset = Koha::Account::Offset->new( + my $payment_offset = Koha::Account::Offset->new( { - credit_id => $credit->id, - type => 'Purchase', - amount => $credit->amount + credit_id => $payment->id, + type => 'CREATE', + amount => $payment->amount } )->store(); - # Link payment to debits - for my $debit ( @{$debits} ) { - Koha::Account::Offset->new( - { - credit_id => $credit->accountlines_id, - debit_id => $debit->id, - amount => $debit->amount * -1, - type => 'Payment', - } - )->store(); - } + # Link payment to charges + $payment->apply( { debits => $debits } ); + $payment->discard_changes; } ); - return $credit; + return $payment; } =head1 AUTHOR diff --git a/t/db_dependent/Koha/Charges/Sales.t b/t/db_dependent/Koha/Charges/Sales.t index c3064fbba0..85676ef840 100755 --- a/t/db_dependent/Koha/Charges/Sales.t +++ b/t/db_dependent/Koha/Charges/Sales.t @@ -236,8 +236,8 @@ subtest 'purchase tests' => sub { is(ref($credit), 'Koha::Account::Line', "Koha::Account::Line returned"); ok($credit->is_credit, "return is a credit for payment"); is($credit->credit_type_code, 'PURCHASE', "credit_type_code set correctly to 'PURCHASE' for payment"); - is($credit->amount, -5.00, "amount is calculated correctly for payment"); - is($credit->amountoutstanding, 0.00, "amountoutstanding is set to zero for payment"); + is($credit->amount * 1, -5, "amount is calculated correctly for payment"); + is($credit->amountoutstanding * 1, 0, "amountoutstanding is set to zero for payment"); is($credit->manager_id, $staff->borrowernumber, "manager_id set correctionly for payment"); is($credit->register_id, $cash_register->id, "register_id set correctly for payment"); is($credit->payment_type, 'CASH', "payment_type set correctly for payment"); -- 2.39.5