Controller-Base: _controller_name in controller_name umbenennen; action_name() ergänzt
[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::Helper::LinkedRecords;
8 use SL::DB::Helper::TransNumberGenerator;
9 use SL::DB::Order;
10
11 use List::Util qw(first);
12
13 __PACKAGE__->meta->add_relationship(orderitems => { type         => 'one to many',
14                                                     class        => 'SL::DB::DeliveryOrderItem',
15                                                     column_map   => { id => 'delivery_order_id' },
16                                                     manager_args => { with_objects => [ 'parts' ] }
17                                                   },
18                                     shipto => { type       => 'one to one',
19                                                 class      => 'SL::DB::Shipto',
20                                                 column_map => { shipto_id => 'shipto_id' },
21                                               },
22                                     department => { type       => 'one to one',
23                                                     class      => 'SL::DB::Department',
24                                                     column_map => { department_id => 'id' },
25                                                   },
26                                    );
27
28 __PACKAGE__->meta->initialize;
29
30 # methods
31
32 sub items { goto &orderitems; }
33
34 sub sales_order {
35   my $self   = shift;
36   my %params = @_;
37
38   my $orders = SL::DB::Manager::Order->get_all(
39     query => [
40       ordnumber => $self->ordnumber,
41       @{ $params{query} || [] },
42     ],
43   );
44
45   return first { $_->is_type('sales_order') } @{ $orders };
46 }
47
48 sub type {
49   return shift->customer_id ? 'sales_delivery_order' : 'purchase_delivery_order';
50 }
51
52 sub displayable_state {
53   my ($self) = @_;
54
55   return join '; ',
56     ($self->closed    ? $::locale->text('closed')    : $::locale->text('open')),
57     ($self->delivered ? $::locale->text('delivered') : $::locale->text('not delivered'));
58 }
59
60 1;