RDBO Support.
[kivitendo-erp.git] / SL / DB / Unit.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::Unit;
5
6 use strict;
7
8 use SL::DB::MetaSetup::Unit;
9
10 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
11 __PACKAGE__->meta->make_manager_class;
12
13 __PACKAGE__->meta->add_relationships(
14   base => {
15     type         => 'one to one',
16     class        => 'SL::DB::Unit',
17     column_map   => { base_unit => 'name' },
18   },
19 );
20
21 __PACKAGE__->meta->initialize;
22
23 #methods
24
25 sub unit_class {
26   my $self   = shift;
27
28   return $self if !$self->base_unit || $self->name eq $self->base_unit;
29   return $self->base->unit_class;
30 }
31
32 sub convertible_units {
33   my $self = shift;
34   return [
35     sort { $a->sortkey <=> $b->sortkey }
36     grep { $_->unit_class->name eq $self->unit_class->name }
37     @{ SL::DB::Manager::Unit->get_all }
38   ];
39 }
40
41 1;