Revision 5d711a25
Von Martin Helmling martin.helmling@octosoft.eu vor fast 8 Jahren hinzugefügt
t/part/assembly.t | ||
---|---|---|
8 | 8 |
use SL::DB::Part; |
9 | 9 |
use SL::DB::Assembly; |
10 | 10 |
use SL::Dev::Part; |
11 |
use SL::DB::Helper::ValidateAssembly; |
|
11 | 12 |
|
12 | 13 |
Support::TestSetup::login(); |
14 |
$::locale = Locale->new("en"); |
|
13 | 15 |
|
14 | 16 |
clear_up(); |
15 | 17 |
reset_state(); |
... | ... | |
20 | 22 |
my $assembly_item_part = SL::DB::Manager::Part->find_by( partnumber => 'ap1' ); |
21 | 23 |
|
22 | 24 |
is($assembly_part->part_type, 'assembly', 'assembly has correct type'); |
23 |
is( scalar @{$assembly_part->assemblies}, 3, 'assembly consists of two parts' );
|
|
25 |
is( scalar @{$assembly_part->assemblies}, 3, 'assembly consists of three parts' );
|
|
24 | 26 |
|
25 | 27 |
# fetch assembly item corresponding to partnumber 19000 |
26 | 28 |
my $assembly_items = $assembly_part->find_assemblies( { parts_id => $assembly_item_part->id } ) || die "can't find assembly_item"; |
... | ... | |
28 | 30 |
is($assembly_item->part->partnumber, 'ap1', 'assembly part part relation works'); |
29 | 31 |
is($assembly_item->assembly_part->partnumber, '19000', 'assembly part assembly part relation works'); |
30 | 32 |
|
33 |
|
|
34 |
|
|
35 |
my $assembly2_part = SL::Dev::Part::create_assembly( partnumber => '20000', part1number => 'ap2', assnumber => 'as2' )->save; |
|
36 |
my $retval = validate_assembly($assembly_part,$assembly2_part); |
|
37 |
ok( $retval eq undef , 'assembly 19000 can be child of assembly 20000' ); |
|
38 |
$assembly2_part->add_assemblies(SL::DB::Assembly->new(parts_id => $assembly_part->id, qty => 3, bom => 1)); |
|
39 |
$assembly2_part->save; |
|
40 |
|
|
41 |
my $assembly3_part = SL::Dev::Part::create_assembly( partnumber => '30000', part1number => 'ap3', assnumber => 'as3' )->save; |
|
42 |
$retval = validate_assembly($assembly3_part,$assembly_part); |
|
43 |
ok( $retval eq undef , 'assembly 30000 can be child of assembly 19000' ); |
|
44 |
|
|
45 |
$retval = validate_assembly($assembly3_part,$assembly2_part); |
|
46 |
ok( $retval eq undef , 'assembly 30000 can be child of assembly 20000' ); |
|
47 |
|
|
48 |
$assembly_part->add_assemblies(SL::DB::Assembly->new(parts_id => $assembly3_part->id, qty => 4, bom => 1)); |
|
49 |
$assembly_part->save; |
|
50 |
|
|
51 |
$retval = validate_assembly($assembly3_part,$assembly2_part); |
|
52 |
ok( $retval eq undef , 'assembly 30000 can be child of assembly 20000' ); |
|
53 |
|
|
54 |
$assembly2_part->add_assemblies(SL::DB::Assembly->new(parts_id => $assembly3_part->id, qty => 5, bom => 1)); |
|
55 |
$assembly2_part->save; |
|
56 |
|
|
57 |
# fetch assembly item corresponding to partnumber 20000 |
|
58 |
my $assembly2_items = $assembly2_part->find_assemblies() || die "can't find assembly_item"; |
|
59 |
is( scalar @{$assembly2_items}, 5, 'assembly2 consists of four parts' ); |
|
60 |
my $assembly2_item = $assembly2_items->[3]; |
|
61 |
is($assembly2_item->qty, 3, 'count of 3.th assembly is 3' ); |
|
62 |
is($assembly2_item->part->part_type, 'assembly', '3.th assembly \''.$assembly2_item->part->partnumber. '\' is also an assembly'); |
|
63 |
my $assembly3_items = $assembly2_item->part->find_assemblies() || die "can't find assembly_item"; |
|
64 |
is( scalar @{$assembly3_items}, 4, 'assembly3 consists of three parts' ); |
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
# check loop to itself |
|
69 |
$retval = validate_assembly($assembly_part,$assembly_part); |
|
70 |
is( $retval,"The assembly '19000' cannot be a part from itself.", 'assembly loops to itself' ); |
|
71 |
if (!$retval && $assembly_part->add_assemblies( SL::DB::Assembly->new(parts_id => $assembly_part->id, qty => 8, bom => 1))) { |
|
72 |
$assembly_part->save; |
|
73 |
} |
|
74 |
is( scalar @{$assembly_part->assemblies}, 4, 'assembly consists of three parts' ); |
|
75 |
|
|
76 |
# check indirekt loop |
|
77 |
$retval = validate_assembly($assembly2_part,$assembly_part); |
|
78 |
ok( $retval, 'assembly indirect loop' ); |
|
79 |
if (!$retval && $assembly_part->add_assemblies( SL::DB::Assembly->new(parts_id => $assembly2_part->id, qty => 9, bom => 1))) { |
|
80 |
$assembly_part->save; |
|
81 |
} |
|
82 |
is( scalar @{$assembly_part->assemblies}, 4, 'assembly consists of three parts' ); |
|
83 |
|
|
31 | 84 |
clear_up(); |
32 | 85 |
done_testing; |
33 | 86 |
|
Auch abrufbar als: Unified diff
Prüfen der Bestandteile eines Erzeugnisses beim Hinzufügen
Erst Prüfung innerhalb des Erzeugnisses,
dann recursive Prüfung der das Erzeugnis enthaltenen Erzeugnisse,
Abbruch nach 100 Rekursionen.
Die Abfrage ist so, dass nur vom Erzeugnis abwärts der Baum in die Tiefe geprüft wird.
Dabei darf auf einem Graph kein Erzeugnis doppelt vorkommen.
Erzeugnisse sind nun editierbar, wenn sie von einem anderen Erzeugnis verwendet werden
solange sie in keinem ERP-Dokument verwendet werden.
Implementiert in einem Helper für SL::Controller::Part.
Er wird auch im Test t/part/assembly.t verwendet