Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision cf3a8cf7

Von Sven Schöling vor mehr als 7 Jahren hinzugefügt

  • ID cf3a8cf79ac2f6228b298ef260f3471490c3132b
  • Vorgänger c878cea9
  • Nachfolger 63410aa6

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"

Unterschiede anzeigen:

SL/Dev/ALL.pm
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__
SL/Dev/CustomerVendor.pm
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});
......
return $customer;
}
sub create_vendor {
sub new_vendor {
my (%params) = @_;
my $taxzone = _check_taxzone(delete $params{taxzone_id});
......
=head1 FUNCTIONS
=head2 C<create_customer %PARAMS>
=head2 C<new_customer %PARAMS>
Creates a new customer.
......
If neither taxzone_id or currency_id (both are NOT NULL) are passed as params
then default values are used.
=head2 C<create_vendor %PARAMS>
=head2 C<new_vendor %PARAMS>
Creates a new vendor.
SL/Dev/File.pm
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';
......
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},
......
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__
......
=head2 C<create_created %PARAMS>
=head2 C<delete_all>
=head1 AUTHOR
Martin Helmling E<lt>martin.helmling@opendynamic.deE<gt>
SL/Dev/Inventory.pm
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;
SL/Dev/Part.pm
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(
......
return $part;
}
sub create_service {
sub new_service {
my (%params) = @_;
my $part = SL::DB::Part->new_service(
......
return $part;
}
sub create_assembly {
sub new_assembly {
my (%params) = @_;
my $assnumber = delete $params{assnumber};
......
$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,
......
return $assembly;
}
sub create_assortment {
sub new_assortment {
my (%params) = @_;
my $assnumber = delete $params{assnumber};
......
$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,
......
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<create_part %PARAMS>
=head2 C<new_part %PARAMS>
Creates a new part (part_type = part).
Minimal usage, default values, without saving to database:
=head2 C<new_service %PARAMS>
Creates a new service (part_type = service).
my $part = SL::Dev::Part::create_part();
=head2 C<new_assembly %PARAMS>
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<create_service %PARAMS>
=over 2
Creates a new service (part_type = service).
=item * C<number_of_parts>
Minimal usage, default values, without saving to database:
The number of automatically created assembly parts.
my $part = SL::Dev::Part::create_service();
=item * C<assnumber>
=head2 C<create_assembly %PARAMS>
the partnumber of the assembly
Create a new assembly (part_type = assembly).
=item * C<partnumber>
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<create_assortment %PARAMS>
=head2 C<new_assortment %PARAMS>
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<number_of_parts>
The number of automatically created assembly parts.
my $assortment = SL::Dev::Part::create_assortment->save;
=item * C<assnumber>
the partnumber of the assortment
=item * C<partnumber>
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
SL/Dev/Payment.pm
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;
SL/Dev/Record.pm
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;
......
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(
......
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
......
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(
......
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(
......
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(
......
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(
......
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 ];

Auch abrufbar als: Unified diff