Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0409db7c

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

  • ID 0409db7c50da81e1eb613bd33663fb5b07935a01
  • Vorgänger eebe8e90
  • Nachfolger df1b03d5

PriceSource: Mehr Informationen an Preise übergeben

record + record_item verfügbar gemacht
best_price für pricegroups
Price: spec/source entzerrt

Unterschiede anzeigen:

SL/DB/Order.pm
15 15
use SL::DB::Helper::PriceUpdater;
16 16
use SL::DB::Helper::TransNumberGenerator;
17 17
use SL::RecordLinks;
18
use Rose::DB::Object::Helpers qw(as_tree);
18 19

  
19 20
__PACKAGE__->meta->add_relationship(
20 21
  orderitems => {
SL/PriceSource.pm
3 3
use strict;
4 4
use parent 'SL::DB::Object';
5 5
use Rose::Object::MakeMethods::Generic (
6
  scalar => [ qw(record_item) ],
6
  scalar => [ qw(record_item record) ],
7 7
);
8 8

  
9 9
use List::UtilsBy qw(min_by);
......
15 15
  my ($self) = @_;
16 16

  
17 17
  return map {
18
    $_->new(record_item => $self->record_item)
18
    $_->new(record_item => $self->record_item, record => $self->record)
19 19
  } SL::PriceSource::ALL->all_price_sources
20 20
}
21 21

  
SL/PriceSource/MasterData.pm
34 34

  
35 35
  return SL::PriceSource::Price->new(
36 36
    price        => $part->sellprice,
37
    source       => 'master_data/sellprice',
37
    spec         => 'sellprice',
38 38
    description  => t8('Sellprice'),
39 39
    price_source => $self,
40 40
  );
SL/PriceSource/Price.pm
4 4

  
5 5
use parent 'SL::DB::Object';
6 6
use Rose::Object::MakeMethods::Generic (
7
  scalar => [ qw(price description source price_source) ],
7
  scalar => [ qw(price description spec price_source) ],
8 8
  array => [ qw(depends_on) ]
9 9
);
10 10

  
11
sub source {
12
  $_[0]->price_source
13
  ?  $_[0]->price_source->name . '/' . $_[0]->spec
14
  : '';
15
}
16

  
11 17
sub full_description {
12 18
  my ($self) = @_;
13 19

  
SL/PriceSource/Pricegroup.pm
5 5

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

  
9 11
sub name { 'pricegroup' }
10 12

  
......
36 38
  return $self->make_price($price);
37 39
}
38 40

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

  
44
  my @prices    = $self->availabe_prices;
45
  my $customer  = $self->record->customer;
46
  my $min_price = min_by { $_->price } @prices;
47

  
48
  return $min_price if !$customer || !$customer->cv_klass;
49

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

  
52
  return $best_price || $min_price;
53
}
54

  
39 55
sub make_price {
40 56
  my ($self, $price_obj) = @_;
41 57

  
42 58
  SL::PriceSource::Price->new(
43 59
    price        => $price_obj->price,
44
    source       => 'pricegroup/' . $price_obj->id,
60
    spec         => $price_obj->id,
45 61
    description  => $price_obj->pricegroup->pricegroup,
46 62
    price_source => $self,
47 63
  )
bin/mozilla/io.pl
218 218

  
219 219
  my $totalweight = 0;
220 220

  
221
  my $record = _make_record();
221 222
  # rows
222 223

  
223 224
  my @ROWS;
......
233 234
      $form->{"sellprice_$i"} = $form->{"price_new_$i"};
234 235
    }
235 236

  
236
    my $record_item = _make_record_item($i);
237
    my $record_item = $record->items->[$i-1];
237 238

  
238 239
# unit begin
239 240
    $form->{"unit_old_$i"}      ||= $form->{"unit_$i"};
......
322 323
    $column_data{weight}      = $form->format_amount(\%myconfig, $form->{"qty_$i"} * $form->{"weight_$i"}, 3) . ' ' . $defaults->{weightunit} if $defaults->{show_weight};
323 324

  
324 325
    if ($form->{"id_${i}"}) {
325
      my $price_source = SL::PriceSource->new(record_item => $record_item);
326
      my $price_source = SL::PriceSource->new(record_item => $record_item, record => $record);
326 327
      my $price = $price_source->price_from_source($::form->{"active_price_source_$i"});
327 328
      $::form->{price_sources}[$i] = $price_source;
328 329
      $column_data{price_source} .= $cgi->button(-value => $price->full_description, -onClick => "toggle_price_source($i)");
......
1890 1891
  $::form->{rowcount} -= $removed_rows;
1891 1892
}
1892 1893

  
1894
# TODO: both of these are makeshift so that price sources can operate on rdbo objects. if
1895
# this ever gets rewritten in controller style, throw this out
1893 1896
sub _make_record_item {
1894 1897
  my ($row) = @_;
1895 1898

  
......
1918 1921
    next unless $obj->meta->column($method);
1919 1922
    if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
1920 1923
      $obj->${\"$method\_as_date"}($::form->{"$method\_$row"});
1924
    } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) {
1925
      $obj->${\"$method\_as\_number"}($::form->{$method});
1921 1926
    } else {
1922 1927
      $obj->$method($::form->{"$method\_$row"});
1923 1928
    }
......
1929 1934

  
1930 1935
  return $obj;
1931 1936
}
1937

  
1938
sub _make_record {
1939
  my $class = {
1940
    sales_order             => 'Order',
1941
    purchase_oder           => 'Order',
1942
    sales_quotation         => 'Order',
1943
    request_quotation       => 'Order',
1944
    invoice                 => 'Invoice',
1945
    purchase_invoice        => 'PurchaseInvoice',
1946
    purchase_delivery_order => 'DeliveryOrder',
1947
    sales_delivery_order    => 'DeliveryOrder',
1948
  }->{$::form->{type}};
1949

  
1950
  return unless $class;
1951

  
1952
  $class = 'SL::DB::' . $class;
1953

  
1954
  eval "require $class";
1955

  
1956
  my $obj = $::form->{id}
1957
          ? $class->meta->convention_manager->auto_manager_class_name->find_by(id => $::form->{id})
1958
          : $class->new;
1959

  
1960
  for my $method (keys %$::form) {
1961
    next unless $obj->can($method);
1962
    next unless $obj->meta->column($method);
1963

  
1964
    if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
1965
      $obj->${\"$method\_as_date"}($::form->{$method});
1966
    } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Numeric|Float|DoublePrecsion)$/) {
1967
      $obj->${\"$method\_as\_number"}($::form->{$method});
1968
    } else {
1969
      $obj->$method($::form->{$method});
1970
    }
1971
  }
1972

  
1973
  my @items;
1974
  for my $i (1 .. $::form->{rowcount}) {
1975
    next unless $::form->{"id_$i"};
1976
    push @items, _make_record_item($i)
1977
  }
1978

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

  
1981
  return $obj;
1982
}
1983

  
bin/mozilla/oe.pl
594 594

  
595 595
  check_oe_access();
596 596

  
597
  my $order = _make_record();
598

  
599 597
  set_headings($form->{"id"} ? "edit" : "add");
600 598

  
601 599
  $form->{update} = 1;
......
2111 2109
  $::form->error($::locale->text('No action defined.'));
2112 2110
}
2113 2111

  
2114
sub _make_record {
2115
  my $obj = SL::DB::Order->new;
2116

  
2117
  for my $method (keys %$::form) {
2118
    next unless $obj->can($method);
2119
    next unless $obj->meta->column($method);
2120

  
2121
    if ($obj->meta->column($method)->isa('Rose::DB::Object::Metadata::Column::Date')) {
2122
      $obj->${\"$method\_as_date"}($::form->{$method});
2123
    } elsif ((ref $obj->meta->column($method)) =~ /^Rose::DB::Object::Metadata::Column::(?:Integer|Numeric|Float|DoublePrecsion)$/) {
2124
      $obj->$method($::form->{$method});
2125
    }
2126
  }
2127

  
2128
  my @items;
2129
  for my $i (1 .. $::form->{rowcount}) {
2130
    next unless $::form->{"id_$i"};
2131
    push @items, _make_record_item($i)
2132
  }
2133

  
2134
  $obj->orderitems(@items);
2135

  
2136
  return $obj;
2137
}
2138

  

Auch abrufbar als: Unified diff