From: G. Richardson Date: Sat, 28 Feb 2015 14:52:01 +0000 (+0100) Subject: Ticket #42 - Nachkommastellen in Menge bei Erzeugniskomponenten X-Git-Tag: release-3.2.0~7 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=fd041aff03f8c1a948a6b38eee43224c05b909ec;p=kivitendo-erp.git Ticket #42 - Nachkommastellen in Menge bei Erzeugniskomponenten Danke an Joachim Zach für einen Patch, ich habe bei der Gelegenheit auch noch ein paar Codestellen kommentiert. Das Verhalten von item_selected bzgl. parse/format_amount unterscheidet sich mittlerweile je nachdem, ob es in Belegen oder in Erzeugnissen verwendet wird. --- diff --git a/bin/mozilla/ic.pl b/bin/mozilla/ic.pl index a51555372..906693126 100644 --- a/bin/mozilla/ic.pl +++ b/bin/mozilla/ic.pl @@ -1787,9 +1787,20 @@ sub update { $auth->assert('part_service_assembly_edit'); + # update checks whether pricegroups, makemodels or assembly items have been changed/added + # new items might have been added (and the original form might have been stored and restored) + # so at the end the ic form is run through check_form in io.pl + # The various combination of events can lead to problems with the order of parse_amount and format_amount + # Currently check_form parses some variables in assembly mode, but not in article or service mode + # This will only ever really be sanely resolved with a rewrite... + # parse pricegroups. and no, don't rely on check_form for this... map { $form->{"price_$_"} = $form->parse_amount(\%myconfig, $form->{"price_$_"}) } 1 .. $form->{price_rows}; - $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) for qw(sellprice listprice ve gv); + + unless ($form->{item} eq 'assembly') { + # for assemblies check_form will parse sellprice and listprice, but not for parts or services + $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) for qw(sellprice listprice ve gv); + }; if ($form->{item} eq 'part') { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) for qw(weight rop); @@ -1809,13 +1820,16 @@ sub update { if ( ($form->{"partnumber_$i"} eq "") && ($form->{"description_$i"} eq "") && ($form->{"partsgroup_$i"} eq "")) { + # no new assembly item was added &check_form; } else { - + # search db for newly added assemblyitems, via partnumber or description IC->assembly_item(\%myconfig, \%$form); + # form->{item_list} contains the possible matches, next check whether the + # match is unique or we need to call the page to select the item my $rows = scalar @{ $form->{item_list} }; if ($rows) { diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index a54f65deb..a2facb5a3 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -509,12 +509,17 @@ sub select_item { print $::form->parse_html_template('io/select_item', { PREVIOUS_FORM => $previous_form, MODE => $mode, ITEM_LIST => \@item_list, + IS_ASSEMBLY => $mode eq 'IC', IS_PURCHASE => $mode eq 'IS' }); $main::lxdebug->leave_sub(); } sub item_selected { + + # this function is used for adding parts to records (mode = IR/IS) + # and to assemblies (mode = IC) + $main::lxdebug->enter_sub(); my $form = $main::form; @@ -528,6 +533,13 @@ sub item_selected { my $id = delete($form->{select_item_id}) || croak 'Missing item selection ID'; my $i = $form->{ $mode eq 'IC' ? 'assembly_rows' : 'rowcount' }; + if ( $mode eq 'IC' ) { + # assembly mode: + # the qty variables of the existing assembly items are all still formatted, so we parse them here (1 .. $i-1) + # including the qty of the just added part ($i) + $form->{"qty_$_"} = $form->parse_amount(\%myconfig, $form->{"qty_$_"}) for (1 .. $i); + }; + $form->{"id_${i}"} = $id; if ($mode eq 'IS') { @@ -598,6 +610,7 @@ sub item_selected { map { $form->{$_} = $form->parse_amount(\%myconfig, $form->{$_}) } qw(sellprice listprice weight); + # at this stage qty of newly added part needs to be have been parsed $form->{weight} += ($form->{"weight_$i"} * $form->{"qty_$i"}); if ($form->{"not_discountable_$i"}) {