Bei Verkaufsbelegen sollen im Dropdown nur Verkaufsklassifizierungen angezeigt werden,
bei Einkaufsbelegen nur Einkaufsklassifizierungen.
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) ],
);
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;
}
);
}
+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 {
#
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 );
}
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);
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 ] } );
}
</tr>
<tr>
<th align="right">[% 'Part Classification' | $T8 %]</th>
- <td>[% P.select_classification('part.classification_id', default => SELF.part.classification_id) %]</td>
+ <td>[% P.select_classification('part.classification_id', default => SELF.part.classification_id, type => SELF.parts_classification_filter ) %]</td>
</tr>
<tr>
<th align="right">[% 'Part Description' | $T8 %]</th>