Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9b93901e

Von Bernd Bleßmann vor etwa 1 Jahr hinzugefügt

  • ID 9b93901ef000fc93c3c6e961b36c34a3315c5928
  • Vorgänger 8f8375c5
  • Nachfolger a3e1833a

S:M:Record: Methode, um beste Preis- und Rabattquellen zu holen

Unterschiede anzeigen:

SL/Model/Record.pm
use SL::Util qw(trim);
use SL::Locale::String qw(t8);
use SL::PriceSource;
sub update_after_new {
......
return;
}
sub get_best_price_and_discount_source {
my ($class, $record, $item, %flags) = @_;
my $ignore_given = !!$flags{ignore_given};
my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
my $price_src;
if ( $item->part->is_assortment ) {
# add assortment items with price 0, as the components carry the price
$price_src = $price_source->price_from_source("");
$price_src->price(0);
} elsif (!$ignore_given && defined $item->sellprice) {
$price_src = $price_source->price_from_source("");
$price_src->price($item->sellprice);
} else {
$price_src = $price_source->best_price
? $price_source->best_price
: $price_source->price_from_source("");
$price_src->price($::form->round_amount($price_src->price / $record->exchangerate, 5)) if $record->exchangerate;
$price_src->price(0) if !$price_source->best_price;
}
my $discount_src;
if (!$ignore_given && defined $item->discount) {
$discount_src = $price_source->discount_from_source("");
$discount_src->discount($item->discount);
} else {
$discount_src = $price_source->best_discount
? $price_source->best_discount
: $price_source->discount_from_source("");
$discount_src->discount(0) if !$price_source->best_discount;
}
return ($price_src, $discount_src);
}
sub delete {
my ($class, $record, %flags) = @_;
......
Increments the record's subversion number.
=item C<get_best_price_and_discount_source>
Get the best price and discount source for an item. You have
to pass the record and the item.
If the flag C<ignore_given> is not set and a price or discount already exists
for this item, these will be used. This means, that the price source and
discount source are set to empty and price of the price source is set to
the existing price and/or the discount of the discount source is set to
the existing discount.
If the flag C<ignore_given> is set, the best price and discount source
is determined via C<SL::PriceSource> and a given price or discount in the
item will be ignored. This can be used to get an default price/discount
that can be displayed to the user even if a price/discount is already
entered.
Returns an reference to an array where the first element is the best
price source and the second element is the best discount source.
=item C<delete>
Expects a record to delete.
t/model/records.t
SL::Model::Record->save($combined_order);
cmp_ok($combined_order->netamount, '==', 3*710, "netamount of combined order ok");
note "testing get price and discount sources";
reset_state();
reset_basic_sales_records();
reset_basic_purchase_records();
$purchase_quotation1->items_sorted->[0]->part->sellprice(500);
$purchase_quotation1->items_sorted->[0]->part->lastcost(300);
$purchase_quotation1->vendor->discount(5.0);
my ($price_source, $discount_source) = SL::Model::Record->get_best_price_and_discount_source($purchase_quotation1,
$purchase_quotation1->items_sorted->[0],
ignore_given => 1);
is($price_source->source_description, 'Master Data', 'get price source right with ignore_given');
is($price_source->price, 300, 'get price source purchase price right with ignore_given');
is($discount_source->source_description, 'Vendor Discount', 'get discount source right with ignore_given');
is($discount_source->discount, 5, 'get discount source purchase discount right with ignore_given');
$purchase_quotation1->items_sorted->[0]->discount(3);
($price_source, $discount_source) = SL::Model::Record->get_best_price_and_discount_source($purchase_quotation1,
$purchase_quotation1->items_sorted->[0],
ignore_given => 0);
is($price_source->source_description, 'None (PriceSource)', 'get price source right with given price');
is($price_source->price, 70, 'get price source purchase price right with given price');
is($discount_source->source_description, 'None (PriceSource Discount)', 'get price source right with given price');
is($discount_source->discount, 3, 'get discount source purchase discount right with given price');
clear_up();
done_testing;

Auch abrufbar als: Unified diff