Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision df1b03d5

Von Sven Schöling vor etwa 10 Jahren hinzugefügt

  • ID df1b03d578280d71fb839b437505dd283f6dd749
  • Vorgänger 0409db7c
  • Nachfolger 2bdd0bc5

PriceSource: Featureabdeckung

- Einkaufs/Verkauf abgedeckt
- Klarere Regeln für price_from_source, available_prices und best_price
- makemodels unterstützung
- bugfixes für Rechnungen und neue Belege
- best_price jetzt getestet
- Verkäuferabhängigkeit von makemodels und pricegroup implementiert und getestet

Unterschiede anzeigen:

SL/PriceSource/ALL.pm
3 3
use strict;
4 4
use SL::PriceSource::Pricegroup;
5 5
use SL::PriceSource::MasterData;
6
use SL::PriceSource::Makemodel;
6 7

  
7 8
my %price_sources_by_name = (
8 9
  master_data => 'SL::PriceSource::MasterData',
9 10
  pricegroup  => 'SL::PriceSource::Pricegroup',
11
  makemodel   => 'SL::PriceSource::Makemodel',
10 12
);
11 13

  
12 14
my @price_sources_order = qw(
13 15
  master_data
14 16
  pricegroup
17
  makemodel
15 18
);
16 19

  
17 20
sub all_price_sources {
SL/PriceSource/Makemodel.pm
1
package SL::PriceSource::Makemodel;
2

  
3
use strict;
4
use parent qw(SL::PriceSource::Base);
5

  
6
use SL::PriceSource::Price;
7
use SL::Locale::String;
8
use SL::DB::MakeModel;
9
use List::UtilsBy qw(min_by);
10

  
11
sub name { 'makemodel' }
12

  
13
sub description { t8('Makemodel Price') }
14

  
15
sub available_prices {
16
  my ($self, %params) = @_;
17

  
18
  return () if !$self->part;
19
  return () if  $self->record->is_sales;
20

  
21
  map { $self->make_price_from_makemodel($_) }
22
  grep { $_->make == $self->record->vendor_id }
23
  $self->part->makemodels;
24
}
25

  
26
sub price_from_source {
27
  my ($self, $source, $spec) = @_;
28

  
29
  my $makemodel = SL::DB::Manager::MakeModel->find_by(id => $spec);
30

  
31
  # TODO: if someone deletes the prices entry, this fails. add a fallback
32
  return $self->make_price_from_makemodel($makemodel);
33

  
34
}
35

  
36
sub best_price {
37
  my ($self, %params) = @_;
38

  
39
  return () if $self->record->is_sales;
40

  
41
  min_by { $_->price } $self->available_prices;
42

  
43
}
44

  
45
sub make_price_from_makemodel {
46
  my ($self, $makemodel) = @_;
47

  
48
  return SL::PriceSource::Price->new(
49
    price        => $makemodel->lastcost,
50
    spec         => $makemodel->id,
51
    description  => $makemodel->model,
52
    price_source => $self,
53
  );
54
}
55

  
56

  
57
1;
SL/PriceSource/MasterData.pm
13 13
sub available_prices {
14 14
  my ($self, %params) = @_;
15 15

  
16
  my $part = $self->part;
16
  return () unless $self->part;
17 17

  
18
  return () unless $part;
19

  
20
  # TODO: sellprice only in sales, lastcost in purchase
21
  return $self->make_sellprice($part);
18
  grep { $_->price > 0 } $self->record->is_sales
19
    ? ($self->make_sellprice, $self->make_listprice)
20
    : ($self->make_lastcost,  $self->make_listprice);
22 21
}
23 22

  
24 23
sub price_from_source {
25 24
  my ($self, $source, $spec) = @_;
26 25

  
27
  if ($spec eq 'sellprice') {
28
    return $self->make_sellprice($self->part);
29
  }
26
    $spec eq 'sellprice' ? $self->make_sellprice
27
  : $spec eq 'lastcost'  ? $self->make_lastcost
28
  : $spec eq 'listprice' ? $self->make_listprice
29
  : do { die "unknown spec '$spec'" };
30
}
31

  
32
sub best_price {
33
  $_[0]->record->is_sales
34
  ? $_[0]->make_sellprice
35
  : $_[0]->make_lastcost
30 36
}
31 37

  
32 38
sub make_sellprice {
33
  my ($self, $part) = @_;
39
  my ($self) = @_;
34 40

  
35 41
  return SL::PriceSource::Price->new(
36
    price        => $part->sellprice,
42
    price        => $self->part->sellprice,
37 43
    spec         => 'sellprice',
38 44
    description  => t8('Sellprice'),
39 45
    price_source => $self,
40 46
  );
41 47
}
42 48

  
49
sub make_listprice {
50
  my ($self) = @_;
51

  
52
  return SL::PriceSource::Price->new(
53
    price        => $self->part->listprice,
54
    spec         => 'listprice',
55
    description  => t8('List Price'),
56
    price_source => $self,
57
  );
58
}
59

  
60
sub make_lastcost {
61
  my ($self) = @_;
62

  
63
  return SL::PriceSource::Price->new(
64
    price        => $self->part->lastcost,
65
    spec         => 'lastcost',
66
    description  => t8('Lastcost'),
67
    price_source => $self,
68
  );
69
}
70

  
43 71
1;
SL/PriceSource/Price.pm
8 8
  array => [ qw(depends_on) ]
9 9
);
10 10

  
11
use SL::DB::Helper::Attr;
12
SL::DB::Helper::Attr::make(__PACKAGE__,
13
  price => 'numeric(15,5)',
14
);
15

  
11 16
sub source {
12 17
  $_[0]->price_source
13 18
  ?  $_[0]->price_source->name . '/' . $_[0]->spec
......
22 27
    : $self->description
23 28
}
24 29

  
30
sub to_str {
31
  "source: @{[ $_[0]->source ]}, price: @{[ $_[0]->price]}, description: @{[ $_[0]->description ]}"
32
}
33

  
25 34
1;
SL/PriceSource/Pricegroup.pm
4 4
use parent qw(SL::PriceSource::Base);
5 5

  
6 6
use SL::PriceSource::Price;
7
use SL::DB::Price;
7 8
use SL::Locale::String;
8 9
use List::UtilsBy qw(min_by);
9 10
use List::Util qw(first);
......
15 16
sub available_prices {
16 17
  my ($self, %params) = @_;
17 18

  
19
  return () unless $self->record->is_sales;
20

  
18 21
  my $item = $self->record_item;
19 22

  
20 23
  my $prices = SL::DB::Manager::Price->get_all(
......
33 36
sub price_from_source {
34 37
  my ($self, $source, $spec) = @_;
35 38

  
36
  my $price = SL::DB::Manager::Price->find_by(id => $spec);
39
  my $price = SL::DB::Manager::Price->find_by(pricegroup_id => $spec, parts_id => $self->part->id);
37 40

  
41
  # TODO: if someone deletes the prices entry, this fails. add a fallback
38 42
  return $self->make_price($price);
39 43
}
40 44

  
41 45
sub best_price {
42 46
  my ($self, %params) = @_;
43 47

  
44
  my @prices    = $self->availabe_prices;
48
  return () unless $self->record->is_sales;
49

  
50
  my @prices    = $self->available_prices;
45 51
  my $customer  = $self->record->customer;
46
  my $min_price = min_by { $_->price } @prices;
47 52

  
48
  return $min_price if !$customer || !$customer->cv_klass;
53
  return () if !$customer || !$customer->klass;
49 54

  
50
  my $best_price = first { $_->spec == $customer->cv_class } @prices;
55
  my $best_price = first { $_->spec == $customer->klass } @prices;
51 56

  
52
  return $best_price || $min_price;
57
  return $best_price || ();
53 58
}
54 59

  
55 60
sub make_price {
......
57 62

  
58 63
  SL::PriceSource::Price->new(
59 64
    price        => $price_obj->price,
60
    spec         => $price_obj->id,
65
    spec         => $price_obj->pricegroup->id,
61 66
    description  => $price_obj->pricegroup->pricegroup,
62 67
    price_source => $self,
63 68
  )
bin/mozilla/io.pl
234 234
      $form->{"sellprice_$i"} = $form->{"price_new_$i"};
235 235
    }
236 236

  
237
    my $record_item = $record->items->[$i-1];
237
    my $record_item = $record->id && $record->items ? $record->items->[$i-1] : _make_record_item($i);
238 238

  
239 239
# unit begin
240 240
    $form->{"unit_old_$i"}      ||= $form->{"unit_$i"};
......
520 520

  
521 521
  map { $form->{"${_}_$i"} = $new_item->{$_} } @new_fields;
522 522

  
523
  my $record       = _make_record();
524
  my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
525
  my $best_price   = $price_source->best_price;
526

  
527
  if ($best_price) {
528
    $::form->{"sellprice_$i"}           = $best_price->price;
529
    $::form->{"active_price_source_$i"} = $best_price->source;
530
  }
531

  
532

  
523 533
  $form->{"marge_price_factor_$i"} = $new_item->{price_factor};
524 534

  
525 535
  if ($form->{"part_payment_id_$i"} ne "") {
......
1941 1951
    purchase_oder           => 'Order',
1942 1952
    sales_quotation         => 'Order',
1943 1953
    request_quotation       => 'Order',
1944
    invoice                 => 'Invoice',
1945
    purchase_invoice        => 'PurchaseInvoice',
1946 1954
    purchase_delivery_order => 'DeliveryOrder',
1947 1955
    sales_delivery_order    => 'DeliveryOrder',
1948 1956
  }->{$::form->{type}};
1949 1957

  
1958
  if ($::form->{type} eq 'invoice') {
1959
    $class = $::form->{vc} eq 'customer' ? 'Invoice'
1960
           : $::form->{vc} eq 'vendor'   ? 'PurchaseInvoice'
1961
           : do { die 'unknown invoice type' };
1962
  }
1963

  
1950 1964
  return unless $class;
1951 1965

  
1952 1966
  $class = 'SL::DB::' . $class;
......
1976 1990
    push @items, _make_record_item($i)
1977 1991
  }
1978 1992

  
1979
  $obj->orderitems(@items);
1993
  $obj->items(@items) if @items;
1980 1994

  
1981 1995
  return $obj;
1982 1996
}
bin/mozilla/oe.pl
678 678
        if ($sellprice) {
679 679
          $form->{"sellprice_$i"} = $sellprice;
680 680
        } else {
681
          my $record       = _make_record();
682
          my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
683
          my $best_price   = $price_source->best_price;
684

  
685
          if ($best_price) {
686
            $::form->{"sellprice_$i"}           = $best_price->price;
687
            $::form->{"active_price_source_$i"} = $best_price->source;
688
          }
689

  
681 690
          $form->{"sellprice_$i"} *= (1 - $form->{tradediscount});
682 691
          $form->{"sellprice_$i"} /= $exchangerate;   # if there is an exchange rate adjust sellprice
683 692
        }
locale/de/all
1442 1442
  'Make (vendor\'s database ID, number or name; with X being a number)' => 'Lieferant (Datenbank-ID, Nummer oder Name des Lieferanten; X ist eine fortlaufende Zahl)',
1443 1443
  'Make compatible for import'  => 'Für den Import kompatibel machen',
1444 1444
  'Make default profile'        => 'Zu Standardprofil machen',
1445
  'Makemodel Price'             => 'Lieferantenpreis',
1445 1446
  'Manage Custom Variables'     => 'Benutzerdefinierte Variablen',
1446 1447
  'Mandantennummer'             => 'Mandantennummer',
1447 1448
  'Mandate Date of Signature'   => 'Mandat-Unterschriftsdatum',

Auch abrufbar als: Unified diff