- if ($object->unit ne $object->part->unit) {
- $sellprice = $object->unit_obj->convert_to($sellprice, $object->part->unit_obj);
+ return if !$record->customervendor;
+
+ # If discount is given, set discount source to none.
+ if (exists $entry->{raw_data}->{discount}) {
+ $item->discount($item->discount/100.0) if $item->discount;
+ $item->discount(0) unless $item->discount;
+
+ my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
+ my $discount = $price_source->price_from_source('');
+ $item->active_discount_source($discount->source);
+
+ } else {
+ # Set discount the best discount of price source
+ my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
+ my $discount = $price_source->best_discount;
+ if ($discount) {
+ $item->discount($discount->discount);
+ $item->active_discount_source($discount->source);
+ } else {
+ $item->discount(0);
+ $item->active_discount_source($price_source->discount_from_source('')->source);