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.
8 use SL::DB::MetaSetup::Unit;
10 # Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
11 __PACKAGE__->meta->make_manager_class;
13 __PACKAGE__->meta->add_relationships(
16 class => 'SL::DB::Unit',
17 column_map => { base_unit => 'name' },
21 __PACKAGE__->meta->initialize;
28 return $self if !$self->base_unit || $self->name eq $self->base_unit;
29 return $self->base->unit_class;
32 sub convertible_units {
35 sort { $a->sortkey <=> $b->sortkey }
36 grep { $_->unit_class->name eq $self->unit_class->name }
37 @{ SL::DB::Manager::Unit->get_all }
44 if (!defined $self->{__base_factor}) {
45 $self->{__base_factor} = !$self->base_unit || !$self->factor || ($self->name eq $self->base_unit) ? 1 : $self->factor * $self->base->base_factor;
48 return $self->{__base_factor};
52 my ($self, $qty, $other_unit) = @_;
54 my $my_base_factor = $self->base_factor || 1;
55 my $other_base_factor = $other_unit->base_factor || 1;
57 return $qty * $my_base_factor / $other_base_factor;