Revision 8bfef5b2
Von Tamino Steinert vor etwa 2 Jahren hinzugefügt
SL/DB/Reclamation.pm | ||
---|---|---|
55 | 55 |
__PACKAGE__->before_save('_before_save_set_record_number'); |
56 | 56 |
__PACKAGE__->before_save('_before_save_remove_empty_custom_shipto'); |
57 | 57 |
__PACKAGE__->before_save('_before_save_set_custom_shipto_module'); |
58 |
__PACKAGE__->after_save('_after_save_link_records'); |
|
58 | 59 |
|
59 | 60 |
# hooks |
60 | 61 |
|
... | ... | |
82 | 83 |
return 1; |
83 | 84 |
} |
84 | 85 |
|
86 |
sub _after_save_link_records { |
|
87 |
my ($self) = @_; |
|
88 |
my %allowed_linked_records = map {$_ => 1} qw( |
|
89 |
SL::DB::Reclamation |
|
90 |
SL::DB::Order |
|
91 |
SL::DB::DeliveryOrder |
|
92 |
SL::DB::Invoice |
|
93 |
SL::DB::PurchaseInvoice |
|
94 |
); |
|
95 |
my %allowed_linked_record_items = map {$_ => 1} qw( |
|
96 |
SL::DB::ReclamationItem |
|
97 |
SL::DB::OrderItem |
|
98 |
SL::DB::DeliveryOrderItem |
|
99 |
SL::DB::InvoiceItem |
|
100 |
); |
|
101 |
|
|
102 |
my $from_record_id = $self->{converted_from_record_id}; |
|
103 |
if ($from_record_id) { |
|
104 |
my $from_record_type = $self->{converted_from_record_type_ref}; |
|
105 |
unless ($allowed_linked_records{$from_record_type}) { |
|
106 |
croak("Not allowed converted_from_record_type_ref: '" . $from_record_type); |
|
107 |
} |
|
108 |
my $src = ${from_record_type}->new(id => $from_record_id)->load; |
|
109 |
$src->link_to_record($self); |
|
110 |
#clear converted_from; |
|
111 |
delete $self->{$_} for qw(converted_from_record_id converted_from_record_type_ref); |
|
112 |
|
|
113 |
if (scalar @{ $self->items_sorted || [] }) { |
|
114 |
for my $idx (0 .. $#{ $self->items_sorted }) { |
|
115 |
my $reclamation_item = $self->items_sorted->[$idx]; |
|
116 |
my $from_item_id = $reclamation_item->{converted_from_record_item_id}; |
|
117 |
next if !$from_item_id; |
|
118 |
my $from_item_type = $reclamation_item->{converted_from_record_item_type_ref}; |
|
119 |
unless ($allowed_linked_record_items{$from_item_type}) { |
|
120 |
croak("Not allowed converted_from_record_item_type_ref: '" . $from_item_type); |
|
121 |
} |
|
122 |
my $src_item = ${from_item_type}->new(id => $from_item_id)->load; |
|
123 |
$src_item->link_to_record($reclamation_item); |
|
124 |
#clear converted_from; |
|
125 |
delete $reclamation_item->{$_} for qw(converted_from_record_item_id converted_from_record_item_type_ref); |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
return 1; |
|
131 |
} |
|
132 |
|
|
85 | 133 |
# methods |
86 | 134 |
|
87 | 135 |
sub items { goto &reclamation_items; } |
Auch abrufbar als: Unified diff
Reclamation: set record_links automatic after reclamation->save