X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FOrder.pm;h=9e781734485e01648dd4fc09ebdf1b98ee908e79;hb=f16c552035ab973a9aed4a1dc29d0e16be7ff541;hp=89f602eb778f2f473eeeeea6422e684a802965b5;hpb=c50f095090b17ace42bfddfe2b50367b4757d1a9;p=kivitendo-erp.git diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index 89f602eb7..9e7817344 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -30,6 +30,12 @@ __PACKAGE__->meta->add_relationship( class => 'SL::DB::PeriodicInvoicesConfig', column_map => { id => 'oe_id' }, }, + custom_shipto => { + type => 'one to one', + class => 'SL::DB::Shipto', + column_map => { id => 'trans_id' }, + query_args => [ module => 'OE' ], + }, ); __PACKAGE__->meta->initialize; @@ -54,6 +60,7 @@ sub _before_save_set_ord_quo_number { # methods sub items { goto &orderitems; } +sub add_items { goto &add_orderitems; } sub items_sorted { my ($self) = @_; @@ -130,12 +137,12 @@ sub convert_to_invoice { croak("Conversion to invoices is only supported for sales records") unless $self->customer_id; my $invoice; - if (!$self->db->do_transaction(sub { + if (!$self->db->with_transaction(sub { require SL::DB::Invoice; $invoice = SL::DB::Invoice->new_from($self)->post(%params) || die; $self->link_to_record($invoice); $self->update_attributes(closed => 1); - # die; + 1; })) { return undef; } @@ -144,18 +151,19 @@ sub convert_to_invoice { } sub convert_to_delivery_order { - my ($self, %params) = @_; + my ($self, @args) = @_; my ($delivery_order, $custom_shipto); - if (!$self->db->do_transaction(sub { + if (!$self->db->with_transaction(sub { require SL::DB::DeliveryOrder; - ($delivery_order, $custom_shipto) = SL::DB::DeliveryOrder->new_from($self); + ($delivery_order, $custom_shipto) = SL::DB::DeliveryOrder->new_from($self, @args); $delivery_order->save; $custom_shipto->save if $custom_shipto; $self->link_to_record($delivery_order); - # die; + $self->update_attributes(delivered => 1); + 1; })) { - return undef; + return wantarray ? () : undef; } return wantarray ? ($delivery_order, $custom_shipto) : $delivery_order; @@ -212,7 +220,9 @@ Returns true if the order is of the given type. Creates a new delivery order with C<$self> as the basis by calling L. That delivery order is saved, and -C<$self> is linked to the new invoice via L. +C<$self> is linked to the new invoice via +L. C<$self>'s C attribute is set to +C, and C<$self> is saved. The arguments in C<%params> are passed to L.