Bugzilla – Attachment 19036 Details for
Bug 10390
Add ability to delete unused invoices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[PASSED QA] Bug 10390: Add ability to delete empty invoices
PASSED-QA-Bug-10390-Add-ability-to-delete-empty-in.patch (text/plain), 6.24 KB, created by
Katrin Fischer
on 2013-06-16 11:29:33 UTC
(
hide
)
Description:
[PASSED QA] Bug 10390: Add ability to delete empty invoices
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2013-06-16 11:29:33 UTC
Size:
6.24 KB
patch
obsolete
>From 1c0657490c59dd7dfd9ba7c74b805df7df6aa103 Mon Sep 17 00:00:00 2001 >From: Jared Camins-Esakov <jcamins@cpbibliography.com> >Date: Sun, 2 Jun 2013 07:50:43 -0400 >Subject: [PATCH] [PASSED QA] Bug 10390: Add ability to delete empty invoices > >There is currently no way to delete unused invoices (for example, >invoices created by mistake), and there really should be, since errors >and absent-mindedness can result in numerous empty invoices over the >course of years. > >To test: >1) Apply patch. >2) Create three invoices in the Acquisitions module. For one of them, > receive at least one item. For the other two, do not receive any > items. >3) View one of the invoices that does not have any items on it. >4) Try to delete it. This should succeed. >5) View the invoice that has an item. There should not be any option > to delete it. >6) Do an invoice search that brings up the other invoice with no items > on it. Try to delete it from the results page. This should succeed. >7) Run the unit test: > > prove t/Acquisition/Invoice.t >8) Sign off. > >Signed-off-by: Srdjan <srdjan@catalyst.net.nz> >Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de> >All tests and QA script pass. I also did another test: > >I cancelled all receipts from an existing invoice and then could >successfully delete it in the last step. >--- > C4/Acquisition.pm | 34 ++++++++++++++++++++ > acqui/invoice.pl | 8 +++++ > .../intranet-tmpl/prog/en/modules/acqui/invoice.tt | 3 ++ > .../prog/en/modules/acqui/invoices.tt | 3 ++ > t/Acquisition/Invoice.t | 23 ++++++++++++- > 5 files changed, 70 insertions(+), 1 deletion(-) > >diff --git a/C4/Acquisition.pm b/C4/Acquisition.pm >index b6fab5d..dd7069a 100644 >--- a/C4/Acquisition.pm >+++ b/C4/Acquisition.pm >@@ -71,6 +71,7 @@ BEGIN { > &ModInvoice > &CloseInvoice > &ReopenInvoice >+ &DelInvoice > > &GetItemnumbersFromOrder > >@@ -2607,6 +2608,39 @@ sub ReopenInvoice { > $sth->execute($invoiceid); > } > >+=head3 DelInvoice >+ >+ DelInvoice($invoiceid); >+ >+Delete an invoice if there are no items attached to it. >+ >+=cut >+ >+sub DelInvoice { >+ my ($invoiceid) = @_; >+ >+ return unless $invoiceid; >+ >+ my $dbh = C4::Context->dbh; >+ my $query = qq{ >+ SELECT COUNT(*) >+ FROM aqorders >+ WHERE invoiceid = ? >+ }; >+ my $sth = $dbh->prepare($query); >+ $sth->execute($invoiceid); >+ my $res = $sth->fetchrow_arrayref; >+ if ( $res && $res->[0] == 0 ) { >+ $query = qq{ >+ DELETE FROM aqinvoices >+ WHERE invoiceid = ? >+ }; >+ my $sth = $dbh->prepare($query); >+ return ( $sth->execute($invoiceid) > 0 ); >+ } >+ return; >+} >+ > 1; > __END__ > >diff --git a/acqui/invoice.pl b/acqui/invoice.pl >index 1b6d97c..e38e02d 100755 >--- a/acqui/invoice.pl >+++ b/acqui/invoice.pl >@@ -86,6 +86,14 @@ elsif ( $op && $op eq 'mod' ) { > } > $template->param( modified => 1 ); > } >+elsif ( $op && $op eq 'delete' ) { >+ DelInvoice($invoiceid); >+ my $referer = $input->param('referer') || 'invoices.pl'; >+ if ($referer) { >+ print $input->redirect($referer); >+ exit 0; >+ } >+} > > my $details = GetInvoiceDetails($invoiceid); > my $bookseller = GetBookSellerFromId( $details->{booksellerid} ); >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >index 96df8d1..1ce4cd8 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoice.tt >@@ -84,6 +84,9 @@ > </fieldset> > <fieldset class="action"> > <input type="submit" value="Save" /> >+ [% UNLESS orders_loop.size %] >+ <a href="invoice.pl?op=delete&invoiceid=[% invoiceid %]">Delete</a> >+ [% END %] > </fieldset> > </form> > <p> >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt >index 52d2ecc..16c1b61 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/invoices.tt >@@ -80,6 +80,9 @@ $(document).ready(function() { > [% ELSE %] > <a href="invoice.pl?op=close&invoiceid=[% invoice.invoiceid %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Close</a> > [% END %] >+ [% UNLESS invoice.receivedbiblios || invoice.receiveditems %] >+ / <a href="invoice.pl?op=delete&invoiceid=[% invoice.invoiceid %]&referer=/cgi-bin/koha/acqui/invoices.pl%3Fop=do_search%26invoicenumber=[% invoicenumber %]%26supplier=[% booksellerid %]%26billingdatefrom=[% billingdatefrom %]%26billingdateto=[% billingdateto %]%26isbneanissn=[% isbneanissn %]%26title=[% title %]%26author=[% author %]%26publisher=[% publisher %]%26publicationyear=[% publicationyear %]%26branch=[% branch %]">Delete</a> >+ [% END %] > </td> > </tr> > [% END %] >diff --git a/t/Acquisition/Invoice.t b/t/Acquisition/Invoice.t >index a887965..0a37f44 100755 >--- a/t/Acquisition/Invoice.t >+++ b/t/Acquisition/Invoice.t >@@ -3,7 +3,7 @@ > use Modern::Perl; > use C4::Context; > >-use Test::More tests => 47; >+use Test::More tests => 49; > use Test::MockModule; > > use_ok('C4::Acquisition'); >@@ -129,3 +129,24 @@ is(scalar(@$history), 1); > @bound_params = @{ $history->[0]->{bound_params} }; > is(scalar(@bound_params), 1); > is($bound_params[0], 42); >+my $checkordersrs = [ >+ [qw(COUNT)], >+ [2] >+]; >+ >+$dbh->{mock_add_resultset} = $checkordersrs; >+is(DelInvoice(42), undef, "Invoices with items don't get deleted"); >+ >+$checkordersrs = [ >+ [qw(COUNT)], >+ [0] >+]; >+ >+my $deleters = [ >+ [qw(COUNT)], >+ [1] >+]; >+ >+$dbh->{mock_add_resultset} = $checkordersrs; >+$dbh->{mock_add_resultset} = $deleters; >+ok(DelInvoice(42), "Invoices with items do get deleted"); >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 10390
:
18590
|
18596
| 19036