397b7fa5cf59907b107106e42ab7507d79712921
[kivitendo-erp.git] / SL / DB / Order.pm
1 package SL::DB::Order;
2
3 use utf8;
4 use strict;
5
6 use Carp;
7 use DateTime;
8 use List::Util qw(max);
9 use List::MoreUtils qw(any);
10
11 use SL::DB::MetaSetup::Order;
12 use SL::DB::Manager::Order;
13 use SL::DB::Helper::Attr;
14 use SL::DB::Helper::AttrHTML;
15 use SL::DB::Helper::AttrSorted;
16 use SL::DB::Helper::FlattenToForm;
17 use SL::DB::Helper::LinkedRecords;
18 use SL::DB::Helper::PriceTaxCalculator;
19 use SL::DB::Helper::PriceUpdater;
20 use SL::DB::Helper::TransNumberGenerator;
21 use SL::Locale::String qw(t8);
22 use SL::RecordLinks;
23 use Rose::DB::Object::Helpers qw(as_tree);
24
25 __PACKAGE__->meta->add_relationship(
26   orderitems => {
27     type         => 'one to many',
28     class        => 'SL::DB::OrderItem',
29     column_map   => { id => 'trans_id' },
30     manager_args => {
31       with_objects => [ 'part' ]
32     }
33   },
34   periodic_invoices_config => {
35     type                   => 'one to one',
36     class                  => 'SL::DB::PeriodicInvoicesConfig',
37     column_map             => { id => 'oe_id' },
38   },
39   custom_shipto            => {
40     type                   => 'one to one',
41     class                  => 'SL::DB::Shipto',
42     column_map             => { id => 'trans_id' },
43     query_args             => [ module => 'OE' ],
44   },
45   exchangerate_obj         => {
46     type                   => 'one to one',
47     class                  => 'SL::DB::Exchangerate',
48     column_map             => { currency_id => 'currency_id', transdate => 'transdate' },
49   },
50 );
51
52 SL::DB::Helper::Attr::make(__PACKAGE__, daily_exchangerate => 'numeric');
53
54 __PACKAGE__->meta->initialize;
55
56 __PACKAGE__->attr_html('notes');
57 __PACKAGE__->attr_sorted('items');
58
59 __PACKAGE__->before_save('_before_save_set_ord_quo_number');
60 __PACKAGE__->before_save('_before_save_create_new_project');
61 __PACKAGE__->before_save('_before_save_remove_empty_custom_shipto');
62 __PACKAGE__->before_save('_before_save_set_custom_shipto_module');
63
64 # hooks
65
66 sub _before_save_set_ord_quo_number {
67   my ($self) = @_;
68
69   # ordnumber is 'NOT NULL'. Therefore make sure it's always set to at
70   # least an empty string, even if we're saving a quotation.
71   $self->ordnumber('') if !$self->ordnumber;
72
73   my $field = $self->quotation ? 'quonumber' : 'ordnumber';
74   $self->create_trans_number if !$self->$field;
75
76   return 1;
77 }
78 sub _before_save_create_new_project {
79   my ($self) = @_;
80
81   # force new project, if not set yet
82   if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq 'sales_order')) {
83
84     die t8("Error while creating project with project number of new order number, project number #1 already exists!", $self->ordnumber)
85       if SL::DB::Manager::Project->find_by(projectnumber => $self->ordnumber);
86
87     eval {
88       my $new_project = SL::DB::Project->new(
89           projectnumber     => $self->ordnumber,
90           description       => $self->customer->name,
91           customer_id       => $self->customer->id,
92           active            => 1,
93           project_type_id   => $::instance_conf->get_project_type_id,
94           project_status_id => $::instance_conf->get_project_status_id,
95           );
96        $new_project->save;
97        $self->globalproject_id($new_project->id);
98     } or die t8('Could not create new project #1', $@);
99   }
100   return 1;
101 }
102
103
104 sub _before_save_remove_empty_custom_shipto {
105   my ($self) = @_;
106
107   $self->custom_shipto(undef) if $self->custom_shipto && $self->custom_shipto->is_empty;
108
109   return 1;
110 }
111
112 sub _before_save_set_custom_shipto_module {
113   my ($self) = @_;
114
115   $self->custom_shipto->module('OE') if $self->custom_shipto;
116
117   return 1;
118 }
119
120 # methods
121
122 sub items { goto &orderitems; }
123 sub add_items { goto &add_orderitems; }
124 sub record_number { goto &number; }
125
126 sub type {
127   my $self = shift;
128
129   return 'sales_order'       if $self->customer_id && ! $self->quotation;
130   return 'purchase_order'    if $self->vendor_id   && ! $self->quotation;
131   return 'sales_quotation'   if $self->customer_id &&   $self->quotation;
132   return 'request_quotation' if $self->vendor_id   &&   $self->quotation;
133
134   return;
135 }
136
137 sub is_type {
138   return shift->type eq shift;
139 }
140
141 sub deliverydate {
142   # oe doesn't have deliverydate, but it does have reqdate.
143   # But this has a different meaning for sales quotations.
144   # deliverydate can be used to determine tax if tax_point isn't set.
145
146   return $_[0]->reqdate if $_[0]->type ne 'sales_quotation';
147 }
148
149 sub effective_tax_point {
150   my ($self) = @_;
151
152   return $self->tax_point || $self->deliverydate || $self->transdate;
153 }
154
155 sub displayable_type {
156   my $type = shift->type;
157
158   return $::locale->text('Sales quotation')   if $type eq 'sales_quotation';
159   return $::locale->text('Request quotation') if $type eq 'request_quotation';
160   return $::locale->text('Sales Order')       if $type eq 'sales_order';
161   return $::locale->text('Purchase Order')    if $type eq 'purchase_order';
162
163   die 'invalid type';
164 }
165
166 sub displayable_name {
167   join ' ', grep $_, map $_[0]->$_, qw(displayable_type record_number);
168 };
169
170 sub is_sales {
171   croak 'not an accessor' if @_ > 1;
172   return !!shift->customer_id;
173 }
174
175 sub daily_exchangerate {
176   my ($self, $val) = @_;
177
178   return 1 if $self->currency_id == $::instance_conf->get_currency_id;
179
180   my $rate = (any { $self->is_type($_) } qw(sales_quotation sales_order))      ? 'buy'
181            : (any { $self->is_type($_) } qw(request_quotation purchase_order)) ? 'sell'
182            : undef;
183   return if !$rate;
184
185   if (defined $val) {
186     croak t8('exchange rate has to be positive') if $val <= 0;
187     if (!$self->exchangerate_obj) {
188       $self->exchangerate_obj(SL::DB::Exchangerate->new(
189         currency_id => $self->currency_id,
190         transdate   => $self->transdate,
191         $rate       => $val,
192       ));
193     } elsif (!defined $self->exchangerate_obj->$rate) {
194       $self->exchangerate_obj->$rate($val);
195     } else {
196       croak t8('exchange rate already exists, no update allowed');
197     }
198   }
199   return $self->exchangerate_obj->$rate if $self->exchangerate_obj;
200 }
201
202 sub invoices {
203   my $self   = shift;
204   my %params = @_;
205
206   if ($self->quotation) {
207     return [];
208   } else {
209     require SL::DB::Invoice;
210     return SL::DB::Manager::Invoice->get_all(
211       query => [
212         ordnumber => $self->ordnumber,
213         @{ $params{query} || [] },
214       ]
215     );
216   }
217 }
218
219 sub displayable_state {
220   my ($self) = @_;
221
222   return $self->closed ? $::locale->text('closed') : $::locale->text('open');
223 }
224
225 sub abschlag_invoices {
226   return shift()->invoices(query => [ abschlag => 1 ]);
227 }
228
229 sub end_invoice {
230   return shift()->invoices(query => [ abschlag => 0 ]);
231 }
232
233 sub convert_to_invoice {
234   my ($self, %params) = @_;
235
236   croak("Conversion to invoices is only supported for sales records") unless $self->customer_id;
237
238   my $invoice;
239   if (!$self->db->with_transaction(sub {
240     require SL::DB::Invoice;
241     $invoice = SL::DB::Invoice->new_from($self, %params)->post || die;
242     $self->link_to_record($invoice);
243     # TODO extend link_to_record for items, otherwise long-term no d.r.y.
244     foreach my $item (@{ $invoice->items }) {
245       foreach (qw(orderitems)) {
246         if ($item->{"converted_from_${_}_id"}) {
247           die unless $item->{id};
248           RecordLinks->create_links('mode'       => 'ids',
249                                     'from_table' => $_,
250                                     'from_ids'   => $item->{"converted_from_${_}_id"},
251                                     'to_table'   => 'invoice',
252                                     'to_id'      => $item->{id},
253           ) || die;
254           delete $item->{"converted_from_${_}_id"};
255         }
256       }
257     }
258     $self->update_attributes(closed => 1);
259     1;
260   })) {
261     return undef;
262   }
263
264   return $invoice;
265 }
266
267 sub convert_to_delivery_order {
268   my ($self, @args) = @_;
269
270   my $delivery_order;
271   if (!$self->db->with_transaction(sub {
272     require SL::DB::DeliveryOrder;
273     $delivery_order = SL::DB::DeliveryOrder->new_from($self, @args);
274     $delivery_order->save;
275     $self->link_to_record($delivery_order);
276     # TODO extend link_to_record for items, otherwise long-term no d.r.y.
277     foreach my $item (@{ $delivery_order->items }) {
278       foreach (qw(orderitems)) {    # expand if needed (delivery_order_items)
279         if ($item->{"converted_from_${_}_id"}) {
280           die unless $item->{id};
281           RecordLinks->create_links('dbh'        => $self->db->dbh,
282                                     'mode'       => 'ids',
283                                     'from_table' => $_,
284                                     'from_ids'   => $item->{"converted_from_${_}_id"},
285                                     'to_table'   => 'delivery_order_items',
286                                     'to_id'      => $item->{id},
287           ) || die;
288           delete $item->{"converted_from_${_}_id"};
289         }
290       }
291     }
292
293     $self->update_attributes(delivered => 1) unless $::instance_conf->get_shipped_qty_require_stock_out;
294     1;
295   })) {
296     return undef;
297   }
298
299   return $delivery_order;
300 }
301
302 sub _clone_orderitem_cvar {
303   my ($cvar) = @_;
304
305   my $cloned = $_->clone_and_reset;
306   $cloned->sub_module('orderitems');
307
308   return $cloned;
309 }
310
311 sub new_from {
312   my ($class, $source, %params) = @_;
313
314   croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order';
315   croak("A destination type must be given as parameter")         unless $params{destination_type};
316
317   my $destination_type  = delete $params{destination_type};
318
319   my @from_tos = (
320     { from => 'sales_quotation',   to => 'sales_order',       abbr => 'sqso' },
321     { from => 'request_quotation', to => 'purchase_order',    abbr => 'rqpo' },
322     { from => 'sales_quotation',   to => 'sales_quotation',   abbr => 'sqsq' },
323     { from => 'sales_order',       to => 'sales_order',       abbr => 'soso' },
324     { from => 'request_quotation', to => 'request_quotation', abbr => 'rqrq' },
325     { from => 'purchase_order',    to => 'purchase_order',    abbr => 'popo' },
326     { from => 'sales_order',       to => 'purchase_order',    abbr => 'sopo' },
327     { from => 'purchase_order',    to => 'sales_order',       abbr => 'poso' },
328     { from => 'sales_order',       to => 'sales_quotation',   abbr => 'sosq' },
329     { from => 'purchase_order',    to => 'request_quotation', abbr => 'porq' },
330   );
331   my $from_to = (grep { $_->{from} eq $source->type && $_->{to} eq $destination_type} @from_tos)[0];
332   croak("Cannot convert from '" . $source->type . "' to '" . $destination_type . "'") if !$from_to;
333
334   my $is_abbr_any = sub {
335     any { $from_to->{abbr} eq $_ } @_;
336   };
337
338   my ($item_parent_id_column, $item_parent_column);
339
340   if (ref($source) eq 'SL::DB::Order') {
341     $item_parent_id_column = 'trans_id';
342     $item_parent_column    = 'order';
343   }
344
345   my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id
346                                                 department_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes
347                                                 ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded tax_point taxzone_id
348                                                 transaction_description vendor_id billing_address_id
349                                              )),
350                quotation => !!($destination_type =~ m{quotation$}),
351                closed    => 0,
352                delivered => 0,
353                transdate => DateTime->today_local,
354                employee  => SL::DB::Manager::Employee->current,
355             );
356
357   if ( $is_abbr_any->(qw(sopo poso)) ) {
358     $args{ordnumber} = undef;
359     $args{quonumber} = undef;
360     $args{reqdate}   = DateTime->today_local->next_workday();
361   }
362   if ( $is_abbr_any->(qw(sopo)) ) {
363     $args{customer_id}      = undef;
364     $args{salesman_id}      = undef;
365     $args{payment_id}       = undef;
366     $args{delivery_term_id} = undef;
367   }
368   if ( $is_abbr_any->(qw(poso)) ) {
369     $args{vendor_id} = undef;
370   }
371   if ( $is_abbr_any->(qw(soso)) ) {
372     $args{periodic_invoices_config} = $source->periodic_invoices_config->clone_and_reset if $source->periodic_invoices_config;
373   }
374   if ( $is_abbr_any->(qw(sosq porq)) ) {
375     $args{ordnumber} = undef;
376     $args{quonumber} = undef;
377     $args{reqdate}   = DateTime->today_local->next_workday();
378   }
379
380   # Custom shipto addresses (the ones specific to the sales/purchase
381   # record and not to the customer/vendor) are only linked from
382   # shipto â†’ order. Meaning order.shipto_id
383   # will not be filled in that case.
384   if (!$source->shipto_id && $source->id) {
385     $args{custom_shipto} = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto;
386
387   } else {
388     $args{shipto_id} = $source->shipto_id;
389   }
390
391   my $order = $class->new(%args);
392   $order->assign_attributes(%{ $params{attributes} }) if $params{attributes};
393   my $items = delete($params{items}) || $source->items_sorted;
394
395   my %item_parents;
396
397   my @items = map {
398     my $source_item      = $_;
399     my $source_item_id   = $_->$item_parent_id_column;
400     my @custom_variables = map { _clone_orderitem_cvar($_) } @{ $source_item->custom_variables };
401
402     $item_parents{$source_item_id} ||= $source_item->$item_parent_column;
403     my $item_parent                  = $item_parents{$source_item_id};
404
405     my $current_oe_item = SL::DB::OrderItem->new(map({ ( $_ => $source_item->$_ ) }
406                                                      qw(active_discount_source active_price_source base_qty cusordnumber
407                                                         description discount lastcost longdescription
408                                                         marge_percent marge_price_factor marge_total
409                                                         ordnumber parts_id price_factor price_factor_id pricegroup_id
410                                                         project_id qty reqdate sellprice serialnumber ship subtotal transdate unit
411                                                         optional
412                                                      )),
413                                                  custom_variables => \@custom_variables,
414     );
415     if ( $is_abbr_any->(qw(sopo)) ) {
416       $current_oe_item->sellprice($source_item->lastcost);
417       $current_oe_item->discount(0);
418     }
419     if ( $is_abbr_any->(qw(poso)) ) {
420       $current_oe_item->lastcost($source_item->sellprice);
421     }
422     $current_oe_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order';
423     $current_oe_item;
424   } @{ $items };
425
426   @items = grep { $params{item_filter}->($_) } @items if $params{item_filter};
427   @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty};
428   @items = grep { $_->qty >=0 } @items if $params{skip_items_negative_qty};
429
430   $order->items(\@items);
431
432   return $order;
433 }
434
435 sub new_from_multi {
436   my ($class, $sources, %params) = @_;
437
438   croak("Unsupported object type in sources")                             if any { ref($_) !~ m{SL::DB::Order} }                   @$sources;
439   croak("Cannot create order for purchase records")                       if any { !$_->is_sales }                                 @$sources;
440   croak("Cannot create order from source records of different customers") if any { $_->customer_id != $sources->[0]->customer_id } @$sources;
441
442   # bb: todo: check shipto: is it enough to check the ids or do we have to compare the entries?
443   if (delete $params{check_same_shipto}) {
444     die "check same shipto address is not implemented yet";
445     die "Source records do not have the same shipto"        if 1;
446   }
447
448   # sort sources
449   if (defined $params{sort_sources_by}) {
450     my $sort_by = delete $params{sort_sources_by};
451     if ($sources->[0]->can($sort_by)) {
452       $sources = [ sort { $a->$sort_by cmp $b->$sort_by } @$sources ];
453     } else {
454       die "Cannot sort source records by $sort_by";
455     }
456   }
457
458   # set this entries to undef that yield different information
459   my %attributes;
460   foreach my $attr (qw(ordnumber transdate reqdate tax_point taxincluded shippingpoint
461                        shipvia notes closed delivered reqdate quonumber
462                        cusordnumber proforma transaction_description
463                        order_probability expected_billing_date)) {
464     $attributes{$attr} = undef if any { ($sources->[0]->$attr//'') ne ($_->$attr//'') } @$sources;
465   }
466   foreach my $attr (qw(cp_id currency_id salesman_id department_id
467                        delivery_customer_id delivery_vendor_id shipto_id
468                        globalproject_id exchangerate)) {
469     $attributes{$attr} = undef if any { ($sources->[0]->$attr||0) != ($_->$attr||0) }   @$sources;
470   }
471
472   # set this entries from customer that yield different information
473   foreach my $attr (qw(language_id taxzone_id payment_id delivery_term_id)) {
474     $attributes{$attr}  = $sources->[0]->customervendor->$attr if any { ($sources->[0]->$attr||0)     != ($_->$attr||0) }      @$sources;
475   }
476   $attributes{intnotes} = $sources->[0]->customervendor->notes if any { ($sources->[0]->intnotes//'') ne ($_->intnotes//'')  } @$sources;
477
478   # no periodic invoice config for new order
479   $attributes{periodic_invoices_config} = undef;
480
481   # set emplyee to the current one
482   $attributes{employee} = SL::DB::Manager::Employee->current;
483
484   # copy global ordnumber, transdate, cusordnumber into item scope
485   #   unless already present there
486   foreach my $attr (qw(ordnumber transdate cusordnumber)) {
487     foreach my $src (@$sources) {
488       foreach my $item (@{ $src->items_sorted }) {
489         $item->$attr($src->$attr) if !$item->$attr;
490       }
491     }
492   }
493
494   # collect items
495   my @items;
496   push @items, @{$_->items_sorted} for @$sources;
497   # make order from first source and all items
498   my $order = $class->new_from($sources->[0],
499                                destination_type => 'sales_order',
500                                attributes       => \%attributes,
501                                items            => \@items,
502                                %params);
503
504   return $order;
505 }
506
507 sub number {
508   my $self = shift;
509
510   return if !$self->type;
511
512   my %number_method = (
513     sales_order       => 'ordnumber',
514     sales_quotation   => 'quonumber',
515     purchase_order    => 'ordnumber',
516     request_quotation => 'quonumber',
517   );
518
519   return $self->${ \ $number_method{$self->type} }(@_);
520 }
521
522 sub customervendor {
523   $_[0]->is_sales ? $_[0]->customer : $_[0]->vendor;
524 }
525
526 sub date {
527   goto &transdate;
528 }
529
530 sub digest {
531   my ($self) = @_;
532
533   sprintf "%s %s %s (%s)",
534     $self->number,
535     $self->customervendor->name,
536     $self->amount_as_number,
537     $self->date->to_kivitendo;
538 }
539
540 1;
541
542 __END__
543
544 =pod
545
546 =encoding utf8
547
548 =head1 NAME
549
550 SL::DB::Order - Order Datenbank Objekt.
551
552 =head1 FUNCTIONS
553
554 =head2 C<type>
555
556 Returns one of the following string types:
557
558 =over 4
559
560 =item sales_order
561
562 =item purchase_order
563
564 =item sales_quotation
565
566 =item request_quotation
567
568 =back
569
570 =head2 C<is_type TYPE>
571
572 Returns true if the order is of the given type.
573
574 =head2 C<daily_exchangerate $val>
575
576 Gets or sets the exchangerate object's value. This is the value from the
577 table C<exchangerate> depending on the order's currency, the transdate and
578 if it is a sales or purchase order.
579
580 The order object (respectively the table C<oe>) has an own column
581 C<exchangerate> which can be get or set with the accessor C<exchangerate>.
582
583 The idea is to drop the legacy table C<exchangerate> in the future and to
584 give all relevant tables it's own C<exchangerate> column.
585
586 So, this method is here if you need to access the "legacy" exchangerate via
587 an order object.
588
589 =over 4
590
591 =item C<$val>
592
593 (optional) If given, the exchangerate in the "legacy" table is set to this
594 value, depending on currency, transdate and sales or purchase.
595
596 =back
597
598 =head2 C<convert_to_delivery_order %params>
599
600 Creates a new delivery order with C<$self> as the basis by calling
601 L<SL::DB::DeliveryOrder::new_from>. That delivery order is saved, and
602 C<$self> is linked to the new invoice via
603 L<SL::DB::RecordLink>. C<$self>'s C<delivered> attribute is set to
604 C<true>, and C<$self> is saved.
605
606 The arguments in C<%params> are passed to
607 L<SL::DB::DeliveryOrder::new_from>.
608
609 Returns C<undef> on failure. Otherwise the new delivery order will be
610 returned.
611
612 =head2 C<convert_to_invoice %params>
613
614 Creates a new invoice with C<$self> as the basis by calling
615 L<SL::DB::Invoice::new_from>. That invoice is posted, and C<$self> is
616 linked to the new invoice via L<SL::DB::RecordLink>. C<$self>'s
617 C<closed> attribute is set to C<true>, and C<$self> is saved.
618
619 The arguments in C<%params> are passed to L<SL::DB::Invoice::new_from>.
620
621 Returns the new invoice instance on success and C<undef> on
622 failure. The whole process is run inside a transaction. On failure
623 nothing is created or changed in the database.
624
625 At the moment only sales quotations and sales orders can be converted.
626
627 =head2 C<new_from $source, %params>
628
629 Creates a new C<SL::DB::Order> instance and copies as much
630 information from C<$source> as possible. At the moment only records with the
631 same destination type as the source type and sales orders from
632 sales quotations and purchase orders from requests for quotations can be
633 created.
634
635 The C<transdate> field will be set to the current date.
636
637 The conversion copies the order items as well.
638
639 Returns the new order instance. The object returned is not
640 saved.
641
642 C<%params> can include the following options
643 (C<destination_type> is mandatory):
644
645 =over 4
646
647 =item C<destination_type>
648
649 (mandatory)
650 The type of the newly created object. Can be C<sales_quotation>,
651 C<sales_order>, C<purchase_quotation> or C<purchase_order> for now.
652
653 =item C<items>
654
655 An optional array reference of RDBO instances for the items to use. If
656 missing then the method C<items_sorted> will be called on
657 C<$source>. This option can be used to override the sorting, to
658 exclude certain positions or to add additional ones.
659
660 =item C<skip_items_negative_qty>
661
662 If trueish then items with a negative quantity are skipped. Items with
663 a quantity of 0 are not affected by this option.
664
665 =item C<skip_items_zero_qty>
666
667 If trueish then items with a quantity of 0 are skipped.
668
669 =item C<item_filter>
670
671 An optional code reference that is called for each item with the item
672 as its sole parameter. Items for which the code reference returns a
673 falsish value will be skipped.
674
675 =item C<attributes>
676
677 An optional hash reference. If it exists then it is passed to C<new>
678 allowing the caller to set certain attributes for the new delivery
679 order.
680
681 =back
682
683 =head2 C<new_from_multi $sources, %params>
684
685 Creates a new C<SL::DB::Order> instance from multiple sources and copies as
686 much information from C<$sources> as possible.
687 At the moment only sales orders can be combined and they must be of the same
688 customer.
689
690 The new order is created from the first one using C<new_from> and the positions
691 of all orders are added to the new order. The orders can be sorted with the
692 parameter C<sort_sources_by>.
693
694 The orders attributes are kept if they contain the same information for all
695 source orders an will be set to empty if they contain different information.
696
697 Returns the new order instance. The object returned is not
698 saved.
699
700 C<params> other then C<sort_sources_by> are passed to C<new_from>.
701
702 =head1 BUGS
703
704 Nothing here yet.
705
706 =head1 AUTHOR
707
708 Sven Schöling <s.schoeling@linet-services.de>
709
710 =cut