X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FOrder.pm;h=a605a36892c6b8a473c337320da43f0e32ba45db;hb=55e399ab36e9b688a4bfbb7b90422fe33e9e14e7;hp=a3c9de0f5b2f6d2b544f23f8d3b5c2fdcb056d39;hpb=7664f50fac4a789932317d0e0d35e15bc2d7d1c4;p=kivitendo-erp.git diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index a3c9de0f5..a605a3689 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; @@ -130,11 +136,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; } @@ -143,18 +150,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; @@ -211,7 +219,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.