From: G. Richardson Date: Thu, 10 Nov 2016 15:38:39 +0000 (+0100) Subject: AssortmentItem - sellprice von pricegroups X-Git-Tag: release-3.5.4~1877 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ed438fb59bb67ed5196695fcf8141f5d2083fb70;p=kivitendo-erp.git AssortmentItem - sellprice von pricegroups --- diff --git a/SL/DB/AssortmentItem.pm b/SL/DB/AssortmentItem.pm index 4aca0c1b4..6ed474f43 100644 --- a/SL/DB/AssortmentItem.pm +++ b/SL/DB/AssortmentItem.pm @@ -12,10 +12,21 @@ use Rose::DB::Object::Helpers qw(clone); __PACKAGE__->meta->initialize; sub linetotal_sellprice { - my ($self) = @_; - - return 0 unless $self->qty > 0 and $self->part->sellprice > 0; - return $self->qty * $self->part->sellprice / ( $self->part->price_factor_id ? $self->part->price_factor->factor : 1 ); + my ($self, %params) = @_; + + my $sellprice = $self->part->sellprice; + if ($params{pricegroup}) { + my $pricegroup = SL::DB::Manager::Pricegroup->find_by( pricegroup => $params{pricegroup}); + die "Can't find pricegroup with name " . $params{pricegroup} unless $pricegroup; + $params{pricegroup_id} = $pricegroup->id if $pricegroup; + } + if ($params{pricegroup_id}) { + my $price = SL::DB::Manager::Price->find_by(pricegroup_id => $params{pricegroup_id}, parts_id => $self->part->id); + $sellprice = $price->price if $price; + } + + return 0 unless $self->qty > 0 and $sellprice > 0; + return $self->qty * $sellprice / ( $self->part->price_factor_id ? $self->part->price_factor->factor : 1 ); } sub linetotal_lastcost {