-use Test::More tests => 49;
+use Test::More tests => 66;
use strict;
use Data::Dumper;
use Support::TestSetup;
use Test::Exception;
+use Test::Deep qw(cmp_bag);
use List::Util qw(max);
use SL::DB::Buchungsgruppe;
use SL::DB::Invoice;
use SL::DB::Order;
use SL::DB::DeliveryOrder;
+use SL::DB::DeliveryOrder::TypeData qw(:types);
use SL::DB::Part;
use SL::DB::Unit;
use SL::DB::TaxZone;
my ($customer, $currency_id, $buchungsgruppe, $employee, $vendor, $taxzone);
my ($link, $links, $o1, $o2, $d, $i);
-sub reset_state {
- my %params = @_;
-
- $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax);
-
+sub clear_up {
SL::DB::Manager::DeliveryOrder->delete_all(all => 1);
SL::DB::Manager::Order->delete_all(all => 1);
SL::DB::Manager::Invoice->delete_all(all => 1);
+ SL::DB::Manager::Part->delete_all(all => 1);
SL::DB::Manager::Customer->delete_all(all => 1);
SL::DB::Manager::Vendor->delete_all(all => 1);
+};
+
+sub reset_state {
+ my %params = @_;
+
+ $params{$_} ||= {} for qw(buchungsgruppe unit customer part tax);
+
+ clear_up();
$buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group";
$employee = SL::DB::Manager::Employee->current || croak "No employee";
$customer = SL::DB::Customer->new(
name => 'Test Customer',
currency_id => $currency_id,
+ taxzone_id => $taxzone->id,
%{ $params{customer} }
)->save;
$vendor = SL::DB::Vendor->new(
name => 'Test Vendor',
currency_id => $currency_id,
+ taxzone_id => $taxzone->id,
%{ $params{vendor} }
)->save;
}
employee_id => $employee->id,
salesman_id => $employee->id,
taxzone_id => $taxzone->id,
+ order_type => SALES_DELIVERY_ORDER_TYPE,
%params,
)->save;
}
reset_state();
-
$o1 = new_order();
$i = new_invoice();
$links = $o1->linked_records(direction => 'both', recursive => 1, save_path => 1);
is @$links, 4, 'recursive dir=both does not give duplicates';
+
+
+# test batch mode
+#
+#
+#
+
+reset_state();
+
+$o1 = new_order();
+$o2 = new_order();
+my $i1 = new_invoice();
+my $i2 = new_invoice();
+
+$o1->link_to_record($i1);
+$o2->link_to_record($i2);
+
+$links = $o1->linked_records(direction => 'to', to => 'Invoice', batch => [ $o1->id, $o2->id ]);
+is_deeply [ map { $_->id } @$links ], [ $i1->id , $i2->id ], "batch works";
+
+$links = $o1->linked_records(direction => 'to', recursive => 1, batch => [ $o1->id, $o2->id ]);
+cmp_bag [ map { $_->id } @$links ], [ $i1->id , $i2->id ], "batch works recursive";
+
+$links = $o1->linked_records(direction => 'to', to => 'Invoice', batch => [ $o1->id, $o2->id ], by_id => 1);
+# $::lxdebug->dump(0, "links", $links);
+is @{ $links->{$o1->id} }, 1, "batch by_id 1";
+is @{ $links->{$o2->id} }, 1, "batch by_id 2";
+is keys %$links, 2, "batch by_id 3";
+is $links->{$o1->id}[0]->id, $i1->id, "batch by_id 4";
+is $links->{$o2->id}[0]->id, $i2->id, "batch by_id 5";
+
+$links = $o1->linked_records(direction => 'to', recursive => 1, batch => [ $o1->id, $o2->id ], by_id => 1);
+is @{ $links->{$o1->id} }, 1, "batch recursive by_id 1";
+is @{ $links->{$o2->id} }, 1, "batch recursive by_id 2";
+is keys %$links, 2, "batch recursive by_id 3";
+is $links->{$o1->id}[0]->id, $i1->id, "batch recursive by_id 4";
+is $links->{$o2->id}[0]->id, $i2->id, "batch recursive by_id 5";
+
+$links = $o1->linked_records(direction => 'both', recursive => 1, batch => [ $o1->id, $o2->id ], by_id => 1);
+is @{ $links->{$o1->id} }, 1, "batch recursive by_id direction both 1";
+is @{ $links->{$o2->id} }, 1, "batch recursive by_id direction both 2";
+is keys %$links, 2, "batch recursive by_id direction both 3";
+is $links->{$o1->id}[0]->id, $i1->id, "batch recursive by_id direction both 4";
+is $links->{$o2->id}[0]->id, $i2->id, "batch recursive by_id direction both 5";
+
+clear_up();
+
1;