kivitendo/SL/Dev/CustomerVendor.pm @ 8f140730
ec1dc3e8 | Geoffrey Richardson | package SL::Dev::CustomerVendor;
|
||
8d4130ed | Sven Schöling | use strict;
|
||
ec1dc3e8 | Geoffrey Richardson | use base qw(Exporter);
|
||
8d4130ed | Sven Schöling | our @EXPORT = qw(create_customer);
|
||
ec1dc3e8 | Geoffrey Richardson | |||
use SL::DB::TaxZone;
|
||||
use SL::DB::Currency;
|
||||
use SL::DB::Customer;
|
||||
sub create_customer {
|
||||
my (%params) = @_;
|
||||
6e0fe1dc | Geoffrey Richardson | my $taxzone = _check_taxzone(delete $params{taxzone_id});
|
||
my $currency = _check_currency(delete $params{currency_id});
|
||||
ec1dc3e8 | Geoffrey Richardson | |||
6e0fe1dc | Geoffrey Richardson | my $customer = SL::DB::Customer->new( name => delete $params{name} || 'Testkunde',
|
||
currency_id => $currency->id,
|
||||
taxzone_id => $taxzone->id,
|
||||
);
|
||||
$customer->assign_attributes( %params );
|
||||
return $customer;
|
||||
}
|
||||
sub create_vendor {
|
||||
my (%params) = @_;
|
||||
my $taxzone = _check_taxzone(delete $params{taxzone_id});
|
||||
my $currency = _check_currency(delete $params{currency_id});
|
||||
my $vendor = SL::DB::Vendor->new( name => delete $params{name} || 'Testlieferant',
|
||||
currency_id => $currency->id,
|
||||
taxzone_id => $taxzone->id,
|
||||
);
|
||||
$vendor->assign_attributes( %params );
|
||||
return $vendor;
|
||||
}
|
||||
sub _check_taxzone {
|
||||
my ($taxzone_id) = @_;
|
||||
# check that taxzone_id exists or if no taxzone_id passed use 'Inland'
|
||||
my $taxzone;
|
||||
if ( $taxzone_id ) {
|
||||
ec1dc3e8 | Geoffrey Richardson | $taxzone = SL::DB::Manager::TaxZone->find_by( id => $taxzone_id ) || die "Can't find taxzone_id";
|
||
} else {
|
||||
$taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || die "No taxzone 'Inland'";
|
||||
}
|
||||
6e0fe1dc | Geoffrey Richardson | return $taxzone;
|
||
}
|
||||
ec1dc3e8 | Geoffrey Richardson | |||
6e0fe1dc | Geoffrey Richardson | sub _check_currency {
|
||
my ($currency_id) = @_;
|
||||
my $currency;
|
||||
if ( $currency_id ) {
|
||||
ec1dc3e8 | Geoffrey Richardson | $currency = SL::DB::Manager::Currency->find_by( id => $currency_id ) || die "Can't find currency_id";
|
||
} else {
|
||||
$currency = SL::DB::Manager::Currency->find_by( id => $::instance_conf->get_currency_id );
|
||||
}
|
||||
6e0fe1dc | Geoffrey Richardson | return $currency;
|
||
ec1dc3e8 | Geoffrey Richardson | }
|
||
1;
|
||||
__END__
|
||||
=head1 NAME
|
||||
SL::Dev::CustomerVendor - create customer and vendor objects for testing, with minimal defaults
|
||||
=head1 FUNCTIONS
|
||||
=head2 C<create_customer %PARAMS>
|
||||
Creates a new customer.
|
||||
Minimal usage, default values, without saving to database:
|
||||
my $customer = SL::Dev::CustomerVendor::create_customer();
|
||||
Complex usage, overwriting some defaults, and save to database:
|
||||
009c62da | Sven Schöling | |||
ec1dc3e8 | Geoffrey Richardson | SL::Dev::CustomerVendor::create_customer(name => 'Test customer',
|
||
hourly_rate => 50,
|
||||
taxzone_id => 2,
|
||||
)->save;
|
||||
6e0fe1dc | Geoffrey Richardson | 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>
|
||||
Creates a new vendor.
|
||||
Minimal usage, default values, without saving to database:
|
||||
3ea2fdd1 | Geoffrey Richardson | my $vendor = SL::Dev::CustomerVendor::create_vendor();
|
||
6e0fe1dc | Geoffrey Richardson | |||
Complex usage, overwriting some defaults, and save to database:
|
||||
SL::Dev::CustomerVendor::create_vendor(name => 'Test vendor',
|
||||
taxzone_id => 2,
|
||||
notes => "Order for 100$ for free delivery",
|
||||
)->save;
|
||||
ec1dc3e8 | Geoffrey Richardson | |||
=head1 BUGS
|
||||
Nothing here yet.
|
||||
=head1 AUTHOR
|
||||
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
|
||||
=cut
|