Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6e0fe1dc

Von Kivitendo Admin vor fast 8 Jahren hinzugefügt

  • ID 6e0fe1dc46a643b80c36b21c4cb62c2f09227f45
  • Vorgänger f12c42cf
  • Nachfolger fb11389a

SL/Dev/CustomerVendor um create_vendor erweitert

Unterschiede anzeigen:

SL/Dev/CustomerVendor.pm
11 11
sub create_customer {
12 12
  my (%params) = @_;
13 13

  
14
  my ($taxzone, $currency);
14
  my $taxzone    = _check_taxzone(delete $params{taxzone_id});
15
  my $currency   = _check_currency(delete $params{currency_id});
15 16

  
16
  if ( my $taxzone_id = delete $params{taxzone_id} ) {
17
  my $customer = SL::DB::Customer->new( name        => delete $params{name} || 'Testkunde',
18
                                        currency_id => $currency->id,
19
                                        taxzone_id  => $taxzone->id,
20
                                      );
21
  $customer->assign_attributes( %params );
22
  return $customer;
23
}
24

  
25
sub create_vendor {
26
  my (%params) = @_;
27

  
28
  my $taxzone    = _check_taxzone(delete $params{taxzone_id});
29
  my $currency   = _check_currency(delete $params{currency_id});
30

  
31
  my $vendor = SL::DB::Vendor->new( name        => delete $params{name} || 'Testlieferant',
32
                                    currency_id => $currency->id,
33
                                    taxzone_id  => $taxzone->id,
34
                                  );
35
  $vendor->assign_attributes( %params );
36
  return $vendor;
37
}
38

  
39
sub _check_taxzone {
40
  my ($taxzone_id) = @_;
41
  # check that taxzone_id exists or if no taxzone_id passed use 'Inland'
42
  my $taxzone;
43
  if ( $taxzone_id ) {
17 44
    $taxzone = SL::DB::Manager::TaxZone->find_by( id => $taxzone_id ) || die "Can't find taxzone_id";
18 45
  } else {
19 46
    $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || die "No taxzone 'Inland'";
20 47
  }
48
  return $taxzone;
49
}
21 50

  
22
  if ( my $currency_id = delete $params{currency_id} ) {
51
sub _check_currency {
52
  my ($currency_id) = @_;
53
  my $currency;
54
  if ( $currency_id ) {
23 55
    $currency = SL::DB::Manager::Currency->find_by( id => $currency_id ) || die "Can't find currency_id";
24 56
  } else {
25 57
    $currency = SL::DB::Manager::Currency->find_by( id => $::instance_conf->get_currency_id );
26 58
  }
27

  
28
  my $customer = SL::DB::Customer->new( name        => delete $params{name} || 'Testkunde',
29
                                        currency_id => $currency->id,
30
                                        taxzone_id  => $taxzone->id,
31
                                      );
32
  $customer->assign_attributes( %params );
33
  return $customer;
59
  return $currency;
34 60
}
35 61

  
36 62
1;
......
58 84
                                           taxzone_id  => 2,
59 85
                                          )->save;
60 86

  
87
If neither taxzone_id or currency_id (both are NOT NULL) are passed as params
88
then default values are used.
89

  
90
=head2 C<create_vendor %PARAMS>
91

  
92
Creates a new vendor.
93

  
94
Minimal usage, default values, without saving to database:
95

  
96
  my $vendor = SL::Dev::vendorVendor::create_vendor();
97

  
98
Complex usage, overwriting some defaults, and save to database:
99

  
100
  SL::Dev::CustomerVendor::create_vendor(name        => 'Test vendor',
101
                                         taxzone_id  => 2,
102
                                         notes       => "Order for 100$ for free delivery",
103
                                        )->save;
61 104

  
62 105
=head1 BUGS
63 106

  

Auch abrufbar als: Unified diff