Revision 26e34663
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/Controller/DeliveryOrder.pm | ||
---|---|---|
108 | 108 |
my $order = SL::DB::Order->new(id => $self->{converted_from_oe_id})->load; |
109 | 109 |
|
110 | 110 |
my $target_type = $::form->{type}; |
111 |
my $delivery_order = SL::Model::Record->new_from_workflow($order, ref($self->order), $target_type);
|
|
111 |
my $delivery_order = SL::Model::Record->new_from_workflow($order, $target_type); |
|
112 | 112 |
$self->order($delivery_order); |
113 | 113 |
|
114 | 114 |
$self->action_add; |
... | ... | |
120 | 120 |
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load; |
121 | 121 |
my $target_type = $reclamation->is_sales ? 'rma_delivery_order' |
122 | 122 |
: 'supplier_delivery_order'; |
123 |
my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, ref($self->order), $target_type);
|
|
123 |
my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, $target_type); |
|
124 | 124 |
$self->{converted_from_reclamation_id} = $::form->{from_id}; |
125 | 125 |
$self->order($delivery_order); |
126 | 126 |
|
... | ... | |
185 | 185 |
my @multi_orders = map { SL::DB::DeliveryOrder->new(id => $_)->load } @multi_ids; |
186 | 186 |
$self->{converted_from_oe_id} = join ' ', map { $_->id } @multi_orders; |
187 | 187 |
my $target_type = SALES_DELIVERY_ORDER_TYPE(); |
188 |
my $delivery_order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, ref($self->order), $target_type, sort_sources_by => 'transdate');
|
|
188 |
my $delivery_order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, $target_type, sort_sources_by => 'transdate'); |
|
189 | 189 |
$self->order($delivery_order); |
190 | 190 |
|
191 | 191 |
$self->action_edit(); |
... | ... | |
1617 | 1617 |
# always save |
1618 | 1618 |
$self->save(); |
1619 | 1619 |
|
1620 |
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, ref($self->order), $destination_type);
|
|
1620 |
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, $destination_type); |
|
1621 | 1621 |
$self->order($delivery_order); |
1622 | 1622 |
$self->{converted_from_oe_id} = delete $::form->{id}; |
1623 | 1623 |
|
... | ... | |
1653 | 1653 |
# always save |
1654 | 1654 |
$self->save(); |
1655 | 1655 |
|
1656 |
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, ref($self->order), $destination_type);
|
|
1656 |
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, $destination_type); |
|
1657 | 1657 |
$self->order($delivery_order); |
1658 | 1658 |
$self->{converted_from_oe_id} = delete $::form->{id}; |
1659 | 1659 |
|
SL/Controller/Order.pm | ||
---|---|---|
103 | 103 |
my %params; |
104 | 104 |
my $target_type = $reclamation->is_sales ? SALES_ORDER_TYPE() |
105 | 105 |
: PURCHASE_ORDER_TYPE(); |
106 |
my $order = SL::Model::Record->new_from_workflow($reclamation, 'SL::DB::Order', ref($self->order), $target_type);
|
|
106 |
my $order = SL::Model::Record->new_from_workflow($reclamation, $target_type); |
|
107 | 107 |
|
108 | 108 |
$self->{converted_from_reclamation_id} = $order->{ RECORD_ID() }; |
109 | 109 |
$_ ->{converted_from_reclamation_items_id} = $_ ->{ RECORD_ITEM_ID() } for @{ $order->items_sorted }; |
... | ... | |
190 | 190 |
my @multi_orders = map { SL::DB::Order->new(id => $_)->load } @multi_ids; |
191 | 191 |
$self->{converted_from_oe_id} = join ' ', map { $_->id } @multi_orders; |
192 | 192 |
my $target_type = "sales_order"; |
193 |
my $order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, ref($self->order), $target_type, sort_sources_by => 'transdate');
|
|
193 |
my $order = SL::Model::Record->new_from_workflow_multi(\@multi_orders, $target_type, sort_sources_by => 'transdate'); |
|
194 | 194 |
$self->order($order); |
195 | 195 |
|
196 | 196 |
$self->action_edit(); |
... | ... | |
882 | 882 |
my $no_linked_records = (any { $destination_type eq $_ } (SALES_QUOTATION_TYPE(), REQUEST_QUOTATION_TYPE())) |
883 | 883 |
&& $from_side eq $to_side; |
884 | 884 |
|
885 |
$self->order(SL::Model::Record->new_from_workflow($self->order, 'SL::DB::Order', $destination_type, no_linked_records => $no_linked_records));
|
|
885 |
$self->order(SL::Model::Record->new_from_workflow($self->order, $destination_type, no_linked_records => $no_linked_records)); |
|
886 | 886 |
|
887 | 887 |
delete $::form->{id}; |
888 | 888 |
|
SL/Controller/Reclamation.pm | ||
---|---|---|
125 | 125 |
} |
126 | 126 |
|
127 | 127 |
my $order = SL::DB::Order->new(id => $::form->{from_id})->load; |
128 |
my $reclamation = SL::Model::Record->new_from_workflow($order, ref($self->reclamation), $self->type);
|
|
128 |
my $reclamation = SL::Model::Record->new_from_workflow($order, $self->type); |
|
129 | 129 |
|
130 | 130 |
$self->reclamation($reclamation); |
131 | 131 |
|
... | ... | |
151 | 151 |
} |
152 | 152 |
|
153 | 153 |
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load; |
154 |
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, ref($self->reclamaiton), $self->type);
|
|
154 |
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $self->type); |
|
155 | 155 |
|
156 | 156 |
$self->reclamation($reclamation); |
157 | 157 |
|
... | ... | |
177 | 177 |
} |
178 | 178 |
|
179 | 179 |
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load; |
180 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, ref($self->reclamaiton), $self->type);
|
|
180 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $self->type); |
|
181 | 181 |
|
182 | 182 |
$self->reclamation($reclamation); |
183 | 183 |
|
SL/Model/Record.pm | ||
---|---|---|
16 | 16 |
use SL::DB::Order::TypeData qw(:types); |
17 | 17 |
use SL::DB::DeliveryOrder::TypeData qw(:types); |
18 | 18 |
use SL::DB::Reclamation::TypeData qw(:types); |
19 |
use SL::DB::Helper::Record qw(get_class_from_type); |
|
19 | 20 |
|
20 | 21 |
use SL::Util qw(trim); |
21 | 22 |
use SL::Locale::String qw(t8); |
... | ... | |
60 | 61 |
} |
61 | 62 |
|
62 | 63 |
sub new_from_workflow { |
63 |
my ($class, $source_object, $target_type, $target_subtype, %flags) = @_;
|
|
64 |
my ($class, $source_object, $target_type, %flags) = @_; |
|
64 | 65 |
|
65 |
$flags{destination_type} = $target_subtype;
|
|
66 |
$flags{destination_type} = $target_type; |
|
66 | 67 |
my %defaults_flags = ( |
67 | 68 |
no_linked_records => 0, |
68 | 69 |
); |
69 | 70 |
%flags = (%defaults_flags, %flags); |
70 | 71 |
|
71 |
my $target_object = ${target_type}->new_from($source_object, %flags); |
|
72 |
my $target_class = get_class_from_type($target_type); |
|
73 |
my $target_object = ${target_class}->new_from($source_object, %flags); |
|
72 | 74 |
return $target_object; |
73 | 75 |
} |
74 | 76 |
|
75 | 77 |
sub new_from_workflow_multi { |
76 |
my ($class, $source_objects, $target_type, $target_subtype, %flags) = @_;
|
|
78 |
my ($class, $source_objects, $target_type, %flags) = @_; |
|
77 | 79 |
|
78 |
my $target_object = ${target_type}->new_from_multi($source_objects, %flags); |
|
80 |
my $target_class = get_class_from_type($target_type); |
|
81 |
my $target_object = ${target_class}->new_from_multi($source_objects, %flags); |
|
79 | 82 |
|
80 | 83 |
return $target_object; |
81 | 84 |
} |
... | ... | |
250 | 253 |
$new_attrs{employee} = SL::DB::Manager::Employee->current; |
251 | 254 |
|
252 | 255 |
|
253 |
my $new_record = SL::Model::Record->new_from_workflow($changed_record, ref($changed_record), $saved_record->type, no_linked_records => 1, attributes => \%new_attrs);
|
|
256 |
my $new_record = SL::Model::Record->new_from_workflow($changed_record, $saved_record->type, no_linked_records => 1, attributes => \%new_attrs); |
|
254 | 257 |
|
255 | 258 |
return $new_record; |
256 | 259 |
} |
... | ... | |
271 | 274 |
This module contains shared behaviour among the main record object types. A given record needs to be already parsed into a Rose object. |
272 | 275 |
All records are treated agnostically and the underlying class needs to implement a type_data call to query for differing behaviour. |
273 | 276 |
|
274 |
Currently the following types and subtypes are supported:
|
|
277 |
Currently the following classes and types are supported:
|
|
275 | 278 |
|
276 | 279 |
=over 4 |
277 | 280 |
|
... | ... | |
345 | 348 |
|
346 | 349 |
=item C<new_from_workflow> |
347 | 350 |
|
348 |
Expects source_object, target_type, target_subtype and can have flags.
|
|
349 |
Creates a new record from a target_subtype by target_type->new_from(source_record).
|
|
351 |
Expects source_object, target_type and can have flags. |
|
352 |
Creates a new record from a by target_class->new_from(source_record).
|
|
350 | 353 |
Set default flag no_link_record to false. |
351 | 354 |
|
352 | 355 |
Throws an error if the target_type doesn't exist. |
... | ... | |
355 | 358 |
|
356 | 359 |
=item C<new_from_workflow_multi> |
357 | 360 |
|
358 |
Expects an arrayref with source_objects, target_type, target_subtype and can have flags.
|
|
361 |
Expects an arrayref with source_objects, target_type and can have flags. |
|
359 | 362 |
Creates a new record object from one or more source objects. |
360 | 363 |
|
361 | 364 |
Returns the new record object. |
t/model/records.t | ||
---|---|---|
84 | 84 |
|
85 | 85 |
|
86 | 86 |
note "testing new_from_workflow for quotation"; |
87 |
foreach my $pair ( pairs @{['SL::DB::Order' => 'sales_order', 'SL::DB::DeliveryOrder' => 'sales_delivery_order']} ) {
|
|
87 |
foreach my $target_record_type (qw(sales_order sales_delivery_order)) {
|
|
88 | 88 |
# TODO: invoice |
89 |
my ($target_record_type, $target_record_subtype) = @$pair; |
|
90 |
note " testing from quotation -> $target_record_subtype"; |
|
91 |
my $new_record = SL::Model::Record->new_from_workflow($sales_quotation1, $target_record_type, $target_record_subtype); |
|
89 |
note " testing from quotation -> $target_record_type"; |
|
90 |
my $new_record = SL::Model::Record->new_from_workflow($sales_quotation1, $target_record_type); |
|
92 | 91 |
|
93 | 92 |
is($new_record->closed, 0, "new quotation is open"); |
94 | 93 |
# in the future closing sales quotations should probably happen as an after-save hook of orders, |
... | ... | |
96 | 95 |
SL::Model::Record->save($new_record, objects_to_close => [ $sales_quotation1 ]); |
97 | 96 |
|
98 | 97 |
$new_record->load; |
99 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_subtype netamount ok") if $new_record->can('netamount');
|
|
98 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount'); |
|
100 | 99 |
|
101 | 100 |
# test whether quotations get closed when sales_order is created |
102 |
if ( $target_record_subtype eq 'sales_order' ) {
|
|
101 |
if ( $target_record_type eq 'sales_order' ) { |
|
103 | 102 |
$sales_quotation1->load; |
104 | 103 |
is($sales_quotation1->closed, 1, "quotation is closed after creating an order"); |
105 | 104 |
} |
... | ... | |
108 | 107 |
|
109 | 108 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, addition => 'SAVED'); |
110 | 109 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
111 |
test_record_links($new_record, "converted $target_record_subtype");
|
|
110 |
test_record_links($new_record, "converted $target_record_type"); |
|
112 | 111 |
}; |
113 | 112 |
|
114 | 113 |
note "testing new_from_workflow for order"; |
115 |
foreach my $pair (pairs @{['SL::DB::DeliveryOrder' => 'sales_delivery_order', 'SL::DB::Reclamation' => 'sales_reclamation']}) {
|
|
114 |
foreach my $target_record_type (qw(sales_delivery_order sales_reclamation)) {
|
|
116 | 115 |
# TODO: invoice |
117 |
my ($target_record_type, $target_record_subtype) = @$pair; |
|
118 |
note " testing from quotation -> $target_record_subtype"; |
|
119 |
my $new_record = SL::Model::Record->new_from_workflow($sales_order1, $target_record_type, $target_record_subtype); |
|
116 |
note " testing from quotation -> $target_record_type"; |
|
117 |
my $new_record = SL::Model::Record->new_from_workflow($sales_order1, $target_record_type); |
|
120 | 118 |
if ( 'SL::DB::Reclamation' eq ref($new_record) ) { |
121 | 119 |
$_->reason($reclamation_reason) foreach @{ $new_record->items }; |
122 | 120 |
}; |
123 | 121 |
SL::Model::Record->save($new_record); |
124 | 122 |
$new_record->load; |
125 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, what_done => $target_record_subtype, addition => 'SAVED');
|
|
123 |
my $record_history = SL::DB::Manager::History->find_by(trans_id => $new_record->id, what_done => $target_record_type, addition => 'SAVED'); |
|
126 | 124 |
|
127 | 125 |
ok($record_history->snumbers =~ m/_/, "history snumbers of record " . $record_history->snumbers . " ok"); |
128 | 126 |
|
129 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_subtype netamount ok") if $new_record->can('netamount');
|
|
130 |
test_record_links($new_record, "converted $target_record_subtype");
|
|
127 |
cmp_ok($new_record->netamount, '==', 710, "converted $target_record_type netamount ok") if $new_record->can('netamount'); |
|
128 |
test_record_links($new_record, "converted $target_record_type"); |
|
131 | 129 |
}; |
132 | 130 |
|
133 | 131 |
note ('testing multi'); |
... | ... | |
137 | 135 |
|
138 | 136 |
note('combining several sales orders to one combined order'); |
139 | 137 |
my @sales_orders; |
140 |
push(@sales_orders, SL::Model::Record->new_from_workflow($sales_quotation1, 'SL::DB::Order', 'sales_order')->save->load) for 1 .. 3;
|
|
141 |
my $combined_order = SL::Model::Record->new_from_workflow_multi(\@sales_orders, 'SL::DB::Order','sales_order', sort_sources_by => 'transdate');
|
|
138 |
push(@sales_orders, SL::Model::Record->new_from_workflow($sales_quotation1, 'sales_order')->save->load) for 1 .. 3; |
|
139 |
my $combined_order = SL::Model::Record->new_from_workflow_multi(\@sales_orders, sort_sources_by => 'transdate'); |
|
142 | 140 |
SL::Model::Record->save($combined_order); |
143 | 141 |
cmp_ok($combined_order->netamount, '==', 3*710, "netamount of combined order ok"); |
144 | 142 |
|
t/workflow/delivery_order_reclamation.t | ||
---|---|---|
182 | 182 |
)->load; |
183 | 183 |
|
184 | 184 |
# convert order → reclamation |
185 |
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_delivery_order, 'SL::DB::Reclamation', 'sales_reclamation');
|
|
185 |
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_delivery_order, 'sales_reclamation'); |
|
186 | 186 |
$converted_sales_reclamation->items_sorted->[0]->reason($reclamation_reason); |
187 | 187 |
$converted_sales_reclamation->items_sorted->[1]->reason($reclamation_reason); |
188 | 188 |
$converted_sales_reclamation->save->load; |
189 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_delivery_order, 'SL::DB::Reclamation', 'purchase_reclamation');
|
|
189 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_delivery_order, 'purchase_reclamation'); |
|
190 | 190 |
$converted_purchase_reclamation->items_sorted->[0]->reason($reclamation_reason); |
191 | 191 |
$converted_purchase_reclamation->items_sorted->[1]->reason($reclamation_reason); |
192 | 192 |
$converted_purchase_reclamation->save->load; |
193 | 193 |
|
194 | 194 |
# convert reclamation → order |
195 |
my $converted_sales_delivery_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::DeliveryOrder', 'rma_delivery_order')->save->load;
|
|
196 |
my $converted_purchase_delivery_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::DeliveryOrder', 'supplier_delivery_order')->save->load;
|
|
195 |
my $converted_sales_delivery_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'rma_delivery_order')->save->load; |
|
196 |
my $converted_purchase_delivery_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'supplier_delivery_order')->save->load; |
|
197 | 197 |
|
198 | 198 |
|
199 | 199 |
#get items before strip |
t/workflow/invoice_to_reclamation.t | ||
---|---|---|
182 | 182 |
)->load; |
183 | 183 |
|
184 | 184 |
# convert invoice → reclamation |
185 |
my $converted_sales_reclamation =SL::Model::Record->new_from_workflow($sales_invoice, 'SL::DB::Reclamation', "sales_reclamation");
|
|
185 |
my $converted_sales_reclamation =SL::Model::Record->new_from_workflow($sales_invoice, "sales_reclamation"); |
|
186 | 186 |
$converted_sales_reclamation->items_sorted->[0]->reason($reclamation_reason); |
187 | 187 |
$converted_sales_reclamation->items_sorted->[1]->reason($reclamation_reason); |
188 | 188 |
$converted_sales_reclamation->save->load; |
189 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_invoice, 'SL::DB::Reclamation', "purchase_reclamation");
|
|
189 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_invoice, "purchase_reclamation"); |
|
190 | 190 |
$converted_purchase_reclamation->items_sorted->[0]->reason($reclamation_reason); |
191 | 191 |
$converted_purchase_reclamation->items_sorted->[1]->reason($reclamation_reason); |
192 | 192 |
$converted_purchase_reclamation->save->load; |
t/workflow/order_reclamation.t | ||
---|---|---|
182 | 182 |
)->load; |
183 | 183 |
|
184 | 184 |
# convert order → reclamation |
185 |
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_order, 'SL::DB::Reclamation', "sales_reclamation");
|
|
185 |
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($sales_order, "sales_reclamation"); |
|
186 | 186 |
$converted_sales_reclamation->items_sorted->[0]->reason($reclamation_reason); |
187 | 187 |
$converted_sales_reclamation->items_sorted->[1]->reason($reclamation_reason); |
188 | 188 |
$converted_sales_reclamation->save->load; |
189 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_order, 'SL::DB::Reclamation', "purchase_reclamation");
|
|
189 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_order, "purchase_reclamation"); |
|
190 | 190 |
$converted_purchase_reclamation->items_sorted->[0]->reason($reclamation_reason); |
191 | 191 |
$converted_purchase_reclamation->items_sorted->[1]->reason($reclamation_reason); |
192 | 192 |
$converted_purchase_reclamation->save->load; |
193 | 193 |
|
194 | 194 |
# convert reclamation → order |
195 |
my $converted_sales_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::Order', 'sales_order')->save->load;
|
|
196 |
my $converted_purchase_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::Order', 'purchase_order')->save->load;
|
|
195 |
my $converted_sales_order = SL::Model::Record->new_from_workflow($sales_reclamation, 'sales_order')->save->load; |
|
196 |
my $converted_purchase_order = SL::Model::Record->new_from_workflow($purchase_reclamation, 'purchase_order')->save->load; |
|
197 | 197 |
|
198 | 198 |
|
199 | 199 |
#get items before strip |
t/workflow/reclamation_reclamation.t | ||
---|---|---|
153 | 153 |
|
154 | 154 |
# new |
155 | 155 |
my $new_sales_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::Reclamation', 'sales_reclamation')->save->load; |
156 |
my $new_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::Reclamation', 'purchase_reclamation')->save->load;
|
|
156 |
my $new_purchase_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'purchase_reclamation')->save->load; |
|
157 | 157 |
|
158 | 158 |
# convert |
159 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'SL::DB::Reclamation', 'purchase_reclamation');
|
|
159 |
my $converted_purchase_reclamation = SL::Model::Record->new_from_workflow($sales_reclamation, 'purchase_reclamation'); |
|
160 | 160 |
$converted_purchase_reclamation->vendor_id($purchase_reclamation->{vendor_id}); |
161 | 161 |
$converted_purchase_reclamation->save->load; |
162 |
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'SL::DB::Reclamation', 'sales_reclamation');
|
|
162 |
my $converted_sales_reclamation = SL::Model::Record->new_from_workflow($purchase_reclamation, 'sales_reclamation'); |
|
163 | 163 |
$converted_sales_reclamation->customer_id($sales_reclamation->{customer_id}); |
164 | 164 |
$converted_sales_reclamation->save->load; |
165 | 165 |
|
Auch abrufbar als: Unified diff
Model::Record: Funktionsaufruf angepasst für new_from_worklow ...
und new_from_workflow_multi