From: Sven Schöling Date: Tue, 22 Aug 2017 14:23:37 +0000 (+0200) Subject: SL::Dev: EXPORT rewrite und create/new split X-Git-Tag: release-3.5.4~876 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=cf3a8cf79ac2f6228b298ef260f3471490c3132b;p=kivitendo-erp.git SL::Dev: EXPORT rewrite und create/new split - SL::Dev module exportieren nicht mehr ungefragt - SL::Dev::ALL exportiert jetzt den übergebenen tag aus allen Modulen - Funktionen nicht nicht speichern (Part/CustomerVendor) heißen jetzt "new_X" anstatt "create_X" --- diff --git a/SL/Dev/ALL.pm b/SL/Dev/ALL.pm index 988ab8134..aa0e8ba15 100644 --- a/SL/Dev/ALL.pm +++ b/SL/Dev/ALL.pm @@ -2,12 +2,21 @@ package SL::Dev::ALL; use strict; +use Exporter; use SL::Dev::Part; use SL::Dev::CustomerVendor; use SL::Dev::Inventory; use SL::Dev::Record; use SL::Dev::Payment; +sub import { + no strict "refs"; + for (qw(Part CustomerVendor Inventory Record Payment)) { + Exporter::export_to_level("SL::Dev::$_", 1, @_); + } +} + + 1; __END__ diff --git a/SL/Dev/CustomerVendor.pm b/SL/Dev/CustomerVendor.pm index 6bf976e45..0ea6263ef 100644 --- a/SL/Dev/CustomerVendor.pm +++ b/SL/Dev/CustomerVendor.pm @@ -2,13 +2,14 @@ package SL::Dev::CustomerVendor; use strict; use base qw(Exporter); -our @EXPORT = qw(create_customer create_vendor); +our @EXPORT_OK = qw(new_customer new_vendor); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use SL::DB::TaxZone; use SL::DB::Currency; use SL::DB::Customer; -sub create_customer { +sub new_customer { my (%params) = @_; my $taxzone = _check_taxzone(delete $params{taxzone_id}); @@ -22,7 +23,7 @@ sub create_customer { return $customer; } -sub create_vendor { +sub new_vendor { my (%params) = @_; my $taxzone = _check_taxzone(delete $params{taxzone_id}); @@ -69,7 +70,7 @@ SL::Dev::CustomerVendor - create customer and vendor objects for testing, with m =head1 FUNCTIONS -=head2 C +=head2 C Creates a new customer. @@ -87,7 +88,7 @@ Complex usage, overwriting some defaults, and save to database: If neither taxzone_id or currency_id (both are NOT NULL) are passed as params then default values are used. -=head2 C +=head2 C Creates a new vendor. diff --git a/SL/Dev/File.pm b/SL/Dev/File.pm index ff1ea116d..62228ea9e 100644 --- a/SL/Dev/File.pm +++ b/SL/Dev/File.pm @@ -2,10 +2,16 @@ package SL::Dev::File; use strict; use base qw(Exporter); -our @EXPORT = qw(create_scanned create_uploaded create_created get_all_count get_all get_all_versions delete_all); +our @EXPORT_OK = qw(create_scanned create_uploaded create_created); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use SL::DB::File; +my %common_params = ( + object_id => 1, + object_type => 'sales_order', +); + sub create_scanned { my (%params) = @_; $params{source} = 'scanner1'; @@ -38,8 +44,7 @@ sub _create_file { my (%params) = @_; my $fileobj = SL::File->save( - object_id => 1, - object_type => 'sales_order', + %common_params, mime_type => 'text/plain', description => 'Test File', file_type => $params{file_type}, @@ -51,33 +56,11 @@ sub _create_file { return $fileobj; } -sub get_all_count { - my ($class,%params) = @_; - $params{object_id} = 1; - $params{object_type} = 'sales_order'; - return SL::File->get_all_count(%params); -} - -sub get_all { - my ($class,%params) = @_; - $params{object_id} = 1; - $params{object_type} = 'sales_order'; - SL::File->get_all(%params); -} - -sub get_all_versions { - my ($class,%params) = @_; - $params{object_id} = 1; - $params{object_type} = 'sales_order'; - SL::File->get_all_versions(%params); -} +sub get_all { SL::File->get_all (%common_params, @_) } +sub get_all_count { SL::File->get_all_count (%common_params, @_) } +sub get_all_versions { SL::File->get_all_versions(%common_params, @_) } +sub delete_all { SL::File->delete_all (%common_params, @_) } -sub delete_all { - my ($class,%params) = @_; - $params{object_id} = 1; - $params{object_type} = 'sales_order'; - SL::File->delete_all(%params); -} 1; __END__ @@ -94,8 +77,6 @@ SL::Dev::File - create file objects for testing, with minimal defaults =head2 C -=head2 C - =head1 AUTHOR Martin Helmling Emartin.helmling@opendynamic.deE diff --git a/SL/Dev/Inventory.pm b/SL/Dev/Inventory.pm index e7aaee5e8..4432d86c8 100644 --- a/SL/Dev/Inventory.pm +++ b/SL/Dev/Inventory.pm @@ -2,11 +2,12 @@ package SL::Dev::Inventory; use strict; use base qw(Exporter); -our @EXPORT = qw( +our @EXPORT_OK = qw( create_warehouse_and_bins set_stock transfer_stock transfer_sales_delivery_order transfer_purchase_delivery_order transfer_delivery_order_item transfer_in transfer_out ); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use SL::DB::Warehouse; use SL::DB::Bin; diff --git a/SL/Dev/Part.pm b/SL/Dev/Part.pm index 45976b6f2..aa69c0d7b 100644 --- a/SL/Dev/Part.pm +++ b/SL/Dev/Part.pm @@ -2,13 +2,14 @@ package SL::Dev::Part; use strict; use base qw(Exporter); -our @EXPORT = qw(create_part create_service create_assembly create_assortment); +our @EXPORT_OK = qw(new_part new_service new_assembly new_assortment); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use SL::DB::Part; use SL::DB::Unit; use SL::DB::Buchungsgruppe; -sub create_part { +sub new_part { my (%params) = @_; my $part = SL::DB::Part->new_part( @@ -22,7 +23,7 @@ sub create_part { return $part; } -sub create_service { +sub new_service { my (%params) = @_; my $part = SL::DB::Part->new_service( @@ -36,7 +37,7 @@ sub create_service { return $part; } -sub create_assembly { +sub new_assembly { my (%params) = @_; my $assnumber = delete $params{assnumber}; @@ -48,9 +49,9 @@ sub create_assembly { $assembly_items = delete $params{assembly_items}; } else { for my $i ( 1 .. delete $params{number_of_parts} || 3) { - my $part = SL::Dev::Part::create_part(partnumber => "$base_partnumber $i", - description => "Testpart $i", - )->save; + my $part = new_part(partnumber => "$base_partnumber $i", + description => "Testpart $i", + )->save; push( @{$assembly_items}, SL::DB::Assembly->new(parts_id => $part->id, qty => 1, position => $i, @@ -71,7 +72,7 @@ sub create_assembly { return $assembly; } -sub create_assortment { +sub new_assortment { my (%params) = @_; my $assnumber = delete $params{assnumber}; @@ -83,9 +84,9 @@ sub create_assortment { $assortment_items = delete $params{assortment_items}; } else { for my $i ( 1 .. delete $params{number_of_parts} || 3) { - my $part = SL::Dev::Part::create_part(partnumber => "$base_partnumber $i", - description => "Testpart $i", - )->save; + my $part = new_part(partnumber => "$base_partnumber $i", + description => "Testpart $i", + )->save; push( @{$assortment_items}, SL::DB::AssortmentItem->new(parts_id => $part->id, qty => 1, position => $i, @@ -126,87 +127,121 @@ __END__ SL::Dev::Part - create part objects for testing, with minimal defaults +=head1 SYNOPSIS + + use SL::DEV::Part qw(new_part new_assembly new_service new_assortment); + + # simple default objects + my $part = new_part()->save; + my $assembly = new_assembly()->save; + my $service = new_service()->save; + my $assortment = new_assortment()->save; + + # pass additional params to the generated object + # see individual functions for special parameters + my $part = new_part( + partnumber => 'Test 001', + warehouse_id => $bin->warehouse->id, + bin_id => $bin->id, + ); + =head1 FUNCTIONS -=head2 C +=head2 C Creates a new part (part_type = part). -Minimal usage, default values, without saving to database: +=head2 C + +Creates a new service (part_type = service). - my $part = SL::Dev::Part::create_part(); +=head2 C -Create a test part with a default warehouse and bin and save it: +Create a new assembly (part_type = assembly). - my $wh = SL::Dev::Inventory::create_warehouse_and_bins()->save; - my $part1 = SL::Dev::Part::create_part(partnumber => 'a123', - description => 'Testpart 1', - warehouse_id => $wh->id, - bin_id => $wh->bins->[0]->id, - )->save; +Special params: -=head2 C +=over 2 -Creates a new service (part_type = service). +=item * C -Minimal usage, default values, without saving to database: +The number of automatically created assembly parts. - my $part = SL::Dev::Part::create_service(); +=item * C -=head2 C +the partnumber of the assembly -Create a new assembly (part_type = assembly). +=item * C -Params: assnumber: the partnumber of the assembly - partnumber: the partnumber of the first assembly part to be created +the partnumber of the first assembly part to be created -By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1). +=back - my $assembly = SL::Dev::Part::create_assembly->save; +By default 3 parts (p1, p2, p3) are created and saved as an assembly (as1). Create a new assembly with 10 parts, the assembly gets partnumber 'Ass1' and the parts get partnumbers 'Testpart 1' to 'Testpart 10': - my $assembly = SL::Dev::Part::create_assembly(number_of_parts => 10, - partnumber => 'Testpart', - assnumber => 'Ass1' - )->save; + my $assembly = SL::Dev::Part::new_assembly( + number_of_parts => 10, + partnumber => 'Testpart', + assnumber => 'Ass1' + )->save; Create an assembly with specific parts: + my $assembly_item_1 = SL::DB::Assembly->new( parts_id => $part1->id, qty => 3, position => 1); my $assembly_item_2 = SL::DB::Assembly->new( parts_id => $part2->id, qty => 3, position => 2); - my $assembly_part = SL::Dev::Part::create_assembly( assnumber => 'Assembly 1', - description => 'Assembly test', - sellprice => $part1->sellprice + $part2->sellprice, - assembly_items => [ $assembly_item_1, $assembly_item_2 ], - )->save; + my $assembly_part = new_assembly( + assnumber => 'Assembly 1', + description => 'Assembly test', + sellprice => $part1->sellprice + $part2->sellprice, + assembly_items => [ $assembly_item_1, $assembly_item_2 ], + ); -=head2 C +=head2 C Create a new assortment (part_type = assortment). -By default 3 parts (p1, p2, p3) are created and saved as an assortment. +Special params: + +=over 2 + +=item * C + +The number of automatically created assembly parts. - my $assortment = SL::Dev::Part::create_assortment->save; +=item * C + +the partnumber of the assortment + +=item * C + +the partnumber of the first assembly part to be created + +=back + +By default 3 parts (p1, p2, p3) are created and saved as an assortment. Create a new assortment with 10 automatically created parts using the number_of_parts param: - my $assortment = SL::Dev::Part::create_assortment(number_of_parts => 10)->save; + my $assortment = new_assortment(number_of_parts => 10)->save; Create an assortment with a certain name and pass some assortment_item Objects from newly created parts: - my $part1 = SL::Dev::Part::create_part( sellprice => '7.77')->save; - my $part2 = SL::Dev::Part::create_part( sellprice => '6.66')->save; + my $part1 = new_part(sellprice => 7.77)->save; + my $part2 = new_part(sellprice => 6.66)->save; my $assortment_item_1 = SL::DB::AssortmentItem->new( parts_id => $part1->id, qty => 3, unit => $part1->unit, position => 1); my $assortment_item_2 = SL::DB::AssortmentItem->new( parts_id => $part2->id, qty => 3, unit => $part2->unit, position => 2); - my $assortment_part = SL::Dev::Part::create_assortment( assnumber => 'Assortment 1', - description => 'assortment test', - sellprice => (3*$part1->sellprice + 3*$part2->sellprice), - lastcost => (3*$part1->lastcost + 3*$part2->lastcost), - assortment_items => [ $assortment_item_1, $assortment_item_2 ], - )->save; + my $assortment_part = SL::Dev::Part::new_assortment( + assnumber => 'Assortment 1', + description => 'assortment test', + sellprice => (3*$part1->sellprice + 3*$part2->sellprice), + lastcost => (3*$part1->lastcost + 3*$part2->lastcost), + assortment_items => [ $assortment_item_1, $assortment_item_2 ], + )->save; =head1 TODO diff --git a/SL/Dev/Payment.pm b/SL/Dev/Payment.pm index d932013fa..0fdb3a4aa 100644 --- a/SL/Dev/Payment.pm +++ b/SL/Dev/Payment.pm @@ -2,7 +2,8 @@ package SL::Dev::Payment; use strict; use base qw(Exporter); -our @EXPORT = qw(create_payment_terms create_bank_account create_bank_transaction); +our @EXPORT_OK = qw(create_payment_terms create_bank_account create_bank_transaction create_sepa_export create_sepa_export_item); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use SL::DB::PaymentTerm; use SL::DB::BankAccount; diff --git a/SL/Dev/Record.pm b/SL/Dev/Record.pm index ae60ade64..5fbbd8738 100644 --- a/SL/Dev/Record.pm +++ b/SL/Dev/Record.pm @@ -2,13 +2,14 @@ package SL::Dev::Record; use strict; use base qw(Exporter); -our @EXPORT = qw(create_invoice_item create_sales_invoice create_credit_note create_order_item create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_purchase_delivery_order create_project); +our @EXPORT_OK = qw(create_invoice_item create_sales_invoice create_credit_note create_order_item create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_purchase_delivery_order create_project); +our %EXPORT_TAGS = (ALL => \@EXPORT_OK); use SL::DB::Invoice; use SL::DB::InvoiceItem; use SL::DB::Employee; -use SL::Dev::Part; -use SL::Dev::CustomerVendor; +use SL::Dev::Part qw(new_part); +use SL::Dev::CustomerVendor qw(new_vendor new_customer); use SL::DB::Project; use SL::DB::ProjectStatus; use SL::DB::ProjectType; @@ -28,7 +29,7 @@ sub create_sales_invoice { my $invoiceitems = delete $params{invoiceitems} // _create_two_items($record_type); _check_items($invoiceitems, $record_type); - my $customer = delete $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save; + my $customer = delete $params{customer} // new_customer(name => 'Testcustomer')->save; die "illegal customer" unless defined $customer && ref($customer) eq 'SL::DB::Customer'; my $invoice = SL::DB::Invoice->new( @@ -59,7 +60,7 @@ sub create_credit_note { my $invoiceitems = delete $params{invoiceitems} // _create_two_items($record_type); _check_items($invoiceitems, $record_type); - my $customer = delete $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save; + my $customer = delete $params{customer} // new_customer(name => 'Testcustomer')->save; die "illegal customer" unless defined $customer && ref($customer) eq 'SL::DB::Customer'; # adjust qty for credit note items @@ -93,7 +94,7 @@ sub create_sales_delivery_order { my $orderitems = delete $params{orderitems} // _create_two_items($record_type); _check_items($orderitems, $record_type); - my $customer = $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save; + my $customer = $params{customer} // new_customer(name => 'Testcustomer')->save; die "illegal customer" unless ref($customer) eq 'SL::DB::Customer'; my $delivery_order = SL::DB::DeliveryOrder->new( @@ -121,7 +122,7 @@ sub create_purchase_delivery_order { my $orderitems = delete $params{orderitems} // _create_two_items($record_type); _check_items($orderitems, $record_type); - my $vendor = $params{vendor} // SL::Dev::CustomerVendor::create_vendor(name => 'Testvendor')->save; + my $vendor = $params{vendor} // new_vendor(name => 'Testvendor')->save; die "illegal customer" unless ref($vendor) eq 'SL::DB::Vendor'; my $delivery_order = SL::DB::DeliveryOrder->new( @@ -151,7 +152,7 @@ sub create_sales_order { my $save = delete $params{save} // 0; - my $customer = $params{customer} // SL::Dev::CustomerVendor::create_customer(name => 'Testcustomer')->save; + my $customer = $params{customer} // new_customer(name => 'Testcustomer')->save; die "illegal customer" unless ref($customer) eq 'SL::DB::Customer'; my $order = SL::DB::Order->new( @@ -182,7 +183,7 @@ sub create_purchase_order { my $save = delete $params{save} // 0; - my $vendor = $params{vendor} // SL::Dev::CustomerVendor::create_vendor(name => 'Testvendor')->save; + my $vendor = $params{vendor} // new_vendor(name => 'Testvendor')->save; die "illegal vendor" unless ref($vendor) eq 'SL::DB::Vendor'; my $order = SL::DB::Order->new( @@ -263,12 +264,12 @@ sub _create_item { sub _create_two_items { my ($record_type) = @_; - my $part1 = SL::Dev::Part::create_part(description => 'Testpart 1', - sellprice => 12, - )->save; - my $part2 = SL::Dev::Part::create_part(description => 'Testpart 2', - sellprice => 10, - )->save; + my $part1 = new_part(description => 'Testpart 1', + sellprice => 12, + )->save; + my $part2 = new_part(description => 'Testpart 2', + sellprice => 10, + )->save; my $item1 = _create_item(record_type => $record_type, part => $part1, qty => 5); my $item2 = _create_item(record_type => $record_type, part => $part2, qty => 8); return [ $item1, $item2 ];