Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 9b93901e

Von Bernd Bleßmann vor 8 Monaten 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
20 20

  
21 21
use SL::Util qw(trim);
22 22
use SL::Locale::String qw(t8);
23
use SL::PriceSource;
23 24

  
24 25

  
25 26
sub update_after_new {
......
101 102
  return;
102 103
}
103 104

  
105
sub get_best_price_and_discount_source {
106
  my ($class, $record, $item, %flags) = @_;
107

  
108
  my $ignore_given = !!$flags{ignore_given};
109

  
110
  my $price_source = SL::PriceSource->new(record_item => $item, record => $record);
111

  
112
  my $price_src;
113
  if ( $item->part->is_assortment ) {
114
    # add assortment items with price 0, as the components carry the price
115
    $price_src = $price_source->price_from_source("");
116
    $price_src->price(0);
117
  } elsif (!$ignore_given && defined $item->sellprice) {
118
    $price_src = $price_source->price_from_source("");
119
    $price_src->price($item->sellprice);
120
  } else {
121
    $price_src = $price_source->best_price
122
               ? $price_source->best_price
123
               : $price_source->price_from_source("");
124
    $price_src->price($::form->round_amount($price_src->price / $record->exchangerate, 5)) if $record->exchangerate;
125
    $price_src->price(0) if !$price_source->best_price;
126
  }
127

  
128
  my $discount_src;
129
  if (!$ignore_given && defined $item->discount) {
130
    $discount_src = $price_source->discount_from_source("");
131
    $discount_src->discount($item->discount);
132
  } else {
133
    $discount_src = $price_source->best_discount
134
                  ? $price_source->best_discount
135
                  : $price_source->discount_from_source("");
136
    $discount_src->discount(0) if !$price_source->best_discount;
137
  }
138

  
139
  return ($price_src, $discount_src);
140
}
141

  
104 142
sub delete {
105 143
  my ($class, $record, %flags) = @_;
106 144

  
......
403 441

  
404 442
Increments the record's subversion number.
405 443

  
444
=item C<get_best_price_and_discount_source>
445

  
446
Get the best price and discount source for an item. You have
447
to pass the record and the item.
448

  
449
If the flag C<ignore_given> is not set and a price or discount already exists
450
for this item, these will be used. This means, that the price source and
451
discount source are set to empty and price of the price source is set to
452
the existing price and/or the discount of the discount source is set to
453
the existing discount.
454

  
455
If the flag C<ignore_given> is set, the best price and discount source
456
is determined via C<SL::PriceSource> and a given price or discount in the
457
item will be ignored. This can be used to get an default price/discount
458
that can be displayed to the user even if a price/discount is already
459
entered.
460

  
461
Returns an reference to an array where the first element is the best
462
price source and the second element is the best discount source.
463

  
406 464
=item C<delete>
407 465

  
408 466
Expects a record to delete.
t/model/records.t
152 152
SL::Model::Record->save($combined_order);
153 153
cmp_ok($combined_order->netamount, '==', 3*710, "netamount of combined order ok");
154 154

  
155

  
156
note "testing get price and discount sources";
157
reset_state();
158
reset_basic_sales_records();
159
reset_basic_purchase_records();
160

  
161
$purchase_quotation1->items_sorted->[0]->part->sellprice(500);
162
$purchase_quotation1->items_sorted->[0]->part->lastcost(300);
163
$purchase_quotation1->vendor->discount(5.0);
164

  
165
my ($price_source, $discount_source) = SL::Model::Record->get_best_price_and_discount_source($purchase_quotation1,
166
                                                                                             $purchase_quotation1->items_sorted->[0],
167
                                                                                             ignore_given => 1);
168
is($price_source->source_description, 'Master Data', 'get price source right with ignore_given');
169
is($price_source->price, 300, 'get price source purchase price right with ignore_given');
170
is($discount_source->source_description, 'Vendor Discount', 'get discount source right with ignore_given');
171
is($discount_source->discount, 5, 'get discount source purchase discount right with ignore_given');
172

  
173
$purchase_quotation1->items_sorted->[0]->discount(3);
174

  
175
($price_source, $discount_source)    = SL::Model::Record->get_best_price_and_discount_source($purchase_quotation1,
176
                                                                                             $purchase_quotation1->items_sorted->[0],
177
                                                                                             ignore_given => 0);
178
is($price_source->source_description, 'None (PriceSource)', 'get price source right with given price');
179
is($price_source->price, 70, 'get price source purchase price right with given price');
180
is($discount_source->source_description, 'None (PriceSource Discount)', 'get price source right with given price');
181
is($discount_source->discount, 3, 'get discount source purchase discount right with given price');
182

  
155 183
clear_up();
156 184
done_testing;
157 185

  

Auch abrufbar als: Unified diff