commit e3b06f8537b33ae022c301c703133499d66c612a
Author: Werner Hahn <wh@futureworldsearch.net>
Date:   Sat Aug 19 14:19:58 2017 +0200

    Shopmodul: syntax in shoporder

diff --git a/SL/DB/ShopOrder.pm b/SL/DB/ShopOrder.pm
index 4cb111001..fb3e9c6e6 100644
--- a/SL/DB/ShopOrder.pm
+++ b/SL/DB/ShopOrder.pm
@@ -16,16 +16,6 @@ __PACKAGE__->meta->add_relationships(
     column_map => { id => 'shop_order_id' },
     type       => 'one to many',
   },
-  customer => {
-    class     => 'SL::DB::Customer',
-    column_map  => { kivi_customer_id => 'id' },
-    type        => 'one to many',
-  },
-  shop => {
-    class     => 'SL::DB::Shop',
-    column_map  => { shop_id => 'id' },
-    type        => 'one to many',
-  },
 );
 
 __PACKAGE__->meta->initialize;
@@ -46,24 +36,22 @@ sub convert_to_sales_order {
 
   my @items = map{
 
-  # TODO Flash and exit if part not found
     my $part = SL::DB::Manager::Part->find_by(partnumber => $_->partnumber);
 
     unless($part){
       push @error_report, t8('Part with partnumber: #1 not found', $_->partnumber);
     }else{
-      my $shop_part = SL::DB::Manager::ShopPart->get_all( where => [ shop_id => $self->shop_id, part_id => $part->id] )->[0];
-
-      my @cvars = map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } ;
-      my $current_order_item =
-        SL::DB::OrderItem->new(parts_id               => $part->id,
-                               description            => $part->description,
-                               qty                    => $_->quantity,
-                               sellprice              => $_->price,
-                               unit                   => $part->unit,
-                               position               => $_->position,
-                               active_price_source    => $shop_part->active_price_source,
-                             );
+      my $shop_part = SL::DB::Manager::ShopPart->find_by( shop_id => $self->shop_id, part_id => $part->id );
+
+      my $current_order_item = SL::DB::OrderItem->new(
+        parts_id            => $part->id,
+        description         => $part->description,
+        qty                 => $_->quantity,
+        sellprice           => $_->price,
+        unit                => $part->unit,
+        position            => $_->position,
+        active_price_source => $shop_part->active_price_source,
+      );
     }
   }@{ $self->shop_order_items };
 
@@ -71,23 +59,23 @@ sub convert_to_sales_order {
 
     my $shipto_id;
     if ($self->billing_firstname ne $self->delivery_firstname || $self->billing_lastname ne $self->delivery_lastname || $self->billing_city ne $self->delivery_city || $self->billing_street ne $self->delivery_street) {
-      if(my $address = SL::DB::Manager::Shipto->find_by( shiptoname          => $self->delivery_firstname . " " . $self->delivery_lastname,
-                                                          shiptostreet        => $self->delivery_street,
-                                                          shiptocity          => $self->delivery_city,
+      if(my $address = SL::DB::Manager::Shipto->find_by( shiptoname   => $self->delivery_firstname . " " . $self->delivery_lastname,
+                                                         shiptostreet => $self->delivery_street,
+                                                         shiptocity   => $self->delivery_city,
                                                         )) {
         $shipto_id = $address->{shipto_id};
       } else {
         my $deliveryaddress = SL::DB::Shipto->new;
         $deliveryaddress->assign_attributes(
-          shiptoname          => $self->delivery_firstname . " " . $self->delivery_lastname,
-          shiptodepartment_1  => $self->delivery_company,
-          shiptodepartment_2  => $self->delivery_department,
-          shiptostreet        => $self->delivery_street,
-          shiptozipcode       => $self->delivery_zipcode,
-          shiptocity          => $self->delivery_city,
-          shiptocountry       => $self->delivery_country,
-          trans_id            => $customer->id,
-          module              => "CT",
+          shiptoname         => $self->delivery_firstname . " " . $self->delivery_lastname,
+          shiptodepartment_1 => $self->delivery_company,
+          shiptodepartment_2 => $self->delivery_department,
+          shiptostreet       => $self->delivery_street,
+          shiptozipcode      => $self->delivery_zipcode,
+          shiptocity         => $self->delivery_city,
+          shiptocountry      => $self->delivery_country,
+          trans_id           => $customer->id,
+          module             => "CT",
         );
         $deliveryaddress->save;
         $shipto_id = $deliveryaddress->{shipto_id};
@@ -95,26 +83,26 @@ sub convert_to_sales_order {
     }
 
     my $order = SL::DB::Order->new(
-                    amount                  => $self->amount,
-                    cusordnumber            => $self->shop_ordernumber,
-                    customer_id             => $customer->id,
-                    shipto_id               => $shipto_id,
-                    orderitems              => [ @items ],
-                    employee_id             => $employee->id,
-                    intnotes                => ($customer->notes ne "" ? "\n[Kundestammdaten]\n" . $customer->notes : ""),
-                    salesman_id             => $employee->id,
-                    taxincluded             => $self->tax_included,
-                    payment_id              => $customer->payment_id,
-                    taxzone_id              => $customer->taxzone_id,
-                    currency_id             => $customer->currency_id,
-                    transaction_description => 'Shop Import',
-                    transdate               => DateTime->today_local
-                  );
+      amount                  => $self->amount,
+      cusordnumber            => $self->shop_ordernumber,
+      customer_id             => $customer->id,
+      shipto_id               => $shipto_id,
+      orderitems              => [ @items ],
+      employee_id             => $employee->id,
+      intnotes                => $customer->notes,
+      salesman_id             => $employee->id,
+      taxincluded             => $self->tax_included,
+      payment_id              => $customer->payment_id,
+      taxzone_id              => $customer->taxzone_id,
+      currency_id             => $customer->currency_id,
+      transaction_description => 'Shop Import',
+      transdate               => DateTime->today_local
+    );
      return $order;
    }else{
      my %error_order = (error   => 1,
                         errors  => [ @error_report ],
-                );
+                       );
      return \%error_order;
    }
 };
