From: Sven Schöling Date: Tue, 11 Jul 2017 17:17:57 +0000 (+0200) Subject: Artikel anlegen mit Rücksprung in Belege X-Git-Tag: release-3.5.4~1026 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=9c76bacaa1bfbefc80f7d595ca47ec882266dc70;p=kivitendo-erp.git Artikel anlegen mit Rücksprung in Belege --- diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 10c6c10b6..869a5248c 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -16,6 +16,7 @@ use DateTime; use SL::DB::History; use SL::DB::Helper::ValidateAssembly qw(validate_assembly); use SL::CVar; +use SL::MoreCommon qw(save_form); use Carp; use Rose::Object::MakeMethods::Generic ( @@ -69,6 +70,15 @@ sub action_add_assortment { $self->add; }; +sub action_add_from_record { + my ($self) = @_; + + check_has_valid_part_type($::form->{part}{part_type}); + + $self->parse_form; + $self->add; +} + sub action_add { my ($self) = @_; @@ -139,7 +149,8 @@ sub action_save { flash_later('info', $is_new ? t8('The item has been created.') . " " . $self->part->displayable_name : t8('The item has been saved.')); if ( $::form->{callback} ) { - $self->redirect_to($::form->unescape($::form->{callback})); + $self->redirect_to($::form->unescape($::form->{callback}) . '&new_parts_id=' . $self->part->id); + } else { # default behaviour after save: reload item, this also resets last_modification! $self->redirect_to(controller => 'Part', action => 'edit', 'part.id' => $self->part->id); diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 28cfc801d..15695215f 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -697,34 +697,35 @@ sub item_selected { } sub new_item { - $main::lxdebug->enter_sub(); + _check_io_auth(); - my $form = $main::form; - my %myconfig = %main::myconfig; + my $price = $::form->{vc} eq 'customer' ? 'sellprice_as_number' : 'lastcost_as_number'; + my $previousform = $::auth->save_form_in_session; + my $callback = build_std_url("action=return_from_new_item", "previousform=$previousform"); + my $i = $::form->{rowcount}; - _check_io_auth(); + my @HIDDENS; + push @HIDDENS, { 'name' => 'callback', 'value' => $callback }; + push @HIDDENS, map +{ 'name' => $_, 'value' => $::form->{$_} }, qw(rowcount vc); + push @HIDDENS, map +{ 'name' => "part.$_", 'value' => $::form->{"${_}_$i"} }, qw(partnumber description unit price_factor_id); + push @HIDDENS, { 'name' => "part.$price", 'value' => $::form->{"sellprice_$i"} }; + push @HIDDENS, { 'name' => "part.notes", 'value' => $::form->{"longdescription_$i"} }; - my $price_key = ($form->{type} =~ m/request_quotation|purchase_order/) || ($form->{script} eq 'ir.pl') ? 'lastcost' : 'sellprice'; + $::form->header; + print $::form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } ); +} - # change callback - $form->{old_callback} = $form->escape($form->{callback}, 1); - $form->{callback} = $form->escape("$form->{script}?action=display_form", 1); +sub return_from_new_item { + _check_io_auth(); - # save all form variables except action in the session and keep the key in the previousform variable - my $previousform = $::auth->save_form_in_session(skip_keys => [ qw(action) ]); + my $part = SL::DB::Manager::Part->find_by(id => delete $::form->{new_parts_id}) or die 'can not find part that was just saved!'; - my @HIDDENS; - push @HIDDENS, { 'name' => 'previousform', 'value' => $previousform }; - push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{$_} }, qw(rowcount vc); - push @HIDDENS, map +{ 'name' => $_, 'value' => $form->{"${_}_$form->{rowcount}"} }, qw(partnumber description unit); - push @HIDDENS, { 'name' => 'taxaccount2', 'value' => $form->{taxaccounts} }; - push @HIDDENS, { 'name' => $price_key, 'value' => $form->parse_amount(\%myconfig, $form->{"sellprice_$form->{rowcount}"}) }; - push @HIDDENS, { 'name' => 'notes', 'value' => $form->{"longdescription_$form->{rowcount}"} }; + $::auth->restore_form_from_session(delete $::form->{previousform}, form => $::form); - $form->header(); - print $form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } ); + $::form->{"id_$::form->{rowcount}"} = $part->id; - $main::lxdebug->leave_sub(); + my $url = build_std_url("script=$::form->{script}", "RESTORE_FORM_FROM_SESSION_ID=" . $::auth->save_form_in_session); + print $::request->{cgi}->redirect($url); } sub check_form { diff --git a/templates/webpages/generic/new_item.html b/templates/webpages/generic/new_item.html index d30427a5b..0a37257d7 100644 --- a/templates/webpages/generic/new_item.html +++ b/templates/webpages/generic/new_item.html @@ -14,10 +14,10 @@

-  [% 'Part' | $T8 %]
-  [% 'Assembly' | $T8 %]
-  [% 'Service' | $T8 %]
-  [% 'Assortment' | $T8 %] +  [% 'Part' | $T8 %]
+  [% 'Assembly' | $T8 %]
+  [% 'Service' | $T8 %]
+  [% 'Assortment' | $T8 %]

[%- FOREACH var = HIDDENS %] @@ -26,7 +26,7 @@

- + [%- ELSE %] [%- END %]