1 package SL::DB::DeliveryOrder;
7 use SL::DB::MetaSetup::DeliveryOrder;
8 use SL::DB::Manager::DeliveryOrder;
9 use SL::DB::Helper::LinkedRecords;
10 use SL::DB::Helper::TransNumberGenerator;
12 use List::Util qw(first);
14 __PACKAGE__->meta->add_relationship(orderitems => { type => 'one to many',
15 class => 'SL::DB::DeliveryOrderItem',
16 column_map => { id => 'delivery_order_id' },
17 manager_args => { with_objects => [ 'part' ] }
21 __PACKAGE__->meta->initialize;
23 __PACKAGE__->before_save('_before_save_set_donumber');
27 sub _before_save_set_donumber {
30 $self->create_trans_number if !$self->donumber;
37 sub items { goto &orderitems; }
42 return [ sort {$a->id <=> $b->id } @{ $self->items } ];
50 require SL::DB::Order;
51 my $orders = SL::DB::Manager::Order->get_all(
53 ordnumber => $self->ordnumber,
54 @{ $params{query} || [] },
58 return first { $_->is_type('sales_order') } @{ $orders };
62 return shift->customer_id ? 'sales_delivery_order' : 'purchase_delivery_order';
65 sub displayable_state {
69 ($self->closed ? $::locale->text('closed') : $::locale->text('open')),
70 ($self->delivered ? $::locale->text('delivered') : $::locale->text('not delivered'));