Invoice, DeliveryOrder-DB: bei Erstellen aus anderen Belegen Preisquellen beibehalten
[kivitendo-erp.git] / SL / DB / Invoice.pm
index a84324c..e8b49c4 100644 (file)
@@ -45,6 +45,15 @@ __PACKAGE__->meta->add_relationship(
     column_map      => { id => 'trans_id' },
     query_args      => [ module => 'AR' ],
   },
+  transactions   => {
+    type         => 'one to many',
+    class        => 'SL::DB::AccTransaction',
+    column_map   => { id => 'trans_id' },
+    manager_args => {
+      with_objects => [ 'chart' ],
+      sort_by      => 'acc_trans_id ASC',
+    },
+  },
 );
 
 __PACKAGE__->meta->initialize;
@@ -69,7 +78,7 @@ sub add_items { goto &add_invoiceitems; }
 sub items_sorted {
   my ($self) = @_;
 
-  return [ sort {$a->id <=> $b->id } @{ $self->items } ];
+  return [ sort {$a->position <=> $b->position } @{ $self->items } ];
 }
 
 sub is_sales {
@@ -187,7 +196,7 @@ sub new_from {
 
     SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) }
                                  qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit
-                                    base_qty longdescription lastcost price_factor_id), @item_columns),
+                                    base_qty longdescription lastcost price_factor_id active_discount_source active_price_source), @item_columns),
                              deliverydate     => $source_item->reqdate,
                              fxsellprice      => $source_item->sellprice,
                              custom_variables => \@custom_variables,
@@ -330,27 +339,25 @@ sub displayable_type {
 }
 
 sub abbreviation {
-  my $self = shift;
+  my ($self) = @_;
 
-  return t8('AR Transaction (abbreviation)') if !$self->invoice;
-  return t8('Credit note (one letter abbreviation)') if $self->type eq 'credit_note' && $self->amount < 0 && !$self->storno;
-  return t8('Invoice (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->type ne 'credit_note' && $self->amount < 0 &&  $self->storno;
-  return t8('Credit note (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->type eq 'credit_note' && $self->amount > 0 &&  $self->storno;
+  return t8('AR Transaction (abbreviation)')         if $self->invoice_type eq 'ar_transaction';
+  return t8('Credit note (one letter abbreviation)') if $self->invoice_type eq 'credit_note';
+  return t8('Invoice (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")" if $self->invoice_type eq 'invoice_storno';
+  return t8('Credit note (one letter abbreviation)') . "(" . t8('Storno (one letter abbreviation)') . ")"  if $self->invoice_type eq 'credit_note_storno';
   return t8('Invoice (one letter abbreviation)');
-
 }
 
 sub date {
   goto &transdate;
 }
 
-sub transactions {
-  my ($self) = @_;
-
-  return unless $self->id;
+sub reqdate {
+  goto &duedate;
+}
 
-  require SL::DB::AccTransaction;
-  SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $self->id ]);
+sub customervendor {
+  goto &customer;
 }
 
 1;