Revision c131da1a
Von Tamino Steinert vor 3 Monaten hinzugefügt
SL/Controller/Order.pm | ||
---|---|---|
85 | 85 |
sub action_add { |
86 | 86 |
my ($self) = @_; |
87 | 87 |
|
88 |
$self->order(SL::Model::Record->update_after_new($self->order)); |
|
89 |
|
|
90 | 88 |
$self->pre_render(); |
91 | 89 |
|
92 | 90 |
if (!$::form->{form_validity_token}) { |
... | ... | |
121 | 119 |
my $order = SL::Model::Record->new_from_workflow($record, $self->type, %flags); |
122 | 120 |
$self->order($order); |
123 | 121 |
|
124 |
# Warn on order locked items if they are not wanted for this record type |
|
125 |
if ($self->type_data->no_order_locked_parts) { |
|
126 |
my @order_locked_positions = map { $_->position } grep { $_->part->order_locked } @{ $self->order->items_sorted }; |
|
127 |
flash('warning', t8('This record contains not orderable items at position #1', join ', ', @order_locked_positions)) if @order_locked_positions; |
|
128 |
} |
|
129 |
|
|
130 |
$self->recalc(); |
|
131 |
$self->pre_render(); |
|
132 |
|
|
133 |
if (!$::form->{form_validity_token}) { |
|
134 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE())->token; |
|
135 |
} |
|
122 |
$self->reinit_after_new_order(); |
|
136 | 123 |
|
137 |
$self->render( |
|
138 |
'order/form', |
|
139 |
title => $self->type_data->text('add'), |
|
140 |
%{$self->{template_args}} |
|
141 |
); |
|
124 |
$self->action_add(); |
|
142 | 125 |
} |
143 | 126 |
|
144 | 127 |
sub action_add_from_purchase_basket { |
... | ... | |
954 | 937 |
$_ ->{converted_from_orderitems_id} = $_ ->{ RECORD_ITEM_ID() } for @{ $self->order->items_sorted }; |
955 | 938 |
} |
956 | 939 |
|
957 |
# set item ids to new fake id, to identify them as new items |
|
958 |
foreach my $item (@{$self->order->items_sorted}) { |
|
959 |
$item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000); |
|
960 |
} |
|
961 |
|
|
962 | 940 |
if ($from_side eq 'sales' && $to_side eq 'purchase') { |
963 | 941 |
if ($::form->{use_shipto}) { |
964 | 942 |
$self->order->custom_shipto($custom_shipto) if $custom_shipto; |
... | ... | |
968 | 946 |
} |
969 | 947 |
} |
970 | 948 |
|
971 |
# change form type |
|
972 |
$::form->{type} = $destination_type; |
|
973 |
$self->type($self->init_type); |
|
974 |
$self->type_data($self->init_type_data); |
|
975 |
$self->cv ($self->init_cv); |
|
976 |
$self->check_auth; |
|
977 |
|
|
978 |
# Warn on order locked items if they are not wanted for this record type |
|
979 |
if ($self->type_data->no_order_locked_parts) { |
|
980 |
my @order_locked_positions = map { $_->position } grep { $_->part->order_locked } @{ $self->order->items_sorted }; |
|
981 |
flash('warning', t8('This record contains not orderable items at position #1', join ', ', @order_locked_positions)) if @order_locked_positions; |
|
982 |
} |
|
983 |
|
|
984 |
$self->recalc(); |
|
985 |
$self->get_unalterable_data(); |
|
986 |
$self->pre_render(); |
|
949 |
$self->reinit_after_new_order(); |
|
987 | 950 |
|
988 |
# trigger rendering values for second row as hidden, because they |
|
989 |
# are loaded only on demand. So we need to keep the values from the |
|
990 |
# source. |
|
991 |
$_->{render_second_row} = 1 for @{ $self->order->items_sorted }; |
|
992 |
|
|
993 |
if (!$::form->{form_validity_token}) { |
|
994 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE())->token; |
|
995 |
} |
|
996 |
|
|
997 |
$self->render( |
|
998 |
'order/form', |
|
999 |
title => $self->type_data->text('edit'), |
|
1000 |
%{$self->{template_args}} |
|
1001 |
); |
|
951 |
$self->action_add; |
|
1002 | 952 |
} |
1003 | 953 |
|
1004 | 954 |
# set form elements in respect to a changed customer or vendor |
... | ... | |
1337 | 1287 |
sub action_return_from_create_part { |
1338 | 1288 |
my ($self) = @_; |
1339 | 1289 |
|
1340 |
$self->{created_part} = SL::DB::Part->new(id => delete $::form->{new_parts_id})->load if $::form->{new_parts_id}; |
|
1290 |
$self->{created_part} = SL::DB::Part->new( |
|
1291 |
id => delete $::form->{new_parts_id} |
|
1292 |
)->load if $::form->{new_parts_id}; |
|
1341 | 1293 |
|
1342 | 1294 |
$::auth->restore_form_from_session(delete $::form->{previousform}); |
1343 | 1295 |
|
1344 |
# set item ids to new fake id, to identify them as new items |
|
1345 |
foreach my $item (@{$self->order->items_sorted}) { |
|
1346 |
$item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000); |
|
1347 |
} |
|
1348 |
|
|
1349 |
$self->recalc(); |
|
1350 |
$self->get_unalterable_data(); |
|
1351 |
$self->pre_render(); |
|
1296 |
$self->order($self->init_order); |
|
1297 |
$self->reinit_after_new_order(); |
|
1352 | 1298 |
|
1353 |
# trigger rendering values for second row/longdescription as hidden, |
|
1354 |
# because they are loaded only on demand. So we need to keep the values |
|
1355 |
# from the source. |
|
1356 |
$_->{render_second_row} = 1 for @{ $self->order->items_sorted }; |
|
1357 |
$_->{render_longdescription} = 1 for @{ $self->order->items_sorted }; |
|
1358 |
|
|
1359 |
if (!$::form->{form_validity_token}) { |
|
1360 |
$::form->{form_validity_token} = SL::DB::ValidityToken->create(scope => SL::DB::ValidityToken::SCOPE_ORDER_SAVE())->token; |
|
1299 |
if ($self->order->id) { |
|
1300 |
$self->action_edit; |
|
1301 |
} else { |
|
1302 |
$self->action_add; |
|
1361 | 1303 |
} |
1362 |
|
|
1363 |
$self->render( |
|
1364 |
'order/form', |
|
1365 |
title => $self->type_data->text('edit'), |
|
1366 |
%{$self->{template_args}} |
|
1367 |
); |
|
1368 |
|
|
1369 | 1304 |
} |
1370 | 1305 |
|
1371 | 1306 |
# load the second row for one or more items |
... | ... | |
1885 | 1820 |
# be retrieved via items until the order is saved. Adding empty items to new |
1886 | 1821 |
# order here solves this problem. |
1887 | 1822 |
my $order; |
1888 |
$order = SL::DB::Order->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id}; |
|
1889 |
$order ||= SL::DB::Order->new(orderitems => [], |
|
1890 |
record_type => $::form->{type}, |
|
1891 |
currency_id => $::instance_conf->get_currency_id(),); |
|
1823 |
if ($::form->{id}) { |
|
1824 |
$order = SL::DB::Order->new( |
|
1825 |
id => $::form->{id} |
|
1826 |
)->load( |
|
1827 |
with => [ |
|
1828 |
'orderitems', |
|
1829 |
'orderitems.part', |
|
1830 |
] |
|
1831 |
); |
|
1832 |
} else { |
|
1833 |
$order = SL::DB::Order->new( |
|
1834 |
orderitems => [], |
|
1835 |
record_type => $::form->{type}, |
|
1836 |
currency_id => $::instance_conf->get_currency_id(), |
|
1837 |
); |
|
1838 |
$order = SL::Model::Record->update_after_new($order) |
|
1839 |
} |
|
1892 | 1840 |
|
1893 | 1841 |
my $cv_id_method = $order->type_data->properties('customervendor'). '_id'; |
1894 | 1842 |
if (!$::form->{id} && $::form->{$cv_id_method}) { |
... | ... | |
2201 | 2149 |
delete $::form->{form_validity_token}; |
2202 | 2150 |
} |
2203 | 2151 |
|
2152 |
sub reinit_after_new_order { |
|
2153 |
my ($self) = @_; |
|
2154 |
|
|
2155 |
# change form type |
|
2156 |
$::form->{type} = $self->order->type; |
|
2157 |
$self->type($self->init_type); |
|
2158 |
$self->type_data($self->init_type_data); |
|
2159 |
$self->cv ($self->init_cv); |
|
2160 |
$self->check_auth; |
|
2161 |
|
|
2162 |
foreach my $item (@{$self->order->items_sorted}) { |
|
2163 |
# set item ids to new fake id, to identify them as new items |
|
2164 |
$item->{new_fake_id} = join('_', 'new', Time::HiRes::gettimeofday(), int rand 1000000000000); |
|
2165 |
|
|
2166 |
# trigger rendering values for second row as hidden, because they |
|
2167 |
# are loaded only on demand. So we need to keep the values from the |
|
2168 |
# source. |
|
2169 |
$item->{render_second_row} = 1; |
|
2170 |
} |
|
2171 |
|
|
2172 |
# Warn on order locked items if they are not wanted for this record type |
|
2173 |
if ($self->type_data->no_order_locked_parts) { |
|
2174 |
my @order_locked_positions = |
|
2175 |
map { $_->position } |
|
2176 |
grep { $_->part->order_locked } |
|
2177 |
@{ $self->order->items_sorted }; |
|
2178 |
flash('warning', t8( |
|
2179 |
'This record contains not orderable items at position #1', |
|
2180 |
join ', ', @order_locked_positions) |
|
2181 |
) if @order_locked_positions; |
|
2182 |
} |
|
2183 |
|
|
2184 |
$self->get_unalterable_data(); |
|
2185 |
$self->recalc(); |
|
2186 |
} |
|
2187 |
|
|
2204 | 2188 |
sub pre_render { |
2205 | 2189 |
my ($self) = @_; |
2206 | 2190 |
|
Auch abrufbar als: Unified diff
FIX: S:C:Order: Daten über Workflows vollständig und korrekt laden