From 2f105e47dc30fc2fc1d5368ea726faa4e6185527 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 3 Dec 2020 10:34:04 +0100 Subject: [PATCH] Order-Controller: Umwandlung: gemeinsamen Code in eigene Funktion ausgelagert --- SL/Controller/Order.pm | 77 +++++++++++++----------------------------- bin/mozilla/oe.pl | 25 ++++---------- 2 files changed, 29 insertions(+), 73 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 29ff0ac49..b51802f62 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -581,27 +581,10 @@ sub action_get_has_active_periodic_invoices { sub action_save_and_delivery_order { my ($self) = @_; - my $errors = $self->save(); - - if (scalar @{ $errors }) { - $self->js->flash('error', $_) foreach @{ $errors }; - return $self->js->render(); - } - - my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved') - : $self->type eq purchase_order_type() ? $::locale->text('The order has been saved') - : $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved') - : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved') - : ''; - flash_later('info', $text); - - my @redirect_params = ( + $self->save_and_redirect_to( controller => 'oe.pl', action => 'oe_delivery_order_from_order', - id => $self->order->id, ); - - $self->redirect_to(@redirect_params); } # save the order and redirect to the frontend subroutine for a new @@ -609,27 +592,10 @@ sub action_save_and_delivery_order { sub action_save_and_invoice { my ($self) = @_; - my $errors = $self->save(); - - if (scalar @{ $errors }) { - $self->js->flash('error', $_) foreach @{ $errors }; - return $self->js->render(); - } - - my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved') - : $self->type eq purchase_order_type() ? $::locale->text('The order has been saved') - : $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved') - : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved') - : ''; - flash_later('info', $text); - - my @redirect_params = ( + $self->save_and_redirect_to( controller => 'oe.pl', action => 'oe_invoice_from_order', - id => $self->order->id, ); - - $self->redirect_to(@redirect_params); } # workflow from sales quotation to sales order @@ -646,27 +612,10 @@ sub action_purchase_order { sub action_save_and_ap_transaction { my ($self) = @_; - my $errors = $self->save(); - - if (scalar @{ $errors }) { - $self->js->flash('error', $_) foreach @{ $errors }; - return $self->js->render(); - } - - my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved') - : $self->type eq purchase_order_type() ? $::locale->text('The order has been saved') - : $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved') - : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved') - : ''; - flash_later('info', $text); - - my @redirect_params = ( + $self->save_and_redirect_to( controller => 'ap.pl', action => 'add_from_purchase_order', - id => $self->order->id, ); - - $self->redirect_to(@redirect_params); } # set form elements in respect to a changed customer or vendor @@ -2111,6 +2060,26 @@ sub nr_key { : ''; } +sub save_and_redirect_to { + my ($self, %params) = @_; + + my $errors = $self->save(); + + if (scalar @{ $errors }) { + $self->js->flash('error', $_) foreach @{ $errors }; + return $self->js->render(); + } + + my $text = $self->type eq sales_order_type() ? $::locale->text('The order has been saved') + : $self->type eq purchase_order_type() ? $::locale->text('The order has been saved') + : $self->type eq sales_quotation_type() ? $::locale->text('The quotation has been saved') + : $self->type eq request_quotation_type() ? $::locale->text('The rfq has been saved') + : ''; + flash_later('info', $text); + + $self->redirect_to(%params, id => $self->order->id); +} + 1; __END__ diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 82f2906a6..555822a2f 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -2050,8 +2050,7 @@ sub delivery_order { $main::lxdebug->leave_sub(); } -sub oe_delivery_order_from_order { - +sub oe_prepare_xyz_from_order { return if !$::form->{id}; my $order = SL::DB::Order->new(id => $::form->{id})->load; @@ -2068,27 +2067,15 @@ sub oe_delivery_order_from_order { $::form->{rowcount}++; _update_ship(); +} + +sub oe_delivery_order_from_order { + oe_prepare_xyz_from_order(); delivery_order(); } sub oe_invoice_from_order { - - return if !$::form->{id}; - - my $order = SL::DB::Order->new(id => $::form->{id})->load; - $order->flatten_to_form($::form, format_amounts => 1); - - # hack: add partsgroup for first row if it does not exists, - # because _remove_billed_or_delivered_rows and _remove_full_delivered_rows - # determine fields to handled by existing fields for the first row. If partsgroup - # is missing there, for deleted rows the partsgroup_field is not emptied and in - # update_delivery_order it will not considered an empty row ... - $::form->{partsgroup_1} = '' if !exists $::form->{partsgroup_1}; - - # fake last empty row - $::form->{rowcount}++; - - _update_ship(); + oe_prepare_xyz_from_order(); invoice(); } -- 2.20.1