BackgroundJob-Hilfsfunktionen
[kivitendo-erp.git] / SL / DB / DeliveryOrder.pm
1 package SL::DB::DeliveryOrder;
2
3 use strict;
4
5 use SL::DB::MetaSetup::DeliveryOrder;
6 use SL::DB::Manager::DeliveryOrder;
7 use SL::DB::Order;
8
9 use List::Util qw(first);
10
11 __PACKAGE__->meta->add_relationship(orderitems => { type         => 'one to many',
12                                                     class        => 'SL::DB::DeliveryOrderItem',
13                                                     column_map   => { id => 'trans_id' },
14                                                     manager_args => { with_objects => [ 'part' ] }
15                                                   },
16                                    );
17
18 __PACKAGE__->meta->initialize;
19
20 # methods
21
22 sub sales_order {
23   my $self   = shift;
24   my %params = @_;
25
26   my $orders = SL::DB::Manager::Order->get_all(
27     query => [
28       ordnumber => $self->ordnumber,
29       @{ $params{query} || [] },
30     ],
31   );
32
33   return first { $_->is_type('sales_order') } @{ $orders };
34 }
35
36 1;