Revision 35777fef
Von Kivitendo Admin vor etwa 8 Jahren hinzugefügt
t/part/assembly.t | ||
---|---|---|
7 | 7 |
use SL::DB::Unit; |
8 | 8 |
use SL::DB::Part; |
9 | 9 |
use SL::DB::Assembly; |
10 |
use SL::Dev::Part; |
|
10 | 11 |
|
11 | 12 |
Support::TestSetup::login(); |
12 | 13 |
|
13 | 14 |
clear_up(); |
14 | 15 |
reset_state(); |
15 | 16 |
|
16 |
is( SL::DB::Manager::Part->get_all_count(), 3, "total number of parts created is 3");
|
|
17 |
is( SL::DB::Manager::Part->get_all_count(), 4, "total number of parts created is 4");
|
|
17 | 18 |
|
18 |
my $assembly_part = SL::DB::Manager::Part->find_by( partnumber => 'as1' );
|
|
19 |
my $assembly_item_part = SL::DB::Manager::Part->find_by( partnumber => '19000' );
|
|
19 |
my $assembly_part = SL::DB::Manager::Part->find_by( partnumber => '19000' ) || die "Can't find part 19000";
|
|
20 |
my $assembly_item_part = SL::DB::Manager::Part->find_by( partnumber => 'ap1' );
|
|
20 | 21 |
|
21 | 22 |
is($assembly_part->part_type, 'assembly', 'assembly has correct type'); |
22 |
is( scalar @{$assembly_part->assemblies}, 2, 'assembly consists of two parts' );
|
|
23 |
is( scalar @{$assembly_part->assemblies}, 3, 'assembly consists of two parts' );
|
|
23 | 24 |
|
24 | 25 |
# fetch assembly item corresponding to partnumber 19000 |
25 | 26 |
my $assembly_items = $assembly_part->find_assemblies( { parts_id => $assembly_item_part->id } ) || die "can't find assembly_item"; |
26 | 27 |
my $assembly_item = $assembly_items->[0]; |
27 |
is($assembly_item->part->partnumber, '19000', 'assembly part part relation works');
|
|
28 |
is($assembly_item->assembly_part->partnumber, 'as1', 'assembly part assembly part relation works');
|
|
28 |
is($assembly_item->part->partnumber, 'ap1', 'assembly part part relation works');
|
|
29 |
is($assembly_item->assembly_part->partnumber, '19000', 'assembly part assembly part relation works');
|
|
29 | 30 |
|
30 | 31 |
clear_up(); |
31 | 32 |
done_testing; |
... | ... | |
38 | 39 |
sub reset_state { |
39 | 40 |
my %params = @_; |
40 | 41 |
|
41 |
# create an assembly that consists of two parts |
|
42 |
my ($part1, $part2, $unit, $assembly_part, $assembly_1, $assembly_2); |
|
43 |
$unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "Can't find unit 'Stck'"; |
|
44 |
|
|
45 |
$part1 = SL::DB::Part->new_part(partnumber => '19000', |
|
46 |
unit => $unit->name, |
|
47 |
part_type => 'part', |
|
48 |
)->save; |
|
49 |
$part2 = $part1->clone_and_reset($part1); |
|
50 |
$part2->partnumber($part1->partnumber + 1); |
|
51 |
$part2->save; |
|
52 |
|
|
53 |
$assembly_part = SL::DB::Part->new_assembly(partnumber => 'as1', |
|
54 |
description => 'assembly', |
|
55 |
unit => $unit->name, |
|
56 |
); |
|
57 |
$assembly_1 = SL::DB::Assembly->new(parts_id => $part1->id, qty => 3, bom => 1); |
|
58 |
$assembly_2 = SL::DB::Assembly->new(parts_id => $part2->id, qty => 3, bom => 1); |
|
59 |
$assembly_part->add_assemblies($assembly_1, $assembly_2); |
|
60 |
$assembly_part->save; |
|
42 |
my $assembly = SL::Dev::Part::create_assembly( partnumber => '19000' )->save; |
|
61 | 43 |
}; |
62 | 44 |
|
63 | 45 |
1; |
t/part/assortment.t | ||
---|---|---|
5 | 5 |
use Support::TestSetup; |
6 | 6 |
use Carp; |
7 | 7 |
use Test::Exception; |
8 |
use SL::DB::Unit; |
|
9 | 8 |
use SL::DB::Part; |
10 |
use Data::Dumper;
|
|
9 |
use SL::Dev::Part;
|
|
11 | 10 |
|
12 | 11 |
Support::TestSetup::login(); |
13 | 12 |
|
14 | 13 |
clear_up(); |
15 |
reset_state(); |
|
16 | 14 |
|
17 |
is( SL::DB::Manager::Part->get_all_count(), 3, "total number of parts created is 3"); |
|
15 |
my $assortment = SL::Dev::Part::create_assortment( partnumber => 'aso1', |
|
16 |
description => "Assortment 1", |
|
17 |
number_of_parts => 10, |
|
18 |
)->save; |
|
18 | 19 |
|
19 |
my $assortment = SL::DB::Manager::Part->find_by( partnumber => 'as1' ); |
|
20 |
is( SL::DB::Manager::Part->get_all_count(), 11, "total number of parts created is 11"); |
|
21 |
|
|
22 |
my $assortment = SL::DB::Manager::Part->find_by( partnumber => 'aso1' ) or die "Can't find assortment with partnumber aso1"; |
|
20 | 23 |
|
21 | 24 |
is($assortment->part_type, 'assortment', 'assortment has correct part_type'); |
22 |
is(scalar @{$assortment->assortment_items}, 2, 'assortment has two parts');
|
|
23 |
is($assortment->items_sellprice_sum, 19.98, 'assortment sellprice sum ok');
|
|
24 |
is($assortment->items_lastcost_sum, 13.32, 'assortment lastcost sum ok');
|
|
25 |
is(scalar @{$assortment->assortment_items}, 10, 'assortment has 10 parts');
|
|
26 |
is($assortment->items_sellprice_sum, 100, 'assortment sellprice sum ok');
|
|
27 |
is($assortment->items_lastcost_sum, 50, 'assortment lastcost sum ok');
|
|
25 | 28 |
|
26 | 29 |
my $assortment_item = $assortment->assortment_items->[0]; |
27 |
is( $assortment_item->assortment->partnumber, 'as1', "assortment_item links back to correct assortment"); |
|
30 |
is( $assortment_item->assortment->partnumber, 'aso1', "assortment_item links back to correct assortment");
|
|
28 | 31 |
|
29 | 32 |
clear_up(); |
30 | 33 |
done_testing; |
31 | 34 |
|
32 |
sub reset_state { |
|
33 |
my %params = @_; |
|
34 |
|
|
35 |
# SL::DB::Manager::AssortmentItem->delete_all(all => 1); |
|
36 |
# SL::DB::Manager::Part->delete_all(all => 1); |
|
37 |
my ($part1, $part2, $unit, $assortment_part, $assortment_1, $assortment_2); |
|
38 |
|
|
39 |
$unit = SL::DB::Manager::Unit->find_by(name => 'Stck') || die "Can't find unit 'Stck'"; |
|
40 |
$part1 = SL::DB::Part->new_part( partnumber => '7777', |
|
41 |
description => "assortment part 1", |
|
42 |
unit => $unit->name, |
|
43 |
sellprice => '3.33', |
|
44 |
lastcost => '2.22', |
|
45 |
)->save; |
|
46 |
$part2 = $part1->clone_and_reset($part1); |
|
47 |
$part2->partnumber( $part1->partnumber + 1 ); |
|
48 |
$part2->description( "assortment part 2" ); |
|
49 |
$part2->save; |
|
50 |
|
|
51 |
$assortment_part = SL::DB::Part->new_assortment( partnumber => 'as1', |
|
52 |
description => 'assortment', |
|
53 |
sellprice => '0', |
|
54 |
unit => $unit->name); |
|
55 |
$assortment_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1); |
|
56 |
$assortment_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2); |
|
57 |
$assortment_part->add_assortment_items($assortment_1, $assortment_2); |
|
58 |
$assortment_part->save or die "Couldn't save assortment"; |
|
59 |
|
|
60 |
}; |
|
61 |
|
|
62 | 35 |
sub clear_up { |
63 | 36 |
SL::DB::Manager::AssortmentItem->delete_all(all => 1); |
64 | 37 |
SL::DB::Manager::Part->delete_all( all => 1); |
Auch abrufbar als: Unified diff
Assortment und Assembly Tests nutzen SL::Dev::Part