From: G. Richardson Date: Wed, 12 Jul 2017 15:43:15 +0000 (+0200) Subject: Artikel aus Belegen anlegen - Artikelklassifizierung berücksichtigen X-Git-Tag: release-3.5.4~1025 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ce904bd69f1eaafe99dbdda7956471b2ea219feb;p=kivitendo-erp.git Artikel aus Belegen anlegen - Artikelklassifizierung berücksichtigen Bei Verkaufsbelegen sollen im Dropdown nur Verkaufsklassifizierungen angezeigt werden, bei Einkaufsbelegen nur Einkaufsklassifizierungen. --- diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 869a5248c..da27a865e 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -26,6 +26,7 @@ use Rose::Object::MakeMethods::Generic ( assortment assortment_items assembly assembly_items all_pricegroups all_translations all_partsgroups all_units all_buchungsgruppen all_payment_terms all_warehouses + parts_classification_filter all_languages all_units all_price_factors) ], 'scalar' => [ qw(warehouse bin) ], ); @@ -75,6 +76,9 @@ sub action_add_from_record { check_has_valid_part_type($::form->{part}{part_type}); + die 'parts_classification_type must be "sales" or "purchases"' + unless $::form->{parts_classification_type} =~ m/^(sales|purchases)$/; + $self->parse_form; $self->add; } @@ -968,6 +972,15 @@ sub init_multi_items_models { ); } +sub init_parts_classification_filter { + return [] unless $::form->{parts_classification_type}; + + return [ used_for_sale => 't' ] if $::form->{parts_classification_type} eq 'sales'; + return [ used_for_purchase => 't' ] if $::form->{parts_classification_type} eq 'purchases'; + + die "no query rules for parts_classification_type " . $::form->{parts_classification_type}; +} + # simple checks to run on $::form before saving sub form_check_part_description_exists { diff --git a/SL/Presenter/Part.pm b/SL/Presenter/Part.pm index ac1bc8b79..8f13aeeb9 100644 --- a/SL/Presenter/Part.pm +++ b/SL/Presenter/Part.pm @@ -104,9 +104,13 @@ sub separate_abbreviation { # sub select_classification { my ($self, $name, %attributes) = @_; + $attributes{value_key} = 'id'; $attributes{title_key} = 'description'; - my $collection = SL::DB::Manager::PartClassification->get_all_sorted(); + + my $classification_type_filter = delete $attributes{type} // []; + + my $collection = SL::DB::Manager::PartClassification->get_all_sorted( where => $classification_type_filter ); $_->description($::locale->text($_->description)) for @{ $collection }; return $self->select_tag( $name, $collection, %attributes ); } diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index 15695215f..dee3b9a42 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -704,6 +704,8 @@ sub new_item { my $callback = build_std_url("action=return_from_new_item", "previousform=$previousform"); my $i = $::form->{rowcount}; + my $parts_classification_type = $::form->{vc} eq 'customer' ? 'sales' : 'purchases'; + my @HIDDENS; push @HIDDENS, { 'name' => 'callback', 'value' => $callback }; push @HIDDENS, map +{ 'name' => $_, 'value' => $::form->{$_} }, qw(rowcount vc); @@ -711,6 +713,8 @@ sub new_item { push @HIDDENS, { 'name' => "part.$price", 'value' => $::form->{"sellprice_$i"} }; push @HIDDENS, { 'name' => "part.notes", 'value' => $::form->{"longdescription_$i"} }; + push @HIDDENS, { 'name' => "parts_classification_type", 'value' => $parts_classification_type }; + $::form->header; print $::form->parse_html_template("generic/new_item", { HIDDENS => [ sort { $a->{name} cmp $b->{name} } @HIDDENS ] } ); } diff --git a/templates/webpages/part/_basic_data.html b/templates/webpages/part/_basic_data.html index 38b15d2e5..47202069c 100644 --- a/templates/webpages/part/_basic_data.html +++ b/templates/webpages/part/_basic_data.html @@ -23,7 +23,7 @@ [% 'Part Classification' | $T8 %] - [% P.select_classification('part.classification_id', default => SELF.part.classification_id) %] + [% P.select_classification('part.classification_id', default => SELF.part.classification_id, type => SELF.parts_classification_filter ) %] [% 'Part Description' | $T8 %]