5 use SL::DB::MetaSetup::Unit;
6 use SL::DB::Manager::Unit;
8 __PACKAGE__->meta->add_relationships(
11 class => 'SL::DB::Unit',
12 column_map => { base_unit => 'name' },
16 __PACKAGE__->meta->initialize;
23 return $self if !$self->base_unit || $self->name eq $self->base_unit;
24 return $self->base->unit_class;
27 sub convertible_units {
30 sort { $a->sortkey <=> $b->sortkey }
31 grep { $_->unit_class->name eq $self->unit_class->name }
32 @{ SL::DB::Manager::Unit->get_all }
39 if (!defined $self->{__base_factor}) {
40 $self->{__base_factor} = !$self->base_unit || !$self->factor || ($self->name eq $self->base_unit) ? 1 : $self->factor * $self->base->base_factor;
43 return $self->{__base_factor};
47 my ($self, $qty, $other_unit) = @_;
49 my $my_base_factor = $self->base_factor || 1;
50 my $other_base_factor = $other_unit->base_factor || 1;
52 return $qty * $my_base_factor / $other_base_factor;