SL::DB::ShopOrder - in convert_to_sales_order transdate übergeben
authorG. Richardson <grichardson@kivitec.de>
Tue, 7 Jul 2020 16:18:27 +0000 (18:18 +0200)
committerG. Richardson <grichardson@kivitec.de>
Tue, 7 Jul 2020 16:35:41 +0000 (18:35 +0200)
Um ein bestimmtes Datum zu forcieren, nützlich für Tests.

Außerdem Umstellung auf hartkodiertes Testjahr 2019 in 2020.

SL/DB/ShopOrder.pm
t/shop/shop_order.t

index ee02f3e..4e125fb 100644 (file)
@@ -26,8 +26,9 @@ __PACKAGE__->meta->initialize;
 sub convert_to_sales_order {
   my ($self, %params) = @_;
 
-  my $customer = delete $params{customer};
-  my $employee = delete $params{employee};
+  my $customer  = delete $params{customer};
+  my $employee  = delete $params{employee};
+  my $transdate = delete $params{transdate} // DateTime->today_local;
   croak "param customer is missing" unless ref($customer) eq 'SL::DB::Customer';
   croak "param employee is missing" unless ref($employee) eq 'SL::DB::Employee';
 
@@ -98,7 +99,7 @@ sub convert_to_sales_order {
       taxzone_id              => $customer->taxzone_id,
       currency_id             => $customer->currency_id,
       transaction_description => $shop->transaction_description,
-      transdate               => DateTime->today_local
+      transdate               => $transdate,
     );
      return $order;
    }else{
index 762c639..aef4150 100644 (file)
@@ -16,12 +16,16 @@ use SL::Controller::ShopOrder;
 use Data::Dumper;
 
 my ($shop, $shop_order, $shop_part, $part, $customer, $employee);
+my ($transdate);
 
 sub reset_state {
   my %params = @_;
 
   clear_up();
 
+  $transdate = DateTime->today_local;
+  $transdate->set_year(2019) if $transdate->year == 2020; # use year 2019 in 2020, because of tax rate change in Germany
+
   $shop = new_shop->save;
   $part = new_part->save;
   $shop_part = new_shop_part(part => $part, shop => $shop)->save;
@@ -73,7 +77,9 @@ my $shop_trans_id = 1;
 
 $shop_order = new_shop_order(
   shop              => $shop,
+  transfer_date     => $transdate,
   shop_trans_id     => $shop_trans_id,
+  order_date        => $transdate->datetime,
   amount            => 59.5,
   billing_lastname  => 'Schmidt',
   billing_firstname => 'Sven',
@@ -141,7 +147,7 @@ is($shop->description   , 'testshop' , 'shop description ok');
 is($shop_order->shop_id , $shop->id  , "shop_id ok");
 
 note('testing convert_to_sales_order');
-my $order = $shop_order->convert_to_sales_order(employee => $employee, customer => $customer);
+my $order = $shop_order->convert_to_sales_order(employee => $employee, customer => $customer, transdate => $shop_order->order_date);
 $order->calculate_prices_and_taxes;
 $order->save;