From 58e107fbe24035e1f4944f2df975ac91126470af Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 2 Jun 2016 15:27:06 -0400 Subject: [PATCH] LP#1413352 Brief record price sets lineitem price Propagate lineitem MARC 'price' attribute value to the lineitem estimated_unit_price field. This allows users to apply a lineitem price directly from the ACQ Brief Record interface. Signed-off-by: Bill Erickson Signed-off-by: Chris Sharp Signed-off-by: Mike Rylander --- .../lib/OpenILS/Application/Acq/Lineitem.pm | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm index 925fc8593f..af491b6c68 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/Acq/Lineitem.pm @@ -65,6 +65,12 @@ sub create_lineitem { $li->selector($e->requestor->id); $li = $e->create_acq_lineitem($li) or return $e->die_event; + # if no price is set, see if it can be extracted from the price attribute. + if (not defined $li->estimated_unit_price) { # '0' is valid + my $evt = set_li_price_from_attr($e, $li); + return $evt if $evt; + } + if ($po) { # apply the default number of copies for this provider for (1 .. $po->provider->default_copy_count) { @@ -79,6 +85,35 @@ sub create_lineitem { return $li->id; } +# See if we have a value for the price attribute. If so, apply the price +# value to the lineitem. +# Returns undef on success, Event on error. +sub set_li_price_from_attr { + my ($e, $li) = @_; + + my $attr = $e->search_acq_lineitem_attr({ + lineitem => $li->id, + attr_type => 'lineitem_marc_attr_definition', + attr_name => 'price' + })->[0]; + + return unless $attr; + + my $val = $attr->attr_value; + + return unless defined $val; # '0' is valid + + $li->estimated_unit_price($val); + + if (!$e->update_acq_lineitem($li)) { + $e->rollback; + return OpenILS::Event->new('BAD_PARAMS', + desc => "Invalid lineitem price value: '$val'") ; + } + + return undef; +} + __PACKAGE__->register_method( method => 'retrieve_lineitem', -- 2.11.0