From: Sven Schöling Date: Tue, 22 Aug 2017 14:25:47 +0000 (+0200) Subject: Tests: SL::Dev Änderungen übernommen X-Git-Tag: release-3.5.4~875 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=63410aa68c7c57655dc66eba4291592358d46cf2;p=kivitendo-erp.git Tests: SL::Dev Änderungen übernommen --- diff --git a/t/background_job/create_periodic_invoices.t b/t/background_job/create_periodic_invoices.t index 2bacad82d..1ce5fe600 100644 --- a/t/background_job/create_periodic_invoices.t +++ b/t/background_job/create_periodic_invoices.t @@ -22,7 +22,7 @@ use utf8; use Carp; use Support::TestSetup; -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); use_ok 'SL::BackgroundJob::CreatePeriodicInvoices'; use_ok 'SL::DB::Chart'; @@ -54,12 +54,12 @@ sub create_invoices { # Clean up: remove invoices, orders, parts and customers clear_up(); - $customer = SL::Dev::CustomerVendor::create_customer( + $customer = new_customer( name => 'Test Customer', %{ $params{customer} } )->save; - $part = SL::Dev::Part::create_part( + $part = new_part( partnumber => 'T4254', description => 'Fourty-two fifty-four', lastcost => 222.22, @@ -68,7 +68,7 @@ sub create_invoices { %{ $params{part} } )->save; - $order = SL::Dev::Record::create_sales_order( + $order = create_sales_order( save => 1, customer => $customer, transaction_description => '<%period_start_date%>', diff --git a/t/bank/bank_transactions.t b/t/bank/bank_transactions.t index d2376a22a..69028b143 100644 --- a/t/bank/bank_transactions.t +++ b/t/bank/bank_transactions.t @@ -23,7 +23,7 @@ use SL::DB::PaymentTerm; use SL::DB::PurchaseInvoice; use SL::DB::BankTransaction; use SL::Controller::BankTransaction; -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); use Data::Dumper; my ($customer, $vendor, $currency_id, $unit, $tax, $tax7, $tax_9, $payment_terms, $bank_account); @@ -117,7 +117,7 @@ sub reset_state { name => SL::DB::Manager::Chart->find_by(description => 'Bank')->description, )->save; - $customer = SL::Dev::CustomerVendor::create_customer( + $customer = new_customer( name => 'Test Customer', iban => 'DE12500105170648489890', bic => 'TESTBIC', @@ -130,9 +130,9 @@ sub reset_state { customernumber => 'CUST1704', )->save; - $payment_terms = SL::Dev::Payment::create_payment_terms; + $payment_terms = create_payment_terms(); - $vendor = SL::Dev::CustomerVendor::create_vendor( + $vendor = new_vendor( name => 'Test Vendor', payment_id => $payment_terms->id, iban => 'DE12500105170648489890', @@ -237,7 +237,7 @@ sub test1 { $ar_transaction = test_ar_transaction(invnumber => 'salesinv1'); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction"; + my $bt = create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { $bt->id => [ $ar_transaction->id ] @@ -261,10 +261,10 @@ sub test_skonto_exact { payment_id => $payment_terms->id, ); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction, - bank_chart_id => $bank->id, - amount => $ar_transaction->amount_less_skonto - ) or die "Couldn't create bank_transaction"; + my $bt = create_bank_transaction(record => $ar_transaction, + bank_chart_id => $bank->id, + amount => $ar_transaction->amount_less_skonto + ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { $bt->id => [ $ar_transaction->id ] @@ -290,11 +290,11 @@ sub test_two_invoices { my $ar_transaction_1 = test_ar_transaction(invnumber => 'salesinv_1'); my $ar_transaction_2 = test_ar_transaction(invnumber => 'salesinv_2'); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction_1, - amount => ($ar_transaction_1->amount + $ar_transaction_2->amount), - purpose => "Rechnungen " . $ar_transaction_1->invnumber . " und " . $ar_transaction_2->invnumber, - bank_chart_id => $bank->id, - ) or die "Couldn't create bank_transaction"; + my $bt = create_bank_transaction(record => $ar_transaction_1, + amount => ($ar_transaction_1->amount + $ar_transaction_2->amount), + purpose => "Rechnungen " . $ar_transaction_1->invnumber . " und " . $ar_transaction_2->invnumber, + bank_chart_id => $bank->id, + ) or die "Couldn't create bank_transaction"; my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($ar_transaction_1); is($agreement, 16, "points for ar_transaction_1 in test_two_invoices ok"); @@ -324,10 +324,10 @@ sub test_overpayment { $ar_transaction = test_ar_transaction(invnumber => 'salesinv overpaid'); # amount 135 > 119 - my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction, - bank_chart_id => $bank->id, - amount => 135 - ) or die "Couldn't create bank_transaction"; + my $bt = create_bank_transaction(record => $ar_transaction, + bank_chart_id => $bank->id, + amount => 135 + ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { $bt->id => [ $ar_transaction->id ] @@ -354,15 +354,15 @@ sub test_overpayment_with_partialpayment { $ar_transaction = test_ar_transaction(invnumber => 'salesinv overpaid partial'); - my $bt_1 = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction, - bank_chart_id => $bank->id, - amount => 10 - ) or die "Couldn't create bank_transaction"; - my $bt_2 = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction, - amount => 119, - transdate => DateTime->today->add(days => 5), - bank_chart_id => $bank->id, - ) or die "Couldn't create bank_transaction"; + my $bt_1 = create_bank_transaction(record => $ar_transaction, + bank_chart_id => $bank->id, + amount => 10 + ) or die "Couldn't create bank_transaction"; + my $bt_2 = create_bank_transaction(record => $ar_transaction, + amount => 119, + transdate => DateTime->today->add(days => 5), + bank_chart_id => $bank->id, + ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { $bt_1->id => [ $ar_transaction->id ] @@ -391,10 +391,10 @@ sub test_partial_payment { $ar_transaction = test_ar_transaction(invnumber => 'salesinv partial payment'); # amount 100 < 119 - my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction, - bank_chart_id => $bank->id, - amount => 100 - ) or die "Couldn't create bank_transaction"; + my $bt = create_bank_transaction(record => $ar_transaction, + bank_chart_id => $bank->id, + amount => 100 + ) or die "Couldn't create bank_transaction"; $::form->{invoice_ids} = { $bt->id => [ $ar_transaction->id ] @@ -414,17 +414,17 @@ sub test_credit_note { my $testname = 'test_credit_note'; - my $part1 = SL::Dev::Part::create_part( partnumber => 'T4254')->save; - my $part2 = SL::Dev::Part::create_service(partnumber => 'Serv1')->save; - my $credit_note = SL::Dev::Record::create_credit_note( + my $part1 = new_part( partnumber => 'T4254')->save; + my $part2 = new_service(partnumber => 'Serv1')->save; + my $credit_note = create_credit_note( invnumber => 'cn 1', customer => $customer, taxincluded => 0, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50), + invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70), + create_invoice_item(part => $part2, qty => 10, sellprice => 50), ] ); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $credit_note, + my $bt = create_bank_transaction(record => $credit_note, amount => $credit_note->amount, bank_chart_id => $bank->id, transdate => DateTime->today->add(days => 10), @@ -476,10 +476,10 @@ sub test_neg_ap_transaction { is($invoice->netamount, -20 , "$testname: netamount ok"); is($invoice->amount , -23.8, "$testname: amount ok"); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $invoice, - amount => $invoice->amount, - bank_chart_id => $bank->id, - transdate => DateTime->today->add(days => 10), + my $bt = create_bank_transaction(record => $invoice, + amount => $invoice->amount, + bank_chart_id => $bank->id, + transdate => DateTime->today->add(days => 10), ); my ($agreement, $rule_matches) = $bt->get_agreement_with_invoice($invoice); is($agreement, 15, "points for negative ap transaction ok"); @@ -531,11 +531,11 @@ sub test_ap_payment_transaction { is($invoice->netamount, 115 , "$testname: netamount ok"); is($invoice->amount , 136.85, "$testname: amount ok"); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $invoice, - amount => $invoice->amount, - bank_chart_id => $bank->id, - transdate => DateTime->today->add(days => 10), - ); + my $bt = create_bank_transaction(record => $invoice, + amount => $invoice->amount, + bank_chart_id => $bank->id, + transdate => DateTime->today->add(days => 10), + ); $::form->{invoice_ids} = { $bt->id => [ $invoice->id ] }; @@ -584,11 +584,11 @@ sub test_ap_payment_part_transaction { is($invoice->netamount, 115 , "$testname: netamount ok"); is($invoice->amount , 136.85, "$testname: amount ok"); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $invoice, - amount => $invoice->amount-100, - bank_chart_id => $bank->id, - transdate => DateTime->today->add(days => 10), - ); + my $bt = create_bank_transaction(record => $invoice, + amount => $invoice->amount-100, + bank_chart_id => $bank->id, + transdate => DateTime->today->add(days => 10), + ); $::form->{invoice_ids} = { $bt->id => [ $invoice->id ] }; @@ -604,11 +604,11 @@ sub test_ap_payment_part_transaction { is($invoice->paid , '36.85000', "$testname: paid ok"); is($bt->invoice_amount, '-36.85000', "$testname: bt invoice amount for ap was assigned"); - my $bt2 = SL::Dev::Payment::create_bank_transaction(record => $invoice, - amount => 100, - bank_chart_id => $bank->id, - transdate => DateTime->today->add(days => 10), - ); + my $bt2 = create_bank_transaction(record => $invoice, + amount => 100, + bank_chart_id => $bank->id, + transdate => DateTime->today->add(days => 10), + ); $::form->{invoice_ids} = { $bt2->id => [ $invoice->id ] }; @@ -630,18 +630,18 @@ sub test_neg_sales_invoice { my $testname = 'test_neg_sales_invoice'; - my $part1 = SL::Dev::Part::create_part( partnumber => 'Funkenhaube öhm')->save; - my $part2 = SL::Dev::Part::create_service(partnumber => 'Service-Pauschale Pasch!')->save; + my $part1 = new_part( partnumber => 'Funkenhaube öhm')->save; + my $part2 = new_service(partnumber => 'Service-Pauschale Pasch!')->save; - my $neg_sales_inv = SL::Dev::Record::create_sales_invoice( + my $neg_sales_inv = create_sales_invoice( invnumber => '20172201', customer => $customer, taxincluded => 0, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => -50), + invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70), + create_invoice_item(part => $part2, qty => 10, sellprice => -50), ] ); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $neg_sales_inv, + my $bt = create_bank_transaction(record => $neg_sales_inv, amount => $neg_sales_inv->amount, bank_chart_id => $bank->id, transdate => DateTime->today, @@ -667,7 +667,7 @@ sub test_bt_rule1 { $ar_transaction = test_ar_transaction(invnumber => 'bt_rule1'); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction"; + my $bt = create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction"; $ar_transaction->load; $bt->load; @@ -697,9 +697,9 @@ sub test_sepa_export { $ar_transaction = test_ar_transaction(invnumber => 'sepa1'); - my $bt = SL::Dev::Payment::create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction"; - my $se = SL::Dev::Payment::create_sepa_export(); - my $sei = SL::Dev::Payment::create_sepa_export_item( + my $bt = create_bank_transaction(record => $ar_transaction) or die "Couldn't create bank_transaction"; + my $se = create_sepa_export(); + my $sei = create_sepa_export_item( chart_id => $bank->id, ar_id => $ar_transaction->id, sepa_export_id => $se->id, diff --git a/t/controllers/financial_controlling/sales_order_with_periodic_invoices_config.t b/t/controllers/financial_controlling/sales_order_with_periodic_invoices_config.t index 8447166ba..5414e9031 100644 --- a/t/controllers/financial_controlling/sales_order_with_periodic_invoices_config.t +++ b/t/controllers/financial_controlling/sales_order_with_periodic_invoices_config.t @@ -22,7 +22,7 @@ use utf8; use Carp; use Support::TestSetup; -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); use_ok 'SL::BackgroundJob::CreatePeriodicInvoices'; use_ok 'SL::Controller::FinancialControllingReport'; @@ -47,19 +47,19 @@ sub init_common_state { $unit = SL::DB::Manager::Unit->find_by(name => 'psch') || croak "No unit"; } -sub create_sales_order { +sub make_sales_order { my %params = @_; cleanup(); $params{$_} ||= {} for qw(customer part order orderitem); - $customer = SL::Dev::CustomerVendor::create_customer( + $customer = new_customer( name => 'Test Customer', %{ $params{customer} } )->save; - $part = SL::Dev::Part::create_part( + $part = new_part( partnumber => 'T4254', description => 'Fourty-two fifty-four', lastcost => 222.22, @@ -69,13 +69,13 @@ sub create_sales_order { )->save; $part->load; - $order = SL::Dev::Record::create_sales_order( + $order = create_sales_order( save => 1, customer => $customer, transaction_description => '<%period_start_date%>', transdate => DateTime->from_kivitendo('01.03.2014'), orderitems => [ - SL::Dev::Record::create_order_item( + create_order_item( part => $part, qty => 1, %{ $params{orderitem} }, @@ -103,7 +103,7 @@ my @columns = qw(net_amount other_amount sub run_tests { my ($msg, $num_orders, $values, %order_params) = @_; - create_sales_order(%order_params); + make_sales_order(%order_params); is($num_orders, scalar @{ $ctrl->orders }, "${msg}, #orders"); is_deeply([ map { ($ctrl->orders->[0]->{$_} // 0) * 1 } @columns ], diff --git a/t/controllers/financial_overview/sales_orders.t b/t/controllers/financial_overview/sales_orders.t index 2f90a2a2a..4c613eeaf 100644 --- a/t/controllers/financial_overview/sales_orders.t +++ b/t/controllers/financial_overview/sales_orders.t @@ -22,7 +22,9 @@ use utf8; use Carp; use Support::TestSetup; -use SL::Dev::ALL; +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'; @@ -46,7 +48,7 @@ sub init_common_state { $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 order orderitem); @@ -54,12 +56,12 @@ sub create_sales_order { # Clean up: remove invoices, orders, parts and customers clear_up(); - $customer = SL::Dev::CustomerVendor::create_customer( + $customer = new_customer( name => 'Test Customer', %{ $params{customer} } )->save; - $part = SL::Dev::Part::create_part( + $part = new_part( partnumber => 'T4254', description => 'Fourty-two fifty-four', lastcost => 222.22, @@ -68,12 +70,12 @@ sub create_sales_order { )->save; $part->load; - $order = SL::Dev::Record::create_sales_order( + $order = create_sales_order( save => 1, customer => $customer, transaction_description => '<%period_start_date%>', transdate => DateTime->from_kivitendo('01.03.2014'), - orderitems => [ SL::Dev::Record::create_order_item(part => $part, qty => 1, %{ $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, @@ -95,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); @@ -105,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', @@ -124,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'), }, @@ -146,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'), }, @@ -170,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'), }, diff --git a/t/controllers/project/project_linked_records.t b/t/controllers/project/project_linked_records.t index 7f7a08118..5ca1224f1 100644 --- a/t/controllers/project/project_linked_records.t +++ b/t/controllers/project/project_linked_records.t @@ -5,7 +5,7 @@ use lib 't'; use Support::TestSetup; use Carp; use Test::Exception; -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); use SL::DB::Part; use SL::DB::Order; use SL::DB::Customer; @@ -20,71 +20,71 @@ Support::TestSetup::login(); clear_up(); -my $vendor = SL::Dev::CustomerVendor::create_vendor->save; -my $customer = SL::Dev::CustomerVendor::create_customer->save; -my $project = SL::Dev::Record::create_project(projectnumber => 'p1', description => 'Project 1')->save; +my $vendor = new_vendor()->save; +my $customer = new_customer()->save; +my $project = create_project(projectnumber => 'p1', description => 'Project 1'); -my $part1 = SL::Dev::Part::create_part( partnumber => 'T4254')->save; -my $part2 = SL::Dev::Part::create_service(partnumber => 'Serv1')->save; +my $part1 = new_part( partnumber => 'T4254')->save; +my $part2 = new_service(partnumber => 'Serv1')->save; # sales order with globalproject_id and item project_ids -my $sales_order = SL::Dev::Record::create_sales_order( +my $sales_order = create_sales_order( save => 1, customer => $customer, globalproject_id => $project->id, taxincluded => 0, - orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), - SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), + orderitems => [ create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), + create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), ] ); # sales order with no globalproject_id but item project_ids -my $sales_order2 = SL::Dev::Record::create_sales_order( +my $sales_order2 = create_sales_order( save => 1, customer => $customer, taxincluded => 0, - orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), - SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50), + orderitems => [ create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), + create_order_item(part => $part2, qty => 10, sellprice => 50), ] ); # purchase order with globalproject_id and item project_ids -my $purchase_order = SL::Dev::Record::create_purchase_order( +my $purchase_order = create_purchase_order( save => 1, vendor => $vendor, globalproject_id => $project->id, taxincluded => 0, - orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), - SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), + orderitems => [ create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), + create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), ] ); # sales_invoice with globalproject_id, and all items with project_id -my $sales_invoice = SL::Dev::Record::create_sales_invoice( +my $sales_invoice = create_sales_invoice( customer => $customer, globalproject_id => $project->id, taxincluded => 0, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), + invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id), + create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), ] ); # sales_invoice with globalproject_id, but none of the items has a project_id -my $sales_invoice2 = SL::Dev::Record::create_sales_invoice( +my $sales_invoice2 = create_sales_invoice( customer => $customer, globalproject_id => $project->id, taxincluded => 0, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50), + invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70), + create_invoice_item(part => $part2, qty => 10, sellprice => 50), ] ); # one of the invoice items has the project id, but there is no globalproject_id -my $sales_invoice4 = SL::Dev::Record::create_sales_invoice( +my $sales_invoice4 = create_sales_invoice( customer => $customer, taxincluded => 0, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), + invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70), + create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id), ] ); diff --git a/t/datev/invoices.t b/t/datev/invoices.t index 45c68ca6d..c944dd8bd 100644 --- a/t/datev/invoices.t +++ b/t/datev/invoices.t @@ -6,7 +6,7 @@ use lib 't'; use_ok 'Support::TestSetup'; use SL::DATEV qw(:CONSTANTS); -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); use List::Util qw(sum); use SL::DB::Buchungsgruppe; use SL::DB::Chart; @@ -24,22 +24,22 @@ my $date = DateTime->new(year => 2017, month => 1, day => 1); my $payment_date = DateTime->new(year => 2017, month => 1, day => 5); my $gldate = DateTime->new(year => 2017, month => 2, day => 9); # simulate bookings for Jan being made in Feb -my $part1 = SL::Dev::Part::create_part(partnumber => '19', description => 'Part 19%')->save; -my $part2 = SL::Dev::Part::create_part( +my $part1 = new_part(partnumber => '19', description => 'Part 19%')->save; +my $part2 = new_part( partnumber => '7', description => 'Part 7%', buchungsgruppen_id => $buchungsgruppe7->id, )->save; -my $invoice = SL::Dev::Record::create_sales_invoice( +my $invoice = create_sales_invoice( invnumber => "1 sales invoice", itime => $gldate, gldate => $gldate, intnotes => 'booked in February', taxincluded => 0, transdate => $date, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50), + invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70), + create_invoice_item(part => $part2, qty => 10, sellprice => 50), ] ); $invoice->pay_invoice(chart_id => $bank->id, @@ -85,27 +85,27 @@ cmp_bag $datev1->generate_datev_lines, [ ], "trans_id datev check ok"; my $march_9 = DateTime->new(year => 2017, month => 3, day => 9); -my $invoice2 = SL::Dev::Record::create_sales_invoice( +my $invoice2 = create_sales_invoice( invnumber => "2 sales invoice", itime => $march_9, gldate => $march_9, intnotes => 'booked in March', taxincluded => 0, transdate => $date, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 6, sellprice => 70), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 20, sellprice => 50), + invoiceitems => [ create_invoice_item(part => $part1, qty => 6, sellprice => 70), + create_invoice_item(part => $part2, qty => 20, sellprice => 50), ] ); -my $credit_note = SL::Dev::Record::create_credit_note( +my $credit_note = create_credit_note( invnumber => 'Gutschrift 34', itime => $gldate, gldate => $gldate, intnotes => 'booked in February', taxincluded => 0, transdate => $date, - invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70), - SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50), + invoiceitems => [ create_invoice_item(part => $part1, qty => 3, sellprice => 70), + create_invoice_item(part => $part2, qty => 10, sellprice => 50), ] ); diff --git a/t/db_helper/convert_invoice.t b/t/db_helper/convert_invoice.t index 0a9c62270..b1ac4c24f 100644 --- a/t/db_helper/convert_invoice.t +++ b/t/db_helper/convert_invoice.t @@ -22,7 +22,7 @@ use SL::DB::DeliveryOrder; use SL::DB::Part; use SL::DB::Unit; -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); my ($customer, $employee, $payment_do, $unit, @parts, $department); @@ -41,7 +41,7 @@ sub reset_state { clear_up(); $unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'"; - $customer = SL::Dev::CustomerVendor::create_customer->save; + $customer = new_customer()->save; $employee = SL::DB::Employee->new( 'login' => 'testuser', @@ -52,7 +52,7 @@ sub reset_state { 'description' => 'Test Department', )->save; - $payment_do = SL::Dev::Payment::create_payment_terms( + $payment_do = create_payment_terms( 'description' => '14Tage 2%Skonto, 30Tage netto', 'description_long' => "Innerhalb von 14 Tagen abzüglich 2 % Skonto, innerhalb von 30 Tagen rein netto.|Bei einer Zahlung bis zum <%skonto_date%> gewähren wir 2 % Skonto (EUR <%skonto_amount%>) entspricht EUR <%total_wo_skonto%>.Bei einer Zahlung bis zum <%netto_date%> ist der fällige Betrag in Höhe von <%total%> <%currency%> zu überweisen.", 'percent_skonto' => '0.02', @@ -62,7 +62,7 @@ sub reset_state { # two real parts @parts = (); - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( description => "description 1", lastcost => '49.95000', listprice => '0.00000', @@ -72,7 +72,7 @@ sub reset_state { weight => '0.79', )->save; - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( description => "description 2", lastcost => '153.00000', listprice => '0.00000', @@ -89,7 +89,7 @@ Support::TestSetup::login(); reset_state(); # we create L20199 with two items -my $do1 = SL::Dev::Record::create_sales_delivery_order( +my $do1 = create_sales_delivery_order( 'department_id' => $department->id, 'donumber' => 'L20199', 'employee_id' => $employee->id, @@ -103,7 +103,7 @@ my $do1 = SL::Dev::Record::create_sales_delivery_order( 'customer_id' => $customer->id, 'notes' => '', orderitems => [ - SL::Dev::Record::create_delivery_order_item( + create_delivery_order_item( part => $parts[0], discount => '0.25', lastcost => '49.95000', @@ -113,7 +113,7 @@ my $do1 = SL::Dev::Record::create_sales_delivery_order( sellprice => '242.20000', unit => $unit->name, ), - SL::Dev::Record::create_delivery_order_item( + create_delivery_order_item( part => $parts[1], discount => '0.25', lastcost => '153.00000', diff --git a/t/db_helper/payment.t b/t/db_helper/payment.t index ac2e44906..b40cf7432 100644 --- a/t/db_helper/payment.t +++ b/t/db_helper/payment.t @@ -10,9 +10,9 @@ use Support::TestSetup; use Test::Exception; use List::Util qw(sum); -use SL::Dev::Record; -use SL::Dev::CustomerVendor; -use SL::Dev::Part; +use SL::Dev::Record qw(create_invoice_item create_sales_invoice create_credit_note); +use SL::Dev::CustomerVendor qw(new_customer new_vendor); +use SL::Dev::Part qw(new_part); use SL::DB::Buchungsgruppe; use SL::DB::Currency; use SL::DB::Exchangerate; @@ -109,7 +109,7 @@ sub reset_state { currency_id => $currency->id, )->save; - $customer = SL::Dev::CustomerVendor::create_customer( + $customer = new_customer( name => 'Test Customer', currency_id => $currency_id, taxzone_id => $taxzone->id, @@ -134,7 +134,7 @@ sub reset_state { auto_calculation => 1, )->save; - $vendor = SL::Dev::CustomerVendor::create_vendor( + $vendor = new_vendor( name => 'Test Vendor', currency_id => $currency_id, taxzone_id => $taxzone->id, @@ -143,7 +143,7 @@ sub reset_state { @parts = (); - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( partnumber => 'T4254', description => 'Fourty-two fifty-four', lastcost => 1.93, @@ -153,7 +153,7 @@ sub reset_state { %{ $params{part1} } )->save; - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( partnumber => 'T0815', description => 'Zero EIGHT fifteeN @ 7%', lastcost => 5.473, @@ -162,7 +162,7 @@ sub reset_state { unit => $unit->name, %{ $params{part2} } )->save; - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( partnumber => '19%', description => 'Testware 19%', lastcost => 0, @@ -171,7 +171,7 @@ sub reset_state { unit => $unit->name, %{ $params{part3} } )->save; - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( partnumber => '7%', description => 'Testware 7%', lastcost => 0, @@ -302,8 +302,8 @@ sub total_amount { sub test_default_invoice_one_item_19_without_skonto() { reset_state() if $ALWAYS_RESET; - my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item = create_invoice_item(part => $parts[0], qty => 2.5); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item ], payment_id => $payment_terms->id, @@ -338,8 +338,8 @@ sub test_default_invoice_one_item_19_without_skonto() { sub test_default_invoice_one_item_19_without_skonto_overpaid() { reset_state() if $ALWAYS_RESET; - my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item = create_invoice_item(part => $parts[0], qty => 2.5); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item ], payment_id => $payment_terms->id, @@ -379,9 +379,9 @@ sub test_default_invoice_one_item_19_without_skonto_overpaid() { sub test_default_invoice_two_items_19_7_tax_with_skonto() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -413,9 +413,9 @@ sub test_default_invoice_two_items_19_7_tax_with_skonto() { sub test_default_invoice_two_items_19_7_tax_with_skonto_tax_included() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 1, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -450,9 +450,9 @@ sub test_default_invoice_two_items_19_7_tax_with_skonto_tax_included() { sub test_default_invoice_two_items_19_7_without_skonto() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -485,9 +485,9 @@ sub test_default_invoice_two_items_19_7_without_skonto() { sub test_default_invoice_two_items_19_7_without_skonto_incomplete_payment() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -516,9 +516,9 @@ sub test_default_invoice_two_items_19_7_without_skonto_incomplete_payment() { sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -552,9 +552,9 @@ sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments() { sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -598,9 +598,9 @@ sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_fi # (11.66) rather than the 19% account (5.85). The actual tax amount is # higher for the 19% case, though (1.11 compared to 0.82) - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -635,9 +635,9 @@ sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_fin reset_state() if $ALWAYS_RESET; # if there are two cents left there will be two skonto bookings, 1 cent each - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 1.2); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[0], qty => 2.5); + my $item2 = create_invoice_item(part => $parts[1], qty => 1.2); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -671,8 +671,8 @@ sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_fin sub test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto() { reset_state() if $ALWAYS_RESET; - my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item = create_invoice_item(part => $parts[0], qty => 2.5); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item ], payment_id => $payment_terms->id, @@ -712,8 +712,8 @@ sub test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto sub test_default_invoice_one_item_19_multiple_payment_final_difference_as_skonto_1cent() { reset_state() if $ALWAYS_RESET; - my $item = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 2.5); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item = create_invoice_item(part => $parts[0], qty => 2.5); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item ], payment_id => $payment_terms->id, @@ -857,9 +857,9 @@ sub test_default_purchase_invoice_two_charts_19_7_tax_without_skonto_multiple_pa sub test_default_invoice_two_items_19_7_tax_with_skonto_50_50() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 1); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 1); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[2], qty => 1); + my $item2 = create_invoice_item(part => $parts[3], qty => 1); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2 ], payment_id => $payment_terms->id, @@ -892,11 +892,11 @@ sub test_default_invoice_two_items_19_7_tax_with_skonto_50_50() { sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5); - my $item3 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5); - my $item4 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[2], qty => 0.5); + my $item2 = create_invoice_item(part => $parts[3], qty => 0.5); + my $item3 = create_invoice_item(part => $parts[2], qty => 0.5); + my $item4 = create_invoice_item(part => $parts[3], qty => 0.5); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2, $item3, $item4 ], payment_id => $payment_terms->id, @@ -928,11 +928,11 @@ sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25() { sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_tax_included() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5); - my $item3 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5); - my $item4 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[2], qty => 0.5); + my $item2 = create_invoice_item(part => $parts[3], qty => 0.5); + my $item3 = create_invoice_item(part => $parts[2], qty => 0.5); + my $item4 = create_invoice_item(part => $parts[3], qty => 0.5); + my $invoice = create_sales_invoice( taxincluded => 1, invoiceitems => [ $item1, $item2, $item3, $item4 ], payment_id => $payment_terms->id, @@ -966,11 +966,11 @@ sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_tax_included() { sub test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_multiple() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5); - my $item3 = SL::Dev::Record::create_invoice_item(part => $parts[2], qty => 0.5); - my $item4 = SL::Dev::Record::create_invoice_item(part => $parts[3], qty => 0.5); - my $invoice = SL::Dev::Record::create_sales_invoice( + my $item1 = create_invoice_item(part => $parts[2], qty => 0.5); + my $item2 = create_invoice_item(part => $parts[3], qty => 0.5); + my $item3 = create_invoice_item(part => $parts[2], qty => 0.5); + my $item4 = create_invoice_item(part => $parts[3], qty => 0.5); + my $invoice = create_sales_invoice( taxincluded => 0, invoiceitems => [ $item1, $item2, $item3, $item4 ], payment_id => $payment_terms->id, @@ -1413,9 +1413,9 @@ sub test_ap_currency_tax_not_included_and_payment_2_credit_note { sub test_credit_note_two_items_19_7_tax_tax_not_included() { reset_state() if $ALWAYS_RESET; - my $item1 = SL::Dev::Record::create_invoice_item(part => $parts[0], qty => 5); - my $item2 = SL::Dev::Record::create_invoice_item(part => $parts[1], qty => 3); - my $invoice = SL::Dev::Record::create_credit_note( + my $item1 = create_invoice_item(part => $parts[0], qty => 5); + my $item2 = create_invoice_item(part => $parts[1], qty => 3); + my $invoice = create_credit_note( invnumber => 'cn1', taxincluded => 0, invoiceitems => [ $item1, $item2 ], diff --git a/t/db_helper/price_tax_calculator.t b/t/db_helper/price_tax_calculator.t index 53135a2f1..c8884018e 100644 --- a/t/db_helper/price_tax_calculator.t +++ b/t/db_helper/price_tax_calculator.t @@ -10,7 +10,7 @@ use Data::Dumper; use List::MoreUtils qw(uniq); use Support::TestSetup; use Test::Exception; -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); use SL::DB::Buchungsgruppe; use SL::DB::Currency; @@ -49,14 +49,14 @@ sub reset_state { $tax7 = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07) || croak "No tax for 7\%"; $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || croak "No taxzone"; - $customer = SL::Dev::CustomerVendor::create_customer( + $customer = new_customer( name => 'Test Customer', taxzone_id => $taxzone->id, %{ $params{customer} } )->save; @parts = (); - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( partnumber => 'T4254', description => 'Fourty-two fifty-four', lastcost => 1.93, @@ -66,7 +66,7 @@ sub reset_state { %{ $params{part1} } )->save; - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( partnumber => 'T0815', description => 'Zero EIGHT fifteeN @ 7%', lastcost => 5.473, @@ -76,7 +76,7 @@ sub reset_state { %{ $params{part2} } )->save; - push @parts, SL::Dev::Part::create_part( + push @parts, new_part( partnumber => 'T888', description => 'Triple 8', lastcost => 0, @@ -91,7 +91,7 @@ sub reset_state { sub new_invoice { my %params = @_; - return SL::Dev::Record::create_sales_invoice( + return create_sales_invoice( taxzone_id => $taxzone->id, %params, ); @@ -102,7 +102,7 @@ sub new_item { my $part = delete($params{part}) || $parts[0]; - return SL::Dev::Record::create_invoice_item( + return create_invoice_item( part => $part, %params, ); diff --git a/t/db_helper/with_transaction.t b/t/db_helper/with_transaction.t index 3071cc3d3..cc3fc0ece 100644 --- a/t/db_helper/with_transaction.t +++ b/t/db_helper/with_transaction.t @@ -10,7 +10,7 @@ use Carp; use Data::Dumper; use Support::TestSetup; use SL::DB::Part; -use SL::Dev::Part; +use SL::Dev::Part qw(new_part); Support::TestSetup::login(); @@ -21,7 +21,7 @@ local $SIG{__WARN__} = sub {}; # test simple transaction -my $part = create_part(); +my $part = new_part(); SL::DB->client->with_transaction(sub { $part->save; ok 1, 'part saved'; @@ -31,7 +31,7 @@ SL::DB->client->with_transaction(sub { }; # test failing transaction -my $part2 = create_part(partnumber => $part->partnumber); # woops, duplicate partnumber +my $part2 = new_part(partnumber => $part->partnumber); # woops, duplicate partnumber SL::DB->client->with_transaction(sub { $part2->save; ok 0, 'part saved'; @@ -55,7 +55,7 @@ dies_ok { # TODO - not possible to test without locally adding hooks in run time # test if error gets correctly stored in db->error -$part2 = create_part(partnumber => $part->partnumber); # woops, duplicate partnumber +$part2 = new_part(partnumber => $part->partnumber); # woops, duplicate partnumber SL::DB->client->with_transaction(sub { $part2->save; ok 0, 'part saved'; diff --git a/t/file/filesystem.t b/t/file/filesystem.t index d35a95faf..8797a1cda 100644 --- a/t/file/filesystem.t +++ b/t/file/filesystem.t @@ -7,7 +7,8 @@ use File::Temp; use Support::TestSetup; use Test::Exception; use SL::File; -use SL::Dev::File; +use SL::Dev::File qw(create_uploaded create_scanned create_created); + Support::TestSetup::login(); @@ -25,12 +26,12 @@ my $scannerfile = "${temp_dir}/f2"; clear_up(); reset_state(); -my $file1 = SL::Dev::File::create_uploaded( file_name => 'file1', file_contents => 'inhalt1 uploaded' ); -my $file2 = SL::Dev::File::create_scanned( file_name => 'file2', file_contents => 'inhalt2 scanned', file_path => $scannerfile ); -my $file3 = SL::Dev::File::create_created( file_name => 'file3', file_contents => 'inhalt3 created' ); -my $file4 = SL::Dev::File::create_created( file_name => 'file3', file_contents => 'inhalt3 new version'); +my $file1 = create_uploaded( file_name => 'file1', file_contents => 'inhalt1 uploaded' ); +my $file2 = create_scanned( file_name => 'file2', file_contents => 'inhalt2 scanned', file_path => $scannerfile ); +my $file3 = create_created( file_name => 'file3', file_contents => 'inhalt3 created' ); +my $file4 = create_created( file_name => 'file3', file_contents => 'inhalt3 new version'); -is( SL::Dev::File->get_all_count(), 3,"total number of files created is 3"); +is( SL::Dev::File::get_all_count(), 3,"total number of files created is 3"); ok( $file1->file_name eq 'file1' ,"file has right name"); my $content1 = $file1->get_content; ok( $$content1 eq 'inhalt1 uploaded' ,"file has right content"); @@ -42,12 +43,12 @@ is( -f $scannerfile ? 1 : 0, 1,"scanned document is mo my $content2 = File::Slurp::read_file($scannerfile); ok( $content2 eq 'inhalt2 scanned' ,"scanned file has right content"); -my @file5 = SL::Dev::File->get_all(file_name => 'file3'); +my @file5 = SL::Dev::File::get_all(file_name => 'file3'); is( scalar( @file5), 1, "one actual file found"); my $content5 = $file5[0]->get_content(); ok( $$content5 eq 'inhalt3 new version' ,"file has right actual content"); -my @file6 = SL::Dev::File->get_all_versions(file_name => 'file3'); +my @file6 = SL::Dev::File::get_all_versions(file_name => 'file3'); is( scalar( @file6), 2,"two file versions found"); $content5 = $file6[0]->get_content; ok( $$content5 eq 'inhalt3 new version' ,"file has right actual content"); @@ -108,7 +109,7 @@ done_testing; sub clear_up { # Cleaning up may fail. eval { - SL::Dev::File->delete_all(); + SL::Dev::File::delete_all(); unlink($scannerfile); }; } diff --git a/t/helper/shipped_qty.t b/t/helper/shipped_qty.t index 0b3ef882a..5d6c70938 100644 --- a/t/helper/shipped_qty.t +++ b/t/helper/shipped_qty.t @@ -18,7 +18,7 @@ use SL::DB::DeliveryOrderItemsStock; use SL::DB::Bin; use SL::WH; use SL::AM; -use SL::Dev::ALL; +use SL::Dev::ALL qw(:ALL); use SL::Helper::ShippedQty; use DateTime; @@ -28,13 +28,13 @@ clear_up(); my ($customer, $vendor, @parts, $unit); -$customer = SL::Dev::CustomerVendor::create_customer(name => 'Testkunde' )->save; -$vendor = SL::Dev::CustomerVendor::create_vendor( name => 'Testlieferant')->save; +$customer = new_customer(name => 'Testkunde' )->save; +$vendor = new_vendor( name => 'Testlieferant')->save; my $default_sellprice = 10; my $default_lastcost = 4; -my ($wh) = SL::Dev::Inventory::create_warehouse_and_bins(); +my ($wh) = create_warehouse_and_bins(); my $bin1 = SL::DB::Manager::Bin->find_by(description => "Bin 1"); my $bin2 = SL::DB::Manager::Bin->find_by(description => "Bin 2"); @@ -46,7 +46,7 @@ my %part_defaults = ( # create 3 parts to be used in test for my $i ( 1 .. 4 ) { - SL::Dev::Part::create_part( %part_defaults, partnumber => $i, description => "part $i test" )->save; + new_part( %part_defaults, partnumber => $i, description => "part $i test" )->save; }; my $part1 = SL::DB::Manager::Part->find_by( partnumber => '1' ); @@ -63,11 +63,11 @@ my %default_transfer_params = ( wh => $wh, bin => $bin1, unit => 'Stck'); note("testing purchases, no fill_up"); -my $purchase_order = SL::Dev::Record::create_purchase_order( +my $purchase_order = create_purchase_order( save => 1, - orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 11), - SL::Dev::Record::create_order_item(part => $part2, qty => 12), - SL::Dev::Record::create_order_item(part => $part3, qty => 13), + orderitems => [ create_order_item(part => $part1, qty => 11), + create_order_item(part => $part2, qty => 12), + create_order_item(part => $part3, qty => 13), ] ); @@ -115,7 +115,7 @@ is($purchase_order->items_sorted->[0]->{shipped_qty}, 0, "require_stock_out => ok(!$purchase_order->items_sorted->[0]->{delivered}, "require_stock_out => 1: first purchase orderitem is not delivered"); # ship items from delivery order -SL::Dev::Inventory::transfer_purchase_delivery_order($purchase_delivery_order); +transfer_purchase_delivery_order($purchase_delivery_order); Rose::DB::Object::Helpers::forget_related($purchase_order, 'orderitems'); $purchase_order->orderitems; @@ -135,11 +135,11 @@ is($purchase_orderitem_part2->shipped_qty(require_stock_out => 1), 11, "OrderIte note('testing sales, no fill_up'); -my $sales_order = SL::Dev::Record::create_sales_order( +my $sales_order = create_sales_order( save => 1, - orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 5), - SL::Dev::Record::create_order_item(part => $part2, qty => 6), - SL::Dev::Record::create_order_item(part => $part3, qty => 7), + orderitems => [ create_order_item(part => $part1, qty => 5), + create_order_item(part => $part2, qty => 6), + create_order_item(part => $part3, qty => 7), ] ); @@ -182,7 +182,7 @@ is($sales_order->items_sorted->[0]->{shipped_qty}, 0, "require_stock_out => 1: ok(!$sales_order->items_sorted->[0]->{delivered}, "require_stock_out => 1: first sales orderitem is not delivered"); # ship items from delivery order -SL::Dev::Inventory::transfer_sales_delivery_order($sales_delivery_order); +transfer_sales_delivery_order($sales_delivery_order); Rose::DB::Object::Helpers::forget_related($sales_order, 'orderitems'); $sales_order->orderitems; diff --git a/t/part/assembly.t b/t/part/assembly.t index 197dfb580..6500dfa5c 100644 --- a/t/part/assembly.t +++ b/t/part/assembly.t @@ -7,7 +7,7 @@ use Test::Exception; use SL::DB::Unit; use SL::DB::Part; use SL::DB::Assembly; -use SL::Dev::Part; +use SL::Dev::Part qw(new_assembly); use SL::DB::Helper::ValidateAssembly; Support::TestSetup::login(); @@ -32,13 +32,13 @@ is($assembly_item->assembly_part->partnumber, '19000', 'assembly part assembly p -my $assembly2_part = SL::Dev::Part::create_assembly( partnumber => '20000', assnumber => 'as2' )->save; +my $assembly2_part = new_assembly( partnumber => '20000', assnumber => 'as2' )->save; my $retval = validate_assembly($assembly_part,$assembly2_part); ok(!defined $retval, 'assembly 19000 can be child of assembly 20000' ); $assembly2_part->add_assemblies(SL::DB::Assembly->new(parts_id => $assembly_part->id, qty => 3, bom => 1)); $assembly2_part->save; -my $assembly3_part = SL::Dev::Part::create_assembly( partnumber => '30000', assnumber => 'as3' )->save; +my $assembly3_part = new_assembly( partnumber => '30000', assnumber => 'as3' )->save; $retval = validate_assembly($assembly3_part,$assembly_part); ok(!defined $retval, 'assembly 30000 can be child of assembly 19000' ); @@ -92,7 +92,7 @@ sub clear_up { sub reset_state { my %params = @_; - my $assembly = SL::Dev::Part::create_assembly( assnumber => '19000', partnumber => '19000' )->save; + my $assembly = new_assembly( assnumber => '19000', partnumber => '19000' )->save; }; 1; diff --git a/t/part/assortment.t b/t/part/assortment.t index 3d6705e3a..46e35de3d 100644 --- a/t/part/assortment.t +++ b/t/part/assortment.t @@ -6,15 +6,15 @@ use Support::TestSetup; use Carp; use Test::Exception; use SL::DB::Part; -use SL::Dev::Part; +use SL::Dev::Part qw(new_assortment); Support::TestSetup::login(); clear_up(); -my $assortment = SL::Dev::Part::create_assortment( assnumber => 'aso1', - description => "Assortment 1", - number_of_parts => 10, +my $assortment = new_assortment( assnumber => 'aso1', + description => "Assortment 1", + number_of_parts => 10, )->save; is( SL::DB::Manager::Part->get_all_count(), 11, "total number of parts created is 11"); diff --git a/t/part/stock.t b/t/part/stock.t index 583aefe4b..39e575665 100644 --- a/t/part/stock.t +++ b/t/part/stock.t @@ -6,20 +6,20 @@ use Support::TestSetup; use Carp; use Test::Exception; use SL::DB::Part; -use SL::Dev::Part; -use SL::Dev::Inventory; +use SL::Dev::Part qw(new_part); +use SL::Dev::Inventory qw(create_warehouse_and_bins set_stock transfer_stock); Support::TestSetup::login(); clear_up(); -my ($wh1, $bin1_1) = SL::Dev::Inventory::create_warehouse_and_bins( +my ($wh1, $bin1_1) = create_warehouse_and_bins( warehouse_description => 'Testlager', bin_description => 'Testlagerplatz', number_of_bins => 2, ); my $bin1_2 = $wh1->bins->[1]; -my ($wh2, $bin2_1) = SL::Dev::Inventory::create_warehouse_and_bins( +my ($wh2, $bin2_1) = create_warehouse_and_bins( warehouse_description => 'Testlager 2', bin_description => 'Testlagerplatz 2', number_of_bins => 2, @@ -28,18 +28,18 @@ my ($wh2, $bin2_1) = SL::Dev::Inventory::create_warehouse_and_bins( my $today = DateTime->today; my $yesterday = $today->clone->add(days => -1); -my $part = SL::Dev::Part::create_part->save; -SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_1->id, qty => 7, shippingdate => $yesterday); -SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_1->id, qty => 5); -SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_1->id, abs_qty => 8); # apply -4 to get qty 8 in bin1_1 -SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin1_2->id, qty => 9); - -SL::Dev::Inventory::set_stock(part => $part, bin_id => $bin2_1->id, abs_qty => 10); -SL::Dev::Inventory::transfer_stock(part => $part, - from_bin => $wh2->bins->[0], - to_bin => $wh2->bins->[1], - qty => 2, - ); +my $part = new_part()->save; +set_stock(part => $part, bin_id => $bin1_1->id, qty => 7, shippingdate => $yesterday); +set_stock(part => $part, bin_id => $bin1_1->id, qty => 5); +set_stock(part => $part, bin_id => $bin1_1->id, abs_qty => 8); # apply -4 to get qty 8 in bin1_1 +set_stock(part => $part, bin_id => $bin1_2->id, qty => 9); + +set_stock(part => $part, bin_id => $bin2_1->id, abs_qty => 10); +transfer_stock(part => $part, + from_bin => $wh2->bins->[0], + to_bin => $wh2->bins->[1], + qty => 2, + ); is( SL::DB::Manager::Part->get_all_count(), 1, "total number of parts created is 1"); is( $part->get_stock == 27 , 1 , "total stock of part is 27"); diff --git a/t/wh/transfer.t b/t/wh/transfer.t index c3cf1e5fc..b85cd68ce 100644 --- a/t/wh/transfer.t +++ b/t/wh/transfer.t @@ -3,7 +3,7 @@ use Test::More; use lib 't'; -use SL::Dev::Part; +use SL::Dev::Part qw(new_part); use_ok 'Support::TestSetup'; use_ok 'SL::DB::Bin'; @@ -28,7 +28,7 @@ SL::DB::Manager::Bin ->delete_all(where => [ or => [ description => NAME() SL::DB::Manager::Warehouse->delete_all(where => [ description => NAME() ]); # Create test data -$part = SL::Dev::Part::create_part(unit => 'mg', description => NAME(), partnumber => NAME())->save(); +$part = new_part(unit => 'mg', description => NAME(), partnumber => NAME())->save(); is(ref($part), 'SL::DB::Part', 'loading a part to test with id ' . $part->id);