From: Moritz Bunkus Date: Tue, 3 Mar 2020 11:37:51 +0000 (+0100) Subject: make_record(_item): Unterstützung für Gutschriften X-Git-Tag: release-3.5.6.1~245^2~19 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=50fb51d9d1557790f30ce06756f9a805f93682e6;p=kivitendo-erp.git make_record(_item): Unterstützung für Gutschriften Bei Gutschriften stehen gewisse Werte in $::form positiv, die aber im Rose-Objekt negativ sein müssen. --- diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 718653383..c6439af7c 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -40,7 +40,7 @@ use Carp; use CGI; use List::MoreUtils qw(any uniq apply); -use List::Util qw(min max first); +use List::Util qw(sum min max first); use List::UtilsBy qw(sort_by uniq_by); use SL::ClientJS; @@ -1852,7 +1852,7 @@ sub _remove_billed_or_delivered_rows { # TODO: both of these are makeshift so that price sources can operate on rdbo objects. if # this ever gets rewritten in controller style, throw this out sub _make_record_item { - my ($row) = @_; + my ($row, %params) = @_; my $class = { sales_order => 'OrderItem', @@ -1922,6 +1922,11 @@ sub _make_record_item { $obj->part(SL::DB::Part->load_cached($::form->{"id_$row"})); } + if ($obj->can('qty')) { + $obj->qty( $obj->qty * $params{factor}); + $obj->base_qty($obj->base_qty * $params{factor}); + } + return $obj; } @@ -1941,6 +1946,8 @@ sub _make_record { : do { die 'unknown invoice type' }; } + my $factor = $::form->{type} =~ m{credit_note} ? -1 : 1; + return unless $class; $class = 'SL::DB::' . $class; @@ -1971,12 +1978,21 @@ sub _make_record { my @items; for my $i (1 .. $::form->{rowcount}) { next unless $::form->{"id_$i"}; - push @items, _make_record_item($i); + push @items, _make_record_item($i, factor => $factor); } $obj->items(@items) if @items; $obj->is_sales(!!$obj->customer_id) if $class eq 'SL::DB::DeliveryOrder'; + if ($class eq 'SL::DB::Invoice') { + my $paid = $factor * + sum + map { $::form->parse_amount(\%::myconfig, $::form->{$_}) } + grep { m{^paid_\d+$} } + keys %{ $::form }; + $obj->paid($paid); + } + return $obj; }