Test für Erzeugnisse per Rose erstellen erweitert
authorG. Richardson <information@kivitendo-premium.de>
Thu, 28 Jul 2016 13:29:22 +0000 (15:29 +0200)
committerG. Richardson <information@kivitendo-premium.de>
Thu, 28 Jul 2016 13:29:22 +0000 (15:29 +0200)
t/part/assembly.t

index 302cffd..f6241c4 100644 (file)
@@ -13,12 +13,21 @@ Support::TestSetup::login();
 clear_up();
 reset_state();
 
-is( SL::DB::Manager::Part->get_all_count(), 3,  "total number of parts created is 2");
+is( SL::DB::Manager::Part->get_all_count(), 3,  "total number of parts created is 3");
 
-my $assembly = SL::DB::Manager::Part->find_by( partnumber => 'as1' );
+my $assembly_part      = SL::DB::Manager::Part->find_by( partnumber => 'as1' );
+my $assembly_item_part = SL::DB::Manager::Part->find_by( partnumber => '19000' );
 
-is($assembly->type, 'assembly', 'assembly has correct type');
-is( scalar @{$assembly->assemblies}, 2, 'assembly consists of two parts' );
+is($assembly_part->inventory_accno_id, undef, "assembly doesn't have an inventory accno id");
+
+is($assembly_part->type, 'assembly', 'assembly has correct type');
+is( scalar @{$assembly_part->assemblies}, 2, 'assembly consists of two parts' );
+
+# fetch assembly item corresponding to partnumber 19000
+my $assembly_items = $assembly_part->find_assemblies( { parts_id => $assembly_item_part->id } ) || die "can't find assembly_item";
+my $assembly_item = $assembly_items->[0];
+is($assembly_item->part->partnumber, '19000', 'assembly part part relation works');
+is($assembly_item->assembly_part->partnumber, 'as1', 'assembly part assembly part relation works');
 
 clear_up();
 done_testing;
@@ -42,11 +51,12 @@ sub reset_state {
   $part2->partnumber($part1->partnumber + 1);
   $part2->save;
 
-  my $assembly_part = SL::DB::Part->new_assembly(partnumber  => 'as1',
-                                                 description => 'assembly',
-                                                 unit        => $unit->name,
+  my $assembly_part = SL::DB::Part->new_assembly(partnumber         => 'as1',
+                                                 description        => 'assembly',
+                                                 unit               => $unit->name,
+                                                 inventory_accno_id => undef, # override
                                                 );
-  my $assembly_1 = SL::DB::Assembly->new(parts_id => $part2->id, qty => 3, bom => 1);
+  my $assembly_1 = SL::DB::Assembly->new(parts_id => $part1->id, qty => 3, bom => 1);
   my $assembly_2 = SL::DB::Assembly->new(parts_id => $part2->id, qty => 3, bom => 1);
   $assembly_part->add_assemblies($assembly_1, $assembly_2);
   $assembly_part->save;