X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=t%2Fcontrollers%2Ffinancial_overview%2Fsales_orders.t;h=4c613eeaf4eb6cb29b4798fbaa3abc708a6634e2;hb=10c5bcd8845b264febd0c7bfd1a690e287703b54;hp=9b278be269aeefa33384f224e9de8c267cde4642;hpb=5534d9cb025cc4036f6fcce28a24c5e5b164641e;p=kivitendo-erp.git diff --git a/t/controllers/financial_overview/sales_orders.t b/t/controllers/financial_overview/sales_orders.t index 9b278be26..4c613eeaf 100644 --- a/t/controllers/financial_overview/sales_orders.t +++ b/t/controllers/financial_overview/sales_orders.t @@ -14,7 +14,7 @@ sub today_local { package main; -use Test::More tests => 49; +use Test::More tests => 43; use lib 't'; use strict; @@ -22,6 +22,9 @@ use utf8; use Carp; use Support::TestSetup; +use SL::Dev::Record qw(create_sales_order create_order_item); +use SL::Dev::CustomerVendor qw(new_customer); +use SL::Dev::Part qw(new_part); use_ok 'SL::BackgroundJob::CreatePeriodicInvoices'; use_ok 'SL::Controller::FinancialOverview'; @@ -31,63 +34,48 @@ use_ok 'SL::DB::Default'; use_ok 'SL::DB::Invoice'; use_ok 'SL::DB::Order'; use_ok 'SL::DB::Part'; -use_ok 'SL::DB::TaxZone'; Support::TestSetup::login(); -our ($ar_chart, $buchungsgruppe, $ctrl, $currency_id, $customer, $employee, $order, $part, $tax_zone, $unit, @invoices); +our ($ar_chart, $ctrl, $customer, $order, $part, $unit, @invoices); + +sub clear_up { + "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); +}; sub init_common_state { - $ar_chart = SL::DB::Manager::Chart->find_by(accno => '1400') || croak "No AR chart"; - $buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%') || croak "No accounting group"; - $currency_id = SL::DB::Default->get->currency_id; - $employee = SL::DB::Manager::Employee->current || croak "No employee"; - $tax_zone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || croak "No taxzone"; - $unit = SL::DB::Manager::Unit->find_by(name => 'psch') || croak "No unit"; + $ar_chart = SL::DB::Manager::Chart->find_by(accno => '1400') || croak "No AR chart"; + $unit = SL::DB::Manager::Unit->find_by(name => 'psch') || croak "No unit"; } -sub create_sales_order { +sub make_sales_order { my %params = @_; - $params{$_} ||= {} for qw(customer part tax order orderitem); + $params{$_} ||= {} for qw(customer part order orderitem); # Clean up: remove invoices, orders, parts and customers - "SL::DB::Manager::${_}"->delete_all(all => 1) for qw(InvoiceItem Invoice OrderItem Order Customer Part); + clear_up(); - $customer = SL::DB::Customer->new( + $customer = new_customer( name => 'Test Customer', - currency_id => $currency_id, - taxzone_id => $tax_zone->id, %{ $params{customer} } )->save; - $part = SL::DB::Part->new( + $part = new_part( partnumber => 'T4254', description => 'Fourty-two fifty-four', lastcost => 222.22, sellprice => 333.33, - buchungsgruppen_id => $buchungsgruppe->id, - unit => $unit->name, %{ $params{part} } )->save; $part->load; - $order = SL::DB::Order->new( - customer_id => $customer->id, - currency_id => $currency_id, - taxzone_id => $tax_zone->id, + $order = create_sales_order( + save => 1, + customer => $customer, transaction_description => '<%period_start_date%>', transdate => DateTime->from_kivitendo('01.03.2014'), - orderitems => [ - { parts_id => $part->id, - description => $part->description, - lastcost => $part->lastcost, - sellprice => $part->sellprice, - qty => 1, - unit => $unit->name, - %{ $params{orderitem} }, - }, - ], + orderitems => [ create_order_item(part => $part, qty => 1, %{ $params{orderitem} }) ], periodic_invoices_config => $params{periodic_invoices_config} ? { active => 1, ar_chart_id => $ar_chart->id, @@ -96,11 +84,7 @@ sub create_sales_order { %{ $params{order} }, ); - $order->calculate_prices_and_taxes; - - ok($order->save(cascade => 1)); - - $::form = Form->new(''); + $::form = Support::TestSetup->create_new_form; $::form->{year} = 2014; $ctrl = SL::Controller::FinancialOverview->new; @@ -113,7 +97,7 @@ init_common_state(); # ---------------------------------------------------------------------- # An order without periodic invoices: -create_sales_order(); +make_sales_order(); is_deeply($ctrl->data->{$_}, { months => [ (0) x 12 ], quarters => [ 0, 0, 0, 0 ], year => 0 }, "no periodic invoices, data for $_") for qw(purchase_invoices purchase_orders requests_for_quotation sales_invoices sales_quotations); @@ -123,7 +107,7 @@ is_deeply($ctrl->data->{$_}, { months => [ 0, 0, 333.33, 0, 0, 0, 0, 0, 0, 0, 0, # ---------------------------------------------------------------------- # order_value_periodicity=y, periodicity=q -create_sales_order( +make_sales_order( periodic_invoices_config => { periodicity => 'm', order_value_periodicity => 'y', @@ -142,7 +126,7 @@ is_deeply($ctrl->data->{sales_orders_per_inv}, # ---------------------------------------------------------------------- # order_value_periodicity=y, periodicity=q, starting in previous year -create_sales_order( +make_sales_order( order => { transdate => DateTime->from_kivitendo('01.03.2013'), }, @@ -164,7 +148,7 @@ is_deeply($ctrl->data->{sales_orders_per_inv}, # ---------------------------------------------------------------------- # order_value_periodicity=y, periodicity=q, starting in previous year, ending middle of year -create_sales_order( +make_sales_order( order => { transdate => DateTime->from_kivitendo('01.03.2013'), }, @@ -188,7 +172,7 @@ is_deeply($ctrl->data->{sales_orders_per_inv}, # ---------------------------------------------------------------------- # order_value_periodicity=y, periodicity=q, starting and ending before current -create_sales_order( +make_sales_order( order => { transdate => DateTime->from_kivitendo('01.03.2012'), }, @@ -203,4 +187,6 @@ create_sales_order( is_deeply($ctrl->data->{$_}, { months => [ (0) x 12 ], quarters => [ 0, 0, 0, 0 ], year => 0 }, "periodic conf p=q ovp=y, no invoices, starting and ending before current year, data for $_") for qw(purchase_invoices purchase_orders requests_for_quotation sales_invoices sales_orders sales_orders_per_inv sales_quotations); +clear_up(); + done_testing();