e98b0c4d7d0ec0c875440675d9b13194a27087bc
[kivitendo-erp.git] / SL / DB / Part.pm
1 package SL::DB::Part;
2
3 use strict;
4
5 use Carp;
6 use List::MoreUtils qw(any uniq);
7 use Rose::DB::Object::Helpers qw(as_tree);
8
9 use SL::Locale::String qw(t8);
10 use SL::DBUtils;
11 use SL::DB::MetaSetup::Part;
12 use SL::DB::Manager::Part;
13 use SL::DB::Chart;
14 use SL::DB::Helper::AttrHTML;
15 use SL::DB::Helper::AttrSorted;
16 use SL::DB::Helper::TransNumberGenerator;
17 use SL::DB::Helper::CustomVariables (
18   module      => 'IC',
19   cvars_alias => 1,
20 );
21 use SL::DB::Helper::DisplayableNamePreferences (
22   title   => t8('Article'),
23   options => [ {name => 'partnumber',  title => t8('Part Number')     },
24                {name => 'description', title => t8('Description')    },
25                {name => 'notes',       title => t8('Notes')},
26                {name => 'ean',         title => t8('EAN')            }, ],
27 );
28
29 use List::Util qw(sum);
30
31 __PACKAGE__->meta->add_relationships(
32   assemblies                     => {
33     type         => 'one to many',
34     class        => 'SL::DB::Assembly',
35     manager_args => { sort_by => 'position' },
36     column_map   => { id => 'id' },
37   },
38   prices         => {
39     type         => 'one to many',
40     class        => 'SL::DB::Price',
41     column_map   => { id => 'parts_id' },
42     manager_args => { with_objects => [ 'pricegroup' ] }
43   },
44   makemodels     => {
45     type         => 'one to many',
46     class        => 'SL::DB::MakeModel',
47     manager_args => { sort_by => 'sortorder' },
48     column_map   => { id => 'parts_id' },
49   },
50   customerprices => {
51     type         => 'one to many',
52     class        => 'SL::DB::PartCustomerPrice',
53     column_map   => { id => 'parts_id' },
54   },
55   translations   => {
56     type         => 'one to many',
57     class        => 'SL::DB::Translation',
58     column_map   => { id => 'parts_id' },
59   },
60   assortment_items => {
61     type         => 'one to many',
62     class        => 'SL::DB::AssortmentItem',
63     column_map   => { id => 'assortment_id' },
64     manager_args => { sort_by => 'position' },
65   },
66   history_entries   => {
67     type            => 'one to many',
68     class           => 'SL::DB::History',
69     column_map      => { id => 'trans_id' },
70     query_args      => [ what_done => 'part' ],
71     manager_args    => { sort_by => 'itime' },
72   },
73   shop_parts     => {
74     type         => 'one to many',
75     class        => 'SL::DB::ShopPart',
76     column_map   => { id => 'part_id' },
77     manager_args => { with_objects => [ 'shop' ] },
78   },
79 );
80
81 __PACKAGE__->meta->initialize;
82
83 __PACKAGE__->attr_html('notes');
84 __PACKAGE__->attr_sorted({ unsorted => 'makemodels',     position => 'sortorder' });
85 __PACKAGE__->attr_sorted({ unsorted => 'customerprices', position => 'sortorder' });
86
87 __PACKAGE__->before_save('_before_save_set_partnumber');
88
89 sub _before_save_set_partnumber {
90   my ($self) = @_;
91
92   $self->create_trans_number if !$self->partnumber;
93   return 1;
94 }
95
96 sub items {
97   my ($self) = @_;
98
99   if ( $self->part_type eq 'assembly' ) {
100     return $self->assemblies;
101   } elsif ( $self->part_type eq 'assortment' ) {
102     return $self->assortment_items;
103   } else {
104     return undef;
105   }
106 }
107
108 sub items_checksum {
109   my ($self) = @_;
110
111   # for detecting if the items of an (orphaned) assembly or assortment have
112   # changed when saving
113
114   return join(' ', sort map { $_->part->id } @{$self->items});
115 };
116
117 sub validate {
118   my ($self) = @_;
119
120   my @errors;
121   push @errors, $::locale->text('The partnumber is missing.')     if $self->id and !$self->partnumber;
122   push @errors, $::locale->text('The unit is missing.')           unless $self->unit;
123   push @errors, $::locale->text('The buchungsgruppe is missing.') unless $self->buchungsgruppen_id or $self->buchungsgruppe;
124
125   unless ( $self->id ) {
126     push @errors, $::locale->text('The partnumber already exists.') if SL::DB::Manager::Part->get_all_count(where => [ partnumber => $self->partnumber ]);
127   };
128
129   if ($self->is_assortment && $self->orphaned && scalar @{$self->assortment_items} == 0) {
130     # when assortment isn't orphaned form doesn't contain any items
131     push @errors, $::locale->text('The assortment doesn\'t have any items.');
132   }
133
134   if ($self->is_assembly && scalar @{$self->assemblies} == 0) {
135     push @errors, $::locale->text('The assembly doesn\'t have any items.');
136   }
137
138   return @errors;
139 }
140
141 sub is_type {
142   my $self = shift;
143   my $type  = lc(shift || '');
144   die 'invalid type' unless $type =~ /^(?:part|service|assembly|assortment)$/;
145
146   return $self->type eq $type ? 1 : 0;
147 }
148
149 sub is_part       { $_[0]->part_type eq 'part'       }
150 sub is_assembly   { $_[0]->part_type eq 'assembly'   }
151 sub is_service    { $_[0]->part_type eq 'service'    }
152 sub is_assortment { $_[0]->part_type eq 'assortment' }
153
154 sub type {
155   return $_[0]->part_type;
156   # my ($self, $type) = @_;
157   # if (@_ > 1) {
158   #   die 'invalid type' unless $type =~ /^(?:part|service|assembly)$/;
159   #   $self->assembly(          $type eq 'assembly' ? 1 : 0);
160   #   $self->inventory_accno_id($type ne 'service'  ? 1 : undef);
161   # }
162
163   # return 'assembly' if $self->assembly;
164   # return 'part'     if $self->inventory_accno_id;
165   # return 'service';
166 }
167
168 sub new_part {
169   my ($class, %params) = @_;
170   $class->new(%params, part_type => 'part');
171 }
172
173 sub new_assembly {
174   my ($class, %params) = @_;
175   $class->new(%params, part_type => 'assembly');
176 }
177
178 sub new_service {
179   my ($class, %params) = @_;
180   $class->new(%params, part_type => 'service');
181 }
182
183 sub new_assortment {
184   my ($class, %params) = @_;
185   $class->new(%params, part_type => 'assortment');
186 }
187
188 sub last_modification {
189   my ($self) = @_;
190   return $self->mtime // $self->itime;
191 };
192
193 sub used_in_record {
194   my ($self) = @_;
195   die 'not an accessor' if @_ > 1;
196
197   return 1 unless $self->id;
198
199   my @relations = qw(
200     SL::DB::InvoiceItem
201     SL::DB::OrderItem
202     SL::DB::DeliveryOrderItem
203   );
204
205   for my $class (@relations) {
206     eval "require $class";
207     return 1 if $class->_get_manager_class->get_all_count(query => [ parts_id => $self->id ]);
208   }
209   return 0;
210 }
211 sub orphaned {
212   my ($self) = @_;
213   die 'not an accessor' if @_ > 1;
214
215   return 1 unless $self->id;
216
217   my @relations = qw(
218     SL::DB::InvoiceItem
219     SL::DB::OrderItem
220     SL::DB::DeliveryOrderItem
221     SL::DB::Inventory
222     SL::DB::AssortmentItem
223   );
224
225   for my $class (@relations) {
226     eval "require $class";
227     return 0 if $class->_get_manager_class->get_all_count(query => [ parts_id => $self->id ]);
228   }
229   return 1;
230 }
231
232 sub get_sellprice_info {
233   my $self   = shift;
234   my %params = @_;
235
236   confess "Missing part id" unless $self->id;
237
238   my $object = $self->load;
239
240   return { sellprice       => $object->sellprice,
241            price_factor_id => $object->price_factor_id };
242 }
243
244 sub get_ordered_qty {
245   my $self   = shift;
246   my %result = SL::DB::Manager::Part->get_ordered_qty($self->id);
247
248   return $result{ $self->id };
249 }
250
251 sub available_units {
252   shift->unit_obj->convertible_units;
253 }
254
255 # autogenerated accessor is slightly off...
256 sub buchungsgruppe {
257   shift->buchungsgruppen(@_);
258 }
259
260 sub get_taxkey {
261   my ($self, %params) = @_;
262
263   my $date     = $params{date} || DateTime->today_local;
264   my $is_sales = !!$params{is_sales};
265   my $taxzone  = $params{ defined($params{taxzone}) ? 'taxzone' : 'taxzone_id' } * 1;
266   my $tk_info  = $::request->cache('get_taxkey');
267
268   $tk_info->{$self->id}                                      //= {};
269   $tk_info->{$self->id}->{$taxzone}                          //= { };
270   my $cache = $tk_info->{$self->id}->{$taxzone}->{$is_sales} //= { };
271
272   if (!exists $cache->{$date}) {
273     $cache->{$date} =
274       $self->get_chart(type => $is_sales ? 'income' : 'expense', taxzone => $taxzone)
275       ->get_active_taxkey($date);
276   }
277
278   return $cache->{$date};
279 }
280
281 sub get_chart {
282   my ($self, %params) = @_;
283
284   my $type    = (any { $_ eq $params{type} } qw(income expense inventory)) ? $params{type} : croak("Invalid 'type' parameter '$params{type}'");
285   my $taxzone = $params{ defined($params{taxzone}) ? 'taxzone' : 'taxzone_id' } * 1;
286
287   my $charts     = $::request->cache('get_chart_id/by_part_id_and_taxzone')->{$self->id} //= {};
288   my $all_charts = $::request->cache('get_chart_id/by_id');
289
290   $charts->{$taxzone} ||= { };
291
292   if (!exists $charts->{$taxzone}->{$type}) {
293     require SL::DB::Buchungsgruppe;
294     my $bugru    = SL::DB::Buchungsgruppe->load_cached($self->buchungsgruppen_id);
295     my $chart_id = ($type eq 'inventory') ? ($self->is_part ? $bugru->inventory_accno_id : undef)
296                  :                          $bugru->call_sub("${type}_accno_id", $taxzone);
297
298     if ($chart_id) {
299       my $chart                    = $all_charts->{$chart_id} // SL::DB::Chart->load_cached($chart_id)->load;
300       $all_charts->{$chart_id}     = $chart;
301       $charts->{$taxzone}->{$type} = $chart;
302     }
303   }
304
305   return $charts->{$taxzone}->{$type};
306 }
307
308 sub get_stock {
309   my ($self, %params) = @_;
310
311   return undef unless $self->id;
312
313   my $query = 'SELECT SUM(qty) FROM inventory WHERE parts_id = ?';
314   my @values = ($self->id);
315
316   if ( $params{bin_id} ) {
317     $query .= ' AND bin_id = ?';
318     push(@values, $params{bin_id});
319   }
320
321   if ( $params{warehouse_id} ) {
322     $query .= ' AND warehouse_id = ?';
323     push(@values, $params{warehouse_id});
324   }
325
326   if ( $params{shippingdate} ) {
327     die unless ref($params{shippingdate}) eq 'DateTime';
328     $query .= ' AND shippingdate <= ?';
329     push(@values, $params{shippingdate});
330   }
331
332   my ($stock) = selectrow_query($::form, $self->db->dbh, $query, @values);
333
334   return $stock || 0; # never return undef
335 };
336
337
338 # this is designed to ignore chargenumbers, expiration dates and just give a list of how much <-> where
339 sub get_simple_stock {
340   my ($self, %params) = @_;
341
342   return [] unless $self->id;
343
344   my $query = <<'';
345     SELECT sum(qty), warehouse_id, bin_id FROM inventory WHERE parts_id = ?
346     GROUP BY warehouse_id, bin_id
347
348   my $stock_info = selectall_hashref_query($::form, $::form->get_standard_dbh, $query, $self->id);
349   [ map { bless $_, 'SL::DB::Part::SimpleStock'} @$stock_info ];
350 }
351 # helper class to have bin/warehouse accessors in stock result
352 { package SL::DB::Part::SimpleStock;
353   sub warehouse { require SL::DB::Warehouse; SL::DB::Manager::Warehouse->find_by_or_create(id => $_[0]->{warehouse_id}) }
354   sub bin       { require SL::DB::Bin;       SL::DB::Manager::Bin      ->find_by_or_create(id => $_[0]->{bin_id}) }
355 }
356
357 sub get_simple_stock_sql {
358   my ($self, %params) = @_;
359
360   return [] unless $self->id;
361
362   my $query = <<SQL;
363      SELECT w.description                         AS warehouse_description,
364             b.description                         AS bin_description,
365             SUM(i.qty)                            AS qty,
366             SUM(i.qty * p.lastcost)               AS stock_value,
367             p.unit                                AS unit,
368             LEAD(w.description)           OVER pt AS wh_lead,            -- to detect warehouse changes for subtotals in template
369             SUM( SUM(i.qty) )             OVER pt AS run_qty,            -- running total of total qty
370             SUM( SUM(i.qty) )             OVER wh AS wh_run_qty,         -- running total of warehouse qty
371             SUM( SUM(i.qty * p.lastcost)) OVER pt AS run_stock_value,    -- running total of total stock_value
372             SUM( SUM(i.qty * p.lastcost)) OVER wh AS wh_run_stock_value  -- running total of warehouse stock_value
373        FROM inventory i
374             LEFT JOIN parts p     ON (p.id           = i.parts_id)
375             LEFT JOIN warehouse w ON (i.warehouse_id = w.id)
376             LEFT JOIN bin b       ON (i.bin_id       = b.id)
377       WHERE parts_id = ?
378    GROUP BY w.description, w.sortkey, b.description, p.unit, i.parts_id
379      HAVING SUM(qty) != 0
380      WINDOW pt AS (PARTITION BY i.parts_id    ORDER BY w.sortkey, b.description, p.unit),
381             wh AS (PARTITION by w.description ORDER BY w.sortkey, b.description, p.unit)
382    ORDER BY w.sortkey, b.description, p.unit
383 SQL
384
385   my $stock_info = selectall_hashref_query($::form, $self->db->dbh, $query, $self->id);
386   return $stock_info;
387 }
388
389 sub get_mini_journal {
390   my ($self) = @_;
391
392   # inventory ids of the most recent 10 inventory trans_ids
393
394   # duplicate code copied from SL::Controller::Inventory mini_journal, except
395   # for the added filter on parts_id
396
397   my $parts_id = $self->id;
398   my $query = <<"SQL";
399 with last_inventories as (
400    select id,
401           trans_id,
402           itime
403      from inventory
404     where parts_id = $parts_id
405  order by itime desc
406     limit 20
407 ),
408 grouped_ids as (
409    select trans_id,
410           array_agg(id) as ids
411      from last_inventories
412  group by trans_id
413  order by max(itime)
414      desc limit 10
415 )
416 select unnest(ids)
417   from grouped_ids
418  limit 20  -- so the planner knows how many ids to expect, the cte is an optimisation fence
419 SQL
420
421   my $objs  = SL::DB::Manager::Inventory->get_all(
422     query        => [ id => [ \"$query" ] ],
423     with_objects => [ 'parts', 'trans_type', 'bin', 'bin.warehouse' ], # prevent lazy loading in template
424     sort_by      => 'itime DESC',
425   );
426   # remember order of trans_ids from query, for ordering hash later
427   my @sorted_trans_ids = uniq map { $_->trans_id } @$objs;
428
429   # at most 2 of them belong to a transaction and the qty determines in or out.
430   my %transactions;
431   for (@$objs) {
432     $transactions{ $_->trans_id }{ $_->qty > 0 ? 'in' : 'out' } = $_;
433     $transactions{ $_->trans_id }{base} = $_;
434   }
435
436   # because the inventory transactions were built in a hash, we need to sort the
437   # hash by using the original sort order of the trans_ids
438   my @sorted = map { $transactions{$_} } @sorted_trans_ids;
439
440   return \@sorted;
441 }
442
443 sub clone_and_reset_deep {
444   my ($self) = @_;
445
446   my $clone = $self->clone_and_reset; # resets id and partnumber (primary key and unique constraint)
447   $clone->makemodels(   map { $_->clone_and_reset } @{$self->makemodels}   ) if @{$self->makemodels};
448   $clone->translations( map { $_->clone_and_reset } @{$self->translations} ) if @{$self->translations};
449
450   if ( $self->is_assortment ) {
451     # use clone rather than reset_and_clone because the unique constraint would also remove parts_id
452     $clone->assortment_items( map { $_->clone } @{$self->assortment_items} );
453     $_->assortment_id(undef) foreach @{ $clone->assortment_items }
454   };
455
456   if ( $self->is_assembly ) {
457     $clone->assemblies( map { $_->clone_and_reset } @{$self->assemblies});
458   };
459
460   if ( $self->prices ) {
461     $clone->prices( map { $_->clone } @{$self->prices}); # pricegroup_id gets reset here because it is part of a unique contraint
462     if ( $clone->prices ) {
463       foreach my $price ( @{$clone->prices} ) {
464         $price->id(undef);
465         $price->parts_id(undef);
466       };
467     };
468   };
469
470   return $clone;
471 }
472
473 sub item_diffs {
474   my ($self, $comparison_part) = @_;
475
476   die "item_diffs needs a part object" unless ref($comparison_part) eq 'SL::DB::Part';
477   die "part and comparison_part need to be of the same part_type" unless
478         ( $self->part_type eq 'assembly' or $self->part_type eq 'assortment' )
479     and ( $comparison_part->part_type eq 'assembly' or $comparison_part->part_type eq 'assortment' )
480     and $self->part_type eq $comparison_part->part_type;
481
482   # return [], [] if $self->items_checksum eq $comparison_part->items_checksum;
483   my @self_part_ids       = map { $_->parts_id } $self->items;
484   my @comparison_part_ids = map { $_->parts_id } $comparison_part->items;
485
486   my %orig       = map{ $_ => 1 } @self_part_ids;
487   my %comparison = map{ $_ => 1 } @comparison_part_ids;
488   my (@additions, @removals);
489   @additions = grep { !exists( $orig{$_}       ) } @comparison_part_ids if @comparison_part_ids;
490   @removals  = grep { !exists( $comparison{$_} ) } @self_part_ids       if @self_part_ids;
491
492   return \@additions, \@removals;
493 };
494
495 sub items_sellprice_sum {
496   my ($self, %params) = @_;
497
498   return unless $self->is_assortment or $self->is_assembly;
499   return unless $self->items;
500
501   if ($self->is_assembly) {
502     return sum map { $_->linetotal_sellprice          } @{$self->items};
503   } else {
504     return sum map { $_->linetotal_sellprice(%params) } grep { $_->charge } @{$self->items};
505   }
506 }
507
508 sub items_lastcost_sum {
509   my ($self) = @_;
510
511   return unless $self->is_assortment or $self->is_assembly;
512   return unless $self->items;
513   sum map { $_->linetotal_lastcost } @{$self->items};
514 };
515
516 1;
517
518 __END__
519
520 =pod
521
522 =encoding utf-8
523
524 =head1 NAME
525
526 SL::DB::Part: Model for the 'parts' table
527
528 =head1 SYNOPSIS
529
530 This is a standard Rose::DB::Object based model and can be used as one.
531
532 =head1 TYPES
533
534 Although the base class is called C<Part> we usually talk about C<Articles> if
535 we mean instances of this class. This is because articles come in three
536 flavours called:
537
538 =over 4
539
540 =item Part     - a single part
541
542 =item Service  - a part without onhand, and without inventory accounting
543
544 =item Assembly - a collection of both parts and services
545
546 =item Assortment - a collection of items (parts or assemblies)
547
548 =back
549
550 These types are sadly represented by data inside the class and cannot be
551 migrated into a flag. To work around this, each C<Part> object knows what type
552 it currently is. Since the type is data driven, there ist no explicit setting
553 method for it, but you can construct them explicitly with C<new_part>,
554 C<new_service>, C<new_assembly> and C<new_assortment>. A Buchungsgruppe should be supplied in this
555 case, but it will use the default Buchungsgruppe if you don't.
556
557 Matching these there are assorted helper methods dealing with types,
558 e.g.  L</new_part>, L</new_service>, L</new_assembly>, L</type>,
559 L</is_type> and others.
560
561 =head1 FUNCTIONS
562
563 =over 4
564
565 =item C<new_part %PARAMS>
566
567 =item C<new_service %PARAMS>
568
569 =item C<new_assembly %PARAMS>
570
571 Will set the appropriate data fields so that the resulting instance will be of
572 the requested type. Since accounting targets are part of the distinction,
573 providing a C<Buchungsgruppe> is recommended. If none is given the constructor
574 will load a default one and set the accounting targets from it.
575
576 =item C<type>
577
578 Returns the type as a string. Can be one of C<part>, C<service>, C<assembly>.
579
580 =item C<is_type $TYPE>
581
582 Tests if the current object is a part, a service or an
583 assembly. C<$type> must be one of the words 'part', 'service' or
584 'assembly' (their plurals are ok, too).
585
586 Returns 1 if the requested type matches, 0 if it doesn't and
587 C<confess>es if an unknown C<$type> parameter is encountered.
588
589 =item C<is_part>
590
591 =item C<is_service>
592
593 =item C<is_assembly>
594
595 Shorthand for C<is_type('part')> etc.
596
597 =item C<get_sellprice_info %params>
598
599 Retrieves the C<sellprice> and C<price_factor_id> for a part under
600 different conditions and returns a hash reference with those two keys.
601
602 If C<%params> contains a key C<project_id> then a project price list
603 will be consulted if one exists for that project. In this case the
604 parameter C<country_id> is evaluated as well: if a price list entry
605 has been created for this country then it will be used. Otherwise an
606 entry without a country set will be used.
607
608 If none of the above conditions is met then the information from
609 C<$self> is used.
610
611 =item C<get_ordered_qty %params>
612
613 Retrieves the quantity that has been ordered from a vendor but that
614 has not been delivered yet. Only open purchase orders are considered.
615
616 =item C<get_taxkey %params>
617
618 Retrieves and returns a taxkey object valid for the given date
619 C<$params{date}> and tax zone C<$params{taxzone}>
620 (C<$params{taxzone_id}> is also recognized). The date defaults to the
621 current date if undefined.
622
623 This function looks up the income (for trueish values of
624 C<$params{is_sales}>) or expense (for falsish values of
625 C<$params{is_sales}>) account for the current part. It uses the part's
626 associated buchungsgruppe and uses the fields belonging to the tax
627 zone given by C<$params{taxzone}>.
628
629 The information retrieved by the function is cached.
630
631 =item C<get_chart %params>
632
633 Retrieves and returns a chart object valid for the given type
634 C<$params{type}> and tax zone C<$params{taxzone}>
635 (C<$params{taxzone_id}> is also recognized). The type must be one of
636 the three key words C<income>, C<expense> and C<inventory>.
637
638 This function uses the part's associated buchungsgruppe and uses the
639 fields belonging to the tax zone given by C<$params{taxzone}>.
640
641 The information retrieved by the function is cached.
642
643 =item C<used_in_record>
644
645 Checks if this article has been used in orders, invoices or delivery orders.
646
647 =item C<orphaned>
648
649 Checks if this article is used in orders, invoices, delivery orders or
650 assemblies.
651
652 =item C<buchungsgruppe BUCHUNGSGRUPPE>
653
654 Used to set the accounting information from a L<SL:DB::Buchungsgruppe> object.
655 Please note, that this is a write only accessor, the original Buchungsgruppe can
656 not be retrieved from an article once set.
657
658 =item C<get_simple_stock_sql>
659
660 Fetches the qty and the stock value for the current part for each bin and
661 warehouse where the part is in stock (or rather different from 0, might be
662 negative).
663
664 Runs some additional window functions to add the running totals (total running
665 total and total per warehouse) for qty and stock value to each line.
666
667 Using the LEAD(w.description) the template can check if the warehouse
668 description is about to change, i.e. the next line will contain numbers from a
669 different warehouse, so that a subtotal line can be added.
670
671 The last row will contain the running qty total (run_qty) and the running total
672 stock value (run_stock_value) over all warehouses/bins and can be used to add a
673 line for the grand totals.
674
675 =item C<items_lastcost_sum>
676
677 Non-recursive lastcost sum of all the items in an assembly or assortment.
678
679 =item C<get_stock %params>
680
681 Fetches stock qty in the default unit for a part.
682
683 bin_id and warehouse_id may be passed as params. If only a bin_id is passed,
684 the stock qty for that bin is returned. If only a warehouse_id is passed, the
685 stock qty for all bins in that warehouse is returned.  If a shippingdate is
686 passed the stock qty for that date is returned.
687
688 Examples:
689  my $qty = $part->get_stock(bin_id => 52);
690
691  $part->get_stock(shippingdate => DateTime->today->add(days => -5));
692
693 =back
694
695 =head1 AUTHORS
696
697 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>,
698 Sven Schöling E<lt>s.schoeling@linet-services.deE<gt>
699
700 =cut