|
Lines 32-49
my $builder = t::lib::TestBuilder->new;
Link Here
|
| 32 |
subtest 'order_line() tests' => sub { |
32 |
subtest 'order_line() tests' => sub { |
| 33 |
# TODO: Split up order_line() to smaller methods in order |
33 |
# TODO: Split up order_line() to smaller methods in order |
| 34 |
# to allow better testing |
34 |
# to allow better testing |
| 35 |
plan tests => 2; |
35 |
plan tests => 24; |
| 36 |
|
36 |
|
| 37 |
$schema->storage->txn_begin; |
37 |
$schema->storage->txn_begin; |
| 38 |
|
38 |
|
| 39 |
my $biblio = $builder->build_sample_biblio(); |
39 |
my $biblio = $builder->build_sample_biblio(); |
|
|
40 |
my $biblioitem = $biblio->biblioitem; |
| 41 |
$biblioitem->update({ isbn => '979-8572072303' }); |
| 42 |
my $biblioitem_itype = $biblioitem->itemtype; |
| 43 |
|
| 44 |
my $item1 = $builder->build_sample_item( |
| 45 |
{ |
| 46 |
biblionumber => $biblio->biblionumber, |
| 47 |
location => 'PROCESSING', |
| 48 |
itemcallnumber => '000.101' |
| 49 |
} |
| 50 |
); |
| 51 |
my $item1_homebranch = $item1->homebranch; |
| 52 |
my $item1_itype = $item1->effective_itemtype; |
| 53 |
my $item2 = $builder->build_sample_item( |
| 54 |
{ |
| 55 |
biblionumber => $biblio->biblionumber, |
| 56 |
location => 'PROCESSING', |
| 57 |
itemcallnumber => '000.102' |
| 58 |
} |
| 59 |
); |
| 60 |
my $item2_homebranch = $item2->homebranch; |
| 61 |
my $item2_itype = $item2->effective_itemtype; |
| 62 |
|
| 40 |
my $ean = $builder->build( { source => 'EdifactEan' } ); |
63 |
my $ean = $builder->build( { source => 'EdifactEan' } ); |
| 41 |
my $order = $builder->build_object( |
64 |
my $dbic_ean = $schema->resultset('EdifactEan')->find($ean->{ee_id}); |
|
|
65 |
my $order = $builder->build_object( |
| 42 |
{ |
66 |
{ |
| 43 |
class => 'Koha::Acquisition::Orders', |
67 |
class => 'Koha::Acquisition::Orders', |
| 44 |
value => { biblionumber => $biblio->biblionumber } |
68 |
value => { |
|
|
69 |
biblionumber => $biblio->biblionumber, |
| 70 |
quantity => 2, |
| 71 |
line_item_id => 'EDILINEID1', |
| 72 |
order_vendornote => 'A not so pretty note', |
| 73 |
listprice => '1.50' |
| 74 |
} |
| 45 |
} |
75 |
} |
| 46 |
); |
76 |
); |
|
|
77 |
my $ordernumber = $order->ordernumber; |
| 78 |
my $supplier_qualifier = $order->suppliers_reference_qualifier; |
| 79 |
my $supplier_ordernumber = $order->suppliers_reference_number; |
| 80 |
my $budgetcode = $order->fund->budget_code; |
| 81 |
my $deliveryplace = $order->basket->deliveryplace; |
| 82 |
$order->add_item($item1->itemnumber); |
| 83 |
$order->add_item($item2->itemnumber); |
| 47 |
|
84 |
|
| 48 |
my $vendor = $builder->build( |
85 |
my $vendor = $builder->build( |
| 49 |
{ |
86 |
{ |
|
Lines 53-58
subtest 'order_line() tests' => sub {
Link Here
|
| 53 |
} |
90 |
} |
| 54 |
} |
91 |
} |
| 55 |
); |
92 |
); |
|
|
93 |
my $dbic_vendor = $schema->resultset('VendorEdiAccount')->find($vendor->{id}); |
| 56 |
|
94 |
|
| 57 |
my @orders = $schema->resultset('Aqorder') |
95 |
my @orders = $schema->resultset('Aqorder') |
| 58 |
->search( { basketno => $order->basket->basketno } )->all; |
96 |
->search( { basketno => $order->basket->basketno } )->all; |
|
Lines 60-79
subtest 'order_line() tests' => sub {
Link Here
|
| 60 |
my $edi_order = Koha::Edifact::Order->new( |
98 |
my $edi_order = Koha::Edifact::Order->new( |
| 61 |
{ |
99 |
{ |
| 62 |
orderlines => \@orders, |
100 |
orderlines => \@orders, |
| 63 |
vendor => $vendor, |
101 |
vendor => $dbic_vendor, |
| 64 |
ean => $ean |
102 |
ean => $dbic_ean |
| 65 |
} |
103 |
} |
| 66 |
); |
104 |
); |
| 67 |
|
105 |
|
| 68 |
$order->basket->create_items('ordering')->store; |
106 |
# FIXME: Add test for an order where the attached biblio has been deleted. |
| 69 |
|
107 |
|
|
|
108 |
$order->basket->create_items('ordering')->store; |
| 70 |
is( $edi_order->order_line( 1, $orders[0] ), |
109 |
is( $edi_order->order_line( 1, $orders[0] ), |
| 71 |
undef, 'Orderline message formed with with "ordering"' ); |
110 |
undef, 'order_line run for message formed with effective_create_items = "ordering"' ); |
|
|
111 |
|
| 112 |
my $segs = $edi_order->{segs}; |
| 113 |
is( $segs->[0], 'LIN+1++EDILINEID1:EN\'', 'LIN segment added containing order->line_item_id' ); |
| 114 |
is( $segs->[1], 'PIA+5+8572072303:IB\'', 'PIA segment added with example biblioitem->isbn13' ); |
| 115 |
is( $segs->[2], 'IMD+L+009+:::Some boring author\'', 'IMD segment added containing demo data author' ); |
| 116 |
is( $segs->[3], 'IMD+L+050+:::Some boring read\'', 'IMD segment added containing demo data title' ); |
| 117 |
is( $segs->[4], 'QTY+21:2\'', 'QTY segement added containing the number of items expected' ); |
| 118 |
is( |
| 119 |
$segs->[5], |
| 120 |
'GIR+001' |
| 121 |
. "+$budgetcode:LFN" |
| 122 |
. "+$item1_homebranch:LLO" |
| 123 |
. "+$item1_itype:LST" |
| 124 |
. "+PROCESSING:LSQ" |
| 125 |
. "+000.101:LSM" |
| 126 |
. "'", |
| 127 |
'GIR segment added for first item and contains item record data' |
| 128 |
); |
| 129 |
is( |
| 130 |
$segs->[6], |
| 131 |
'GIR+002' |
| 132 |
. "+$budgetcode:LFN" |
| 133 |
. "+$item2_homebranch:LLO" |
| 134 |
. "+$item2_itype:LST" |
| 135 |
. "+PROCESSING:LSQ" |
| 136 |
. "+000.102:LSM" |
| 137 |
. "'", |
| 138 |
'GIR segment added for second item and contains item record data' |
| 139 |
); |
| 140 |
is( $segs->[7], 'FTX+LIN+++A not so pretty note\'', 'FTX segment added containing data from vendor_note' ); |
| 141 |
is( $segs->[8], 'PRI+AAE:1.50:CA\'', 'PRI segment added containing data orderline listprice' ); |
| 142 |
is( $segs->[9], "RFF+LI:$ordernumber'", 'RFF segment added containing koha orderline id' ); |
| 143 |
is( $segs->[10], "RFF+$supplier_qualifier:$supplier_ordernumber'", 'RFF segment added containing supplier orderline id' ); |
| 144 |
|
| 145 |
# Reset segments for effective_create_items = 'receiving' |
| 146 |
$edi_order->{segs} = []; |
| 72 |
|
147 |
|
| 73 |
$order->basket->create_items('receiving')->store; |
148 |
$order->basket->create_items('receiving')->store; |
| 74 |
|
|
|
| 75 |
is( $edi_order->order_line( 1, $orders[0] ), |
149 |
is( $edi_order->order_line( 1, $orders[0] ), |
| 76 |
undef, 'Orderline message formed with "receiving"' ); |
150 |
undef, 'order_line run for message formed with effective_create_items = "receiving"' ); |
|
|
151 |
|
| 152 |
$segs = $edi_order->{segs}; |
| 153 |
is( $segs->[0], 'LIN+1++EDILINEID1:EN\'', 'LIN segment added containing order->line_item_id' ); |
| 154 |
is( $segs->[1], 'PIA+5+8572072303:IB\'', 'PIA segment added with example biblioitem->isbn13' ); |
| 155 |
is( $segs->[2], 'IMD+L+009+:::Some boring author\'', 'IMD segment added containing demo data author' ); |
| 156 |
is( $segs->[3], 'IMD+L+050+:::Some boring read\'', 'IMD segment added containing demo data title' ); |
| 157 |
is( $segs->[4], 'QTY+21:2\'', 'QTY segement added containing the number of items expected' ); |
| 158 |
is( |
| 159 |
$segs->[5], |
| 160 |
'GIR+001' |
| 161 |
. "+$budgetcode:LFN" |
| 162 |
. "+$deliveryplace:LLO" |
| 163 |
. "+$biblioitem_itype:LST" |
| 164 |
. "'", |
| 165 |
'GIR segment added for first item and contains biblioitem data' |
| 166 |
); |
| 167 |
is( |
| 168 |
$segs->[6], |
| 169 |
'GIR+002' |
| 170 |
. "+$budgetcode:LFN" |
| 171 |
. "+$deliveryplace:LLO" |
| 172 |
. "+$biblioitem_itype:LST" |
| 173 |
. "'", |
| 174 |
'GIR segment added for second item and contains biblioitem data' |
| 175 |
); |
| 176 |
is( $segs->[7], 'FTX+LIN+++A not so pretty note\'', 'FTX segment added containing data from vendor_note' ); |
| 177 |
is( $segs->[8], 'PRI+AAE:1.50:CA\'', 'PRI segment added containing data orderline listprice' ); |
| 178 |
is( $segs->[9], "RFF+LI:$ordernumber'", 'RFF segment added containing koha orderline id' ); |
| 179 |
is( $segs->[10], "RFF+$supplier_qualifier:$supplier_ordernumber'", 'RFF segment added containing supplier orderline id' ); |
| 77 |
|
180 |
|
| 78 |
$schema->storage->txn_rollback; |
181 |
$schema->storage->txn_rollback; |
| 79 |
}; |
182 |
}; |
| 80 |
- |
|
|