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;
}
-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) = @_;
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__
account for the given taxzone (either the DB id or an instance of
L<SL::DB::TaxZone>).
+=item C<orphaned>
+
+Checks whether this Buchungsgruppe is assigned to any parts.
+
=back
=head1 BUGS