[open-ils-commits] [GIT] Evergreen ILS branch master updated. 5c3d3e36c186e94367b5659755043e7c67d22099

Evergreen Git git at git.evergreen-ils.org
Thu Feb 18 11:54:06 EST 2016


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Evergreen ILS".

The branch, master has been updated
       via  5c3d3e36c186e94367b5659755043e7c67d22099 (commit)
       via  136b6b146483ecaa00b846eadcbc9383a28c2e9e (commit)
       via  9f8444fd8e2bbc339bf77533d29e8332665fcba6 (commit)
       via  81804c9e733b02dcfad7aa91c0b26747512b7c5b (commit)
       via  94ec1e175985be989f64ecbb24bfa3f78e97a023 (commit)
      from  258c8c7b5e23c8b7fdb21d8c62920cd97840ccf1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 5c3d3e36c186e94367b5659755043e7c67d22099
Author: Kathy Lussier <klussier at masslnc.org>
Date:   Thu Feb 18 11:50:56 2016 -0500

    LP#1380709 Renaming live-t test to avoid duplicate numbers
    
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/src/perlmods/live_t/12-acq-invoicing.t b/Open-ILS/src/perlmods/live_t/13-acq-invoicing.t
similarity index 100%
rename from Open-ILS/src/perlmods/live_t/12-acq-invoicing.t
rename to Open-ILS/src/perlmods/live_t/13-acq-invoicing.t

commit 136b6b146483ecaa00b846eadcbc9383a28c2e9e
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Jan 4 11:20:27 2016 -0500

    LP#1380709 Perl live test
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/src/perlmods/live_t/12-acq-invoicing.t b/Open-ILS/src/perlmods/live_t/12-acq-invoicing.t
new file mode 100644
index 0000000..1df01fa
--- /dev/null
+++ b/Open-ILS/src/perlmods/live_t/12-acq-invoicing.t
@@ -0,0 +1,67 @@
+#!perl
+use strict; use warnings;
+use Test::More tests => 4;
+use OpenILS::Utils::TestUtils;
+use OpenILS::Utils::CStoreEditor qw/:funcs/;
+
+diag("Tests ACQ invoices");
+
+my $script = OpenILS::Utils::TestUtils->new();
+$script->bootstrap;
+
+my $e = new_editor();
+$e->init;
+
+$script->authenticate({
+    username => 'admin',
+    password => 'demo123',
+    type => 'staff'
+});
+
+ok($script->authtoken, 'Have an authtoken');
+
+my $invoice = Fieldmapper::acq::invoice->new;
+$invoice->isnew(1);
+$invoice->receiver(1);
+$invoice->provider(1);
+$invoice->shipper(1);
+$invoice->inv_ident(rand());
+$invoice->complete('f');
+
+my $entry = Fieldmapper::acq::invoice_entry->new;
+$entry->isnew(1);
+$entry->lineitem(3);
+$entry->purchase_order(2);
+$entry->inv_item_count(1);
+$entry->phys_item_count(1);
+$entry->cost_billed('25.00');
+$entry->actual_cost('25.00');
+$entry->amount_paid('25.00');
+
+my $acq_ses = $script->session('open-ils.acq');
+
+my $req = $acq_ses->request(
+    'open-ils.acq.invoice.update', $script->authtoken, $invoice, [$entry]);
+
+$invoice = $req->recv->content;
+
+is(ref $invoice, 'Fieldmapper::acq::invoice', 'Invoice created');
+
+# Close the invoice.  LP#1333254. 
+$invoice->complete('t');
+$invoice->ischanged(1);
+
+$req = $acq_ses->request(
+    'open-ils.acq.invoice.update', $script->authtoken, $invoice);
+
+$invoice = $req->recv->content;
+
+is($invoice->complete, 't', 'Invoice is closed');
+
+$entry = $invoice->entries->[0];
+my $debits = $e->search_acq_fund_debit({id => [1,2]});
+my @matching = grep { ($_->invoice_entry || '') eq $entry->id } @$debits;
+
+isnt(scalar(@matching), 0, 
+    'At least one fund_debit should link to new invoice entry');
+

commit 9f8444fd8e2bbc339bf77533d29e8332665fcba6
Author: Bill Erickson <berickxx at gmail.com>
Date:   Thu Dec 11 14:17:09 2014 -0500

    LP#1380709 acq.lineitem_detail.fund_debit INDEX
    
    Use of the new fund_debit.invoice_entry column includes a query joining
    fund_debits to lineitem_details.  On sufficiently large data sets
    (tested on 2M rows), the query can take > 1 second without the index.
    Down to < 1ms with the index.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Jennifer Pringle <jennifer.pringle at bc.libraries.coop>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql
index 3df7e85..309e80f 100644
--- a/Open-ILS/src/sql/Pg/200.schema.acq.sql
+++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql
@@ -541,6 +541,7 @@ CREATE TABLE acq.lineitem_detail (
 );
 
 CREATE INDEX li_detail_li_idx ON acq.lineitem_detail (lineitem);
+CREATE INDEX lineitem_detail_fund_debit_idx ON acq.lineitem_detail (fund_debit);
 
 CREATE TABLE acq.lineitem_attr_definition (
 	id		BIGSERIAL	PRIMARY KEY,
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
index 7575ef9..48560e4 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
@@ -8,5 +8,6 @@ ALTER TABLE acq.fund_debit
         ON DELETE SET NULL;
 
 CREATE INDEX fund_debit_invoice_entry_idx ON acq.fund_debit (invoice_entry);
+CREATE INDEX lineitem_detail_fund_debit_idx ON acq.lineitem_detail (fund_debit);
 
 COMMIT;

commit 81804c9e733b02dcfad7aa91c0b26747512b7c5b
Author: Bill Erickson <berickxx at gmail.com>
Date:   Mon Dec 8 10:34:26 2014 -0500

    LP#1380709 fund_debit.invoice_entry INDEX
    
    Adds index on new acq.fund_debit.invoice_entry column, since fund_debit
    can get quite large.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Jennifer Pringle <jennifer.pringle at bc.libraries.coop>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql
index ac780c5..3df7e85 100644
--- a/Open-ILS/src/sql/Pg/200.schema.acq.sql
+++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql
@@ -857,6 +857,8 @@ ALTER TABLE acq.fund_debit
         REFERENCES acq.invoice_entry (id)
         ON DELETE SET NULL;
 
+CREATE INDEX fund_debit_invoice_entry_idx ON acq.fund_debit (invoice_entry);
+
 CREATE TABLE acq.invoice_item_type (
     code    TEXT    PRIMARY KEY,
     name    TEXT    NOT NULL,  -- i18n-ize
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
index aca7918..7575ef9 100644
--- a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
@@ -7,4 +7,6 @@ ALTER TABLE acq.fund_debit
         REFERENCES acq.invoice_entry (id)
         ON DELETE SET NULL;
 
+CREATE INDEX fund_debit_invoice_entry_idx ON acq.fund_debit (invoice_entry);
+
 COMMIT;

commit 94ec1e175985be989f64ecbb24bfa3f78e97a023
Author: Bill Erickson <berickxx at gmail.com>
Date:   Thu Oct 16 16:17:16 2014 -0400

    LP#1380709 Fund debit links to invoice entry
    
    Fund debits created by lineitem_details (copies) now track which invoice
    entry last touched the fund debit.  With this, it's possible to say with
    certainty which invoice a fund_debit "belongs" to, which is particularly
    useful for reporting fund summary information on an invoice.
    
    Note this has no affect fund_debit's linked to invoice_item's, since
    they already link to the fund debits.
    
    Signed-off-by: Bill Erickson <berickxx at gmail.com>
    Signed-off-by: Jennifer Pringle <jennifer.pringle at bc.libraries.coop>
    Signed-off-by: Kathy Lussier <klussier at masslnc.org>

diff --git a/Open-ILS/examples/fm_IDL.xml b/Open-ILS/examples/fm_IDL.xml
index 421b967..85b485f 100644
--- a/Open-ILS/examples/fm_IDL.xml
+++ b/Open-ILS/examples/fm_IDL.xml
@@ -7935,10 +7935,12 @@ SELECT  usr,
 			<field reporter:label="Encumbrance" name="encumbrance" reporter:datatype="bool" />
 			<field reporter:label="Debit Type" name="debit_type" reporter:datatype="text" />
 			<field reporter:label="Create Time" name="create_time" reporter:datatype="timestamp" />
+			<field reporter:label="Invoice Entry" name="invoice_entry" reporter:datatype="link" />
 		</fields>
 		<links>
 			<link field="fund" reltype="has_a" key="id" map="" class="acqf"/>
 			<link field="origin_currency_type" reltype="has_a" key="code" map="" class="acqct"/>
+			<link field="invoice_entry" reltype="has_a" key="id" map="" class="acqie"/>
 		</links>
 		<permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
 			<actions>
diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Invoice.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Invoice.pm
index 3980e62..95071bb 100644
--- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Invoice.pm
+++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Invoice.pm
@@ -287,6 +287,10 @@ sub rollback_entry_debits {
         # revert to the original estimated amount re-encumber
         $debit->encumbrance('t');
         $debit->amount($lineitem->estimated_unit_price());
+
+        # debit is no longer "invoiced"; detach it from the entry;
+        $debit->clear_invoice_entry;
+
         $e->update_acq_fund_debit($debit) or return $e->die_event;
         update_copy_cost($e, $debit) or return $e->die_event; # clear the cost
     }
@@ -312,6 +316,11 @@ sub update_entry_debits {
         my $amount = entry_amount_per_item($entry);
         $debit->amount($amount);
         $debit->encumbrance('f');
+
+        # debit always reports the invoice_entry responsible
+        # for its most recent modification.
+        $debit->invoice_entry($entry->id);
+
         $e->update_acq_fund_debit($debit) or return $e->die_event;
 
         # TODO: this does not reflect ancillary charges, like taxes, etc.
@@ -473,14 +482,30 @@ sub amounts_spent_per_fund {
     return \@totals;
 }
 
-# there is no direct link between invoice_entry and fund debits.
-# when we need to retrieve the related debits, we have to do some searching
+# find fund debits related to an invoice entry.
 sub find_entry_debits {
-    my($e, $entry, $encumbrance, $amount) = @_;
+    my($e, $entry, $encumbrance, $amount, $fallback) = @_;
 
     my $query = {
         select => {acqfdeb => ['id']},
-        from => {
+        # sort received items to the front
+        order_by => {'acqlid' => ['recv_time']}
+    };
+
+    if ($encumbrance eq 'f' and !$fallback) { # previously invoiced
+
+        # Debits which have been invoiced (encumbrance = f) will have a 
+        # link to the last entry which affected them
+
+        $query->{from} = {acqfdeb => 'acqlid'};
+        $query->{where} = {'+acqfdeb' => {invoice_entry => $entry->id}};
+
+    } else {
+
+        # For un-invoiced (or $fallback) debits, search for those 
+        # that are linked to the entry via the lineitem.
+
+        $query->{from} = {
             acqfdeb => {
                 acqlid => {
                     join => {
@@ -494,17 +519,34 @@ sub find_entry_debits {
                     }
                 }
             }
-        },
-        where => {'+acqfdeb' => {encumbrance => $encumbrance}},
-        order_by => {'acqlid' => ['recv_time']}, # un-received items will sort to the end
-        limit => $entry->phys_item_count
-    };
+        };
+
+        $query->{limit} = $entry->phys_item_count;
+        $query->{where} = {'+acqfdeb' => {encumbrance => $encumbrance}};
+    }
 
     $query->{where}->{'+acqfdeb'}->{amount} = $amount if $amount;
 
     my $debits = $e->json_query($query);
     my $debit_ids = [map { $_->{id} } @$debits];
-    return (@$debit_ids) ? $e->search_acq_fund_debit({id => $debit_ids}) : [];
+
+    if (!@$debit_ids) { # no debits found
+
+        # if a lookup for previously invoiced debits (encumbrance=f) 
+        # returns zero results, it may be becuase the debits were
+        # created before the presence of the acq.fund_debit.invoice_entry
+        # column.  Attempt to use the old-style lookup for these debits
+        # using the "$fallback" flag.
+        if (!$fallback and $encumbrance eq 'f') {
+            $logger->info(
+                "invoice: using debit fallback lookup for entry ".$entry->id);
+            return find_entry_debits($e, $entry, $encumbrance, $amount, 1);
+        }
+
+        return [];
+    }
+
+    return $e->search_acq_fund_debit({id => $debit_ids});
 }
 
 
diff --git a/Open-ILS/src/sql/Pg/200.schema.acq.sql b/Open-ILS/src/sql/Pg/200.schema.acq.sql
index 0359ed7..ac780c5 100644
--- a/Open-ILS/src/sql/Pg/200.schema.acq.sql
+++ b/Open-ILS/src/sql/Pg/200.schema.acq.sql
@@ -852,6 +852,11 @@ CREATE INDEX ie_inv_idx on acq.invoice_entry (invoice);
 CREATE INDEX ie_po_idx on acq.invoice_entry (purchase_order);
 CREATE INDEX ie_li_idx on acq.invoice_entry (lineitem);
 
+ALTER TABLE acq.fund_debit 
+    ADD COLUMN invoice_entry INTEGER 
+        REFERENCES acq.invoice_entry (id)
+        ON DELETE SET NULL;
+
 CREATE TABLE acq.invoice_item_type (
     code    TEXT    PRIMARY KEY,
     name    TEXT    NOT NULL,  -- i18n-ize
diff --git a/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
new file mode 100644
index 0000000..aca7918
--- /dev/null
+++ b/Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql
@@ -0,0 +1,10 @@
+BEGIN;
+
+-- SELECT evergreen.upgrade_deps_block_check('XXXX', :eg_version);
+
+ALTER TABLE acq.fund_debit 
+    ADD COLUMN invoice_entry INTEGER 
+        REFERENCES acq.invoice_entry (id)
+        ON DELETE SET NULL;
+
+COMMIT;

-----------------------------------------------------------------------

Summary of changes:
 Open-ILS/examples/fm_IDL.xml                       |    2 +
 .../lib/OpenILS/Application/Acq/Invoice.pm         |   62 +++++++++++++++---
 Open-ILS/src/perlmods/live_t/13-acq-invoicing.t    |   67 ++++++++++++++++++++
 Open-ILS/src/sql/Pg/200.schema.acq.sql             |    8 +++
 .../XXXX.schema.fund_debit_invoice_links.sql       |   13 ++++
 5 files changed, 142 insertions(+), 10 deletions(-)
 create mode 100644 Open-ILS/src/perlmods/live_t/13-acq-invoicing.t
 create mode 100644 Open-ILS/src/sql/Pg/upgrade/XXXX.schema.fund_debit_invoice_links.sql


hooks/post-receive
-- 
Evergreen ILS


More information about the open-ils-commits mailing list