+sub handle_unit {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Set unit from part if not given.
+ if (!$object->unit) {
+ $object->unit($object->part->unit);
+ return 1;
+ }
+
+ # Check whether or not unit is valid.
+ if ($object->unit && !$self->units_by->{name}->{ $object->unit }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid unit');
+ return 0;
+ }
+
+ # Check whether unit is convertible to parts unit
+ if (none { $object->unit eq $_ } map { $_->name } @{ $object->part->unit_obj->convertible_units }) {
+ push @{ $entry->{errors} }, $::locale->text('Error: Invalid unit');
+ return 0;
+ }
+
+ return 1;
+}
+
+sub handle_sellprice {
+ my ($self, $entry) = @_;
+
+ my $object = $entry->{object};
+
+ # Set sellprice from part if not given. Convert with respect to unit.
+ if (!defined $object->sellprice) {
+ my $sellprice = $object->part->sellprice;
+
+ if ($object->unit ne $object->part->unit) {
+ $sellprice = $object->unit_obj->convert_to($sellprice, $object->part->unit_obj);
+ }
+ $object->sellprice($sellprice);
+ }
+}
+