X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FBuchungsgruppe.pm;h=9074fb90bfd41ed4a9bbea001b94bbaf3a8c7237;hb=4ddcd46105d2a7afc41220ba51a703f9e2aef034;hp=1b5bdad59bda17cd835aee205449e5ddce3d2344;hpb=1c62d23ef8305ca67a7cf19f69d4fb2939f972a0;p=kivitendo-erp.git diff --git a/SL/DB/Buchungsgruppe.pm b/SL/DB/Buchungsgruppe.pm index 1b5bdad59..9074fb90b 100644 --- a/SL/DB/Buchungsgruppe.pm +++ b/SL/DB/Buchungsgruppe.pm @@ -21,22 +21,17 @@ sub validate { 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('Buchungsgruppe #1 needs a valid inventory account', $self->description)) unless $inventory_accno; + } else { + push @errors, $::locale->text('The Buchungsgruppe needs an inventory account.'); + }; return @errors; } -sub inventory_accno { - my ($self) = @_; - require SL::DB::Manager::Chart; - return SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id) ? SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id)->accno() : undef; -} - -sub inventory_accno_description { - my ($self) = @_; - require SL::DB::Manager::Chart; - return SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id) ? SL::DB::Manager::Chart->find_by(id => $self->inventory_accno_id)->description() : undef; -} - sub income_accno_id { my ($self, $taxzone) = @_; @@ -85,6 +80,15 @@ sub taxzonecharts { return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]); } +sub orphaned { + my ($self) = @_; + die 'not an accessor' if @_ > 1; + + require SL::DB::Part; + return 0 if SL::DB::Manager::Part->get_all_count(query => [ buchungsgruppen_id => $self->id ]); + return 1; +} + 1; __END__ @@ -123,6 +127,10 @@ Return the chart (an instance of L) for the income account for the given taxzone (either the DB id or an instance of L). +=item C + +Checks whether this Buchungsgruppe is assigned to any parts. + =back =head1 BUGS