Auftrags-Controller: Kunde/Lieferant vorbelegen, wenn deren id übergeben wird
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 16 May 2018 14:58:36 +0000 (16:58 +0200)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Wed, 16 May 2018 15:02:23 +0000 (17:02 +0200)
Für die Workflow-Links aus den Kunden-/Lieferantenstammdaten heraus werden
die customer_id oder vendor_id berücksichtigt und die Kunden-/Lieferanten-
abhängigen Attribute im Order-Objekt entprechend gesetzt.

SL/Controller/Order.pm

index 845115c..4229964 100644 (file)
@@ -576,6 +576,9 @@ sub action_purchase_order {
 sub action_customer_vendor_changed {
   my ($self) = @_;
 
+  _setup_order_from_cv($self->order);
+  $self->_recalc();
+
   my $cv_method = $self->cv;
 
   if ($self->order->$cv_method->contacts && scalar @{ $self->order->$cv_method->contacts } > 0) {
@@ -590,19 +593,7 @@ sub action_customer_vendor_changed {
     $self->js->hide('#shipto_row');
   }
 
-  $self->order->taxzone_id($self->order->$cv_method->taxzone_id);
-
-  if ($self->order->is_sales) {
-    $self->order->taxincluded(defined($self->order->$cv_method->taxincluded_checked)
-                              ? $self->order->$cv_method->taxincluded_checked
-                              : $::myconfig{taxincluded_checked});
-    $self->js->val('#order_salesman_id', $self->order->$cv_method->salesman_id);
-  }
-
-  $self->order->payment_id($self->order->$cv_method->payment_id);
-  $self->order->delivery_term_id($self->order->$cv_method->delivery_term_id);
-
-  $self->_recalc();
+  $self->js->val( '#order_salesman_id',      $self->order->salesman_id)        if $self->order->is_sales;
 
   $self->js
     ->replaceWith('#order_cp_id',            $self->build_contact_select)
@@ -612,7 +603,7 @@ sub action_customer_vendor_changed {
     ->val(        '#order_taxincluded',      $self->order->taxincluded)
     ->val(        '#order_payment_id',       $self->order->payment_id)
     ->val(        '#order_delivery_term_id', $self->order->delivery_term_id)
-    ->val(        '#order_intnotes',         $self->order->$cv_method->notes)
+    ->val(        '#order_intnotes',         $self->order->intnotes)
     ->focus(      '#order_' . $self->cv . '_id');
 
   $self->_js_redisplay_amounts_and_taxes;
@@ -1132,6 +1123,12 @@ sub _make_order {
   $order ||= SL::DB::Order->new(orderitems => [],
                                 quotation  => (any { $self->type eq $_ } (_sales_quotation_type(), _request_quotation_type())));
 
+  my $cv_id_method = $self->cv . '_id';
+  if (!$::form->{id} && $::form->{$cv_id_method}) {
+    $order->$cv_id_method($::form->{$cv_id_method});
+    _setup_order_from_cv($order);
+  }
+
   my $form_orderitems               = delete $::form->{order}->{orderitems};
   my $form_periodic_invoices_config = delete $::form->{order}->{periodic_invoices_config};
 
@@ -1251,6 +1248,22 @@ sub _new_item {
   return $item;
 }
 
+sub _setup_order_from_cv {
+  my ($order) = @_;
+
+  $order->$_($order->customervendor->$_) for (qw(taxzone_id payment_id delivery_term_id));
+
+  $order->intnotes($order->customervendor->notes);
+
+  if ($order->is_sales) {
+    $order->salesman_id($order->customer->salesman_id);
+    $order->taxincluded(defined($order->customer->taxincluded_checked)
+                        ? $order->customer->taxincluded_checked
+                        : $::myconfig{taxincluded_checked});
+  }
+
+}
+
 # recalculate prices and taxes
 #
 # Using the PriceTaxCalculator. Store linetotals in the item objects.