Zu Kontoauszug Zuordnung verbessern, alte Logik auch entfernen
[kivitendo-erp.git] / SL / DB / Buchungsgruppe.pm
index eb467c5..cad8bb6 100644 (file)
@@ -6,21 +6,22 @@ use SL::DB::MetaSetup::Buchungsgruppe;
 use SL::DB::Manager::Buchungsgruppe;
 use SL::DB::Helper::ActsAsList;
 
-__PACKAGE__->meta->add_relationship(
-  inventory_account => {
-    type          => 'many to one',
-    class         => 'SL::DB::Chart',
-    column_map    => { inventory_accno_id => 'id' },
-  },
-);
-
 __PACKAGE__->meta->initialize;
 
+sub inventory_account { goto &inventory_accno; }
+
 sub validate {
   my ($self) = @_;
 
   my @errors;
   push @errors, $::locale->text('The description is missing.') if !$self->description;
+  if( $self->inventory_accno_id ) {
+    require SL::DB::Chart;
+    my $inventory_accno = SL::DB::Manager::Chart->find_by( id => $self->inventory_accno_id );
+    push(@errors, $::locale->text('Booking group #1 needs a valid inventory account', $self->description)) unless $inventory_accno;
+  } else {
+    push @errors, $::locale->text('The booking group needs an inventory account.');
+  };
 
   return @errors;
 }