1 package SL::PriceSource::Vendor;
4 use parent qw(SL::PriceSource::Base);
7 use SL::PriceSource::Price;
8 use SL::Locale::String;
10 sub name { 'vendor_discount' }
12 sub description { t8('Vendor Discount') }
14 sub available_prices { }
16 sub available_discounts {
17 my ($self, %params) = @_;
19 return if $self->record->is_sales;
20 return unless $self->record->vendor;
21 return unless $self->record->vendor->discount != 0;
23 SL::PriceSource::Vendor->new(
24 discount => $self->record->vendor->discount,
25 spec => $self->record->vendor->id,
26 description => t8('Vendor Discount'),
27 price_source => $self,
31 sub price_from_source {
32 my ($self, $source, $spec) = @_;
34 my $vendor = SL::DB::Vendor->load_cached($spec);
37 return SL::PriceSource::Discount->new(
38 missing => t8('Could not load this vendor'),
39 price_source => $self,
43 if (!$self->record->vendor) {
44 return SL::PriceSource::Discount->new(
45 discount => $vendor->discount,
47 description => t8('Vendor Discount'),
48 price_source => $self,
49 invalid => t8('This discount is only valid in purchase documents'),
53 if ($vendor->id != $self->record->vendor->id) {
54 return SL::PriceSource::Discount->new(
55 discount => $vendor->discount,
57 description => t8('Vendor Discount'),
58 price_source => $self,
59 invalid => t8('This discount is only valid for vendor #1', $vendor->full_description),
63 return SL::PriceSource::Discount->new(
64 discount => $vendor->discount,
66 description => t8('Vendor Discount'),
67 price_source => $self,