Skip to content

Commit

Permalink
Add PO number to sort1 as the basket name
Browse files Browse the repository at this point in the history
  • Loading branch information
mblenk committed Sep 7, 2023
1 parent 06d0c82 commit d750d4a
Showing 1 changed file with 34 additions and 25 deletions.
59 changes: 34 additions & 25 deletions Koha/MarcOrder.pm
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,6 @@ sub create_order_lines_from_file {

my $vendor_record = Koha::Acquisition::Booksellers->find({ id => $vendor_id });

my $basket_id = _create_basket_for_file({
filename => $filename,
vendor_id => $vendor_id
});

my $format = index($filename, '.mrc') != -1 ? 'ISO2709' : 'MARCXML';
my $params = {
record_type => $profile->record_type,
Expand All @@ -116,6 +111,13 @@ sub create_order_lines_from_file {
import_batch_id => $import_batch_id,
});

my ( $basket_id, $marc_fields_to_order ) = _create_basket_for_file(
{
vendor_id => $vendor_id,
import_records => $import_records
}
);

while( my $import_record = $import_records->next ){
my $result = add_biblios_from_import_record({
import_batch_id => $import_batch_id,
Expand All @@ -128,11 +130,12 @@ sub create_order_lines_from_file {
next if $result->{skip};

my $order_line_details = add_items_from_import_record({
record_result => $result->{record_result},
basket_id => $basket_id,
vendor => $vendor_record,
budget_id => $budget_id,
agent => $agent,
record_result => $result->{record_result},
vendor => $vendor_record,
basket_id => $basket_id,
budget_id => $budget_id,
agent => $agent,
marc_fields_to_order => $marc_fields_to_order
});

my $order_lines = create_order_lines({
Expand Down Expand Up @@ -210,7 +213,7 @@ sub import_record_and_create_order_lines {
=head3 _create_basket_for_file
my $basket_id = _create_basket_for_file({
filename => $filename,
import_records => $import_records,
vendor_id => $vendor_id
});
Expand All @@ -221,8 +224,14 @@ sub import_record_and_create_order_lines {
sub _create_basket_for_file {
my ( $args ) = @_;

my $filename = $args->{filename};
my $vendor_id = $args->{vendor_id};
my $vendor_id = $args->{vendor_id};
my @import_records = $args->{import_records}->as_list;
my $marcrecord = $import_records[0]->get_marc_record;
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data(
'MarcFieldsToOrder', $marcrecord,
[ 'price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2' ]
);
my $filename = $marc_fields_to_order->{sort1};

# aqbasketname.basketname has a max length of 50 characters so long file names will need to be truncated
my $basketname = length($filename) > 50 ? substr( $filename, 0, 50 ): $filename;
Expand All @@ -231,7 +240,7 @@ sub _create_basket_for_file {
NewBasket( $vendor_id, 0, $basketname, q{},
q{} . q{} );

return $basketno;
return ( $basketno, $marc_fields_to_order );
}

=head3 _stage_file
Expand Down Expand Up @@ -563,19 +572,19 @@ sub add_biblios_from_import_record {
sub add_items_from_import_record {
my ( $args ) = @_;

my $record_result = $args->{record_result};
my $basket_id = $args->{basket_id};
my $budget_id = $args->{budget_id};
my $vendor = $args->{vendor};
my $agent = $args->{agent};
my $client_item_fields = $args->{client_item_fields} || undef;
my $active_currency = Koha::Acquisition::Currencies->get_active;
my $biblionumber = $record_result->{biblionumber};
my $marcrecord = $record_result->{marcrecord};
my $record_result = $args->{record_result};
my $budget_id = $args->{budget_id};
my $basket_id = $args->{basket_id};
my $vendor = $args->{vendor};
my $agent = $args->{agent};
my $client_item_fields = $args->{client_item_fields} || undef;
my $active_currency = Koha::Acquisition::Currencies->get_active;
my $biblionumber = $record_result->{biblionumber};
my $marcrecord = $record_result->{marcrecord};
my $marc_fields_to_order = $args->{marc_fields_to_order};
my @order_line_details;

if($agent eq 'cron') {
my $marc_fields_to_order = _get_MarcFieldsToOrder_syspref_data('MarcFieldsToOrder', $marcrecord, ['price', 'quantity', 'budget_code', 'discount', 'sort1', 'sort2']);
my $quantity = $marc_fields_to_order->{quantity};
my $budget_code = $marc_fields_to_order->{budget_code} || $budget_id; # Use fallback from ordering profile if not mapped
my $price = $marc_fields_to_order->{price};
Expand Down Expand Up @@ -643,7 +652,7 @@ sub add_items_from_import_record {
my %order_detail_hash = (
biblionumber => $biblionumber,
basketno => $basket_id,
itemnumbers => ($item->itemnumber),
itemnumbers => ($item->itemnumber),
quantity => 1,
budget_id => $item_budget_id,
currency => $vendor->listprice,
Expand Down

0 comments on commit d750d4a

Please sign in to comment.