From b39653f82441d0db075db54950752f6efa267e1c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 15 Oct 2018 16:37:40 +0200 Subject: [PATCH] =?utf8?q?Auftrags-Controller:=20Auftr=C3=A4ge=20auch=20mi?= =?utf8?q?t=20neuem=20Controller=20zusammenfassen=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/Order.pm | 44 +++++++++++++++++++++++++++++++++++------- bin/mozilla/oe.pl | 10 ++++++++++ 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 0144529d5..55f3f747f 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -99,6 +99,36 @@ sub action_edit { ); } +# edit a collective order (consisting of one or more existing orders) +sub action_edit_collective { + my ($self) = @_; + + # collect order ids + my @multi_ids = map { + $_ =~ m{^multi_id_(\d+)$} && $::form->{'multi_id_' . $1} && $::form->{'trans_id_' . $1} && $::form->{'trans_id_' . $1} + } grep { $_ =~ m{^multi_id_\d+$} } keys %$::form; + + # fall back to add if no ids are given + if (scalar @multi_ids == 0) { + $self->action_add(); + return; + } + + # fall back to save as new if only one id is given + if (scalar @multi_ids == 1) { + $self->order(SL::DB::Order->new(id => $multi_ids[0])->load); + $self->action_save_as_new(); + return; + } + + # make new order from given orders + my @multi_orders = map { SL::DB::Order->new(id => $_)->load } @multi_ids; + $self->{converted_from_oe_id} = join ' ', map { $_->id } @multi_orders; + $self->order(SL::DB::Order->new_from_multi(\@multi_orders, sort_sources_by => 'transdate')); + + $self->action_edit(); +} + # delete the order sub action_delete { my ($self) = @_; @@ -1400,17 +1430,17 @@ sub save { my $db = $self->order->db; $db->with_transaction(sub { - SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete}; + SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []}; $self->order->save(cascade => 1); # link records if ($::form->{converted_from_oe_id}) { - my $src = SL::DB::Order->new(id => $::form->{converted_from_oe_id})->load; - # implement OE::_close_quotations_rfqs - this a 1 : 1 connection - # close only if workflow: quotation -> order. TODO test case - $src->update_attributes(closed => 1) if $src->type =~ /_quotation$/; - $src->link_to_record($self->order); - + my @converted_from_oe_ids = split ' ', $::form->{converted_from_oe_id}; + foreach my $converted_from_oe_id (@converted_from_oe_ids) { + my $src = SL::DB::Order->new(id => $converted_from_oe_id)->load; + $src->update_attributes(closed => 1) if $src->type =~ /_quotation$/; + $src->link_to_record($self->order); + } if (scalar @{ $::form->{converted_from_orderitems_ids} || [] }) { my $idx = 0; foreach (@{ $self->order->items_sorted }) { diff --git a/bin/mozilla/oe.pl b/bin/mozilla/oe.pl index 7aeb1b974..9bad69ae9 100644 --- a/bin/mozilla/oe.pl +++ b/bin/mozilla/oe.pl @@ -48,6 +48,8 @@ use List::MoreUtils qw(uniq any none); use List::Util qw(min max reduce sum); use Data::Dumper; +use SL::Controller::Order; + use SL::DB::Customer; use SL::DB::TaxZone; use SL::DB::PaymentTerm; @@ -184,6 +186,14 @@ sub edit { # editing without stuff to edit? try adding it first if ($form->{rowcount} && !$form->{print_and_save}) { + if ($::instance_conf->get_feature_experimental_order) { + my $c = SL::Controller::Order->new; + $c->action_edit_collective(); + + $main::lxdebug->leave_sub(); + $::dispatcher->end_request; + } + my $id; map { $id++ if $form->{"multi_id_$_"} } (1 .. $form->{rowcount}); if (!$id) { -- 2.20.1