From: G. Richardson Date: Mon, 8 Aug 2016 09:04:29 +0000 (+0200) Subject: Sortiment - Test für Sortimentsartikel X-Git-Tag: release-3.5.4~1889 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=5b6df6e8f5b2993c1606d1db4163ec9d9134a13f;p=kivitendo-erp.git Sortiment - Test für Sortimentsartikel --- diff --git a/t/part/assortment.t b/t/part/assortment.t new file mode 100644 index 000000000..0aea44784 --- /dev/null +++ b/t/part/assortment.t @@ -0,0 +1,67 @@ +use strict; +use Test::More; + +use lib 't'; +use Support::TestSetup; +use Carp; +use Test::Exception; +use SL::DB::Unit; +use SL::DB::Part; +use Data::Dumper; + +Support::TestSetup::login(); + +clear_up(); +reset_state(); + +is( SL::DB::Manager::Part->get_all_count(), 3, "total number of parts created is 3"); + +my $assortment = SL::DB::Manager::Part->find_by( partnumber => 'as1' ); + +is( $assortment->part_type, 'assortment', 'assortment has correct part_type'); +is( scalar @{$assortment->assortment_items}, 2, 'assortment has two parts' ); + +my $assortment_item = $assortment->assortment_items->[0]; +is( $assortment_item->assortment->partnumber, 'as1', "assortment_item links back to correct assortment"); + +clear_up(); +done_testing; + +sub reset_state { + my %params = @_; + + my ($part1, $part2, $unit); + + # SL::DB::Manager::AssortmentItem->delete_all(all => 1); + # SL::DB::Manager::Part->delete_all(all => 1); + my ($part1, $part2, $unit, $assortment_part, $assortment_1, $assortment_2); + + my $unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "Can't find unit 'Stck'"; + $part1 = SL::DB::Part->new_part( partnumber => '7777', + description => "assortment part 1", + unit => $unit->name, + sellprice => '3.33', + )->save; + $part2 = $part1->clone_and_reset($part1); + $part2->partnumber( $part1->partnumber + 1 ); + $part2->description( "assortment part 2" ); + $part2->save; + + my $assortment_part = SL::DB::Part->new_assortment( partnumber => 'as1', + description => 'assortment', + sellprice => '0', + unit => $unit->name); + my $assortment_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1); + my $assortment_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2); + $assortment_part->add_assortment_items($assortment_1, $assortment_2); + $assortment_part->save or die "Couldn't save assortment"; + +}; + +sub clear_up { + SL::DB::Manager::AssortmentItem->delete_all(all => 1); + SL::DB::Manager::Part->delete_all( all => 1); +}; + + +1;