X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;ds=sidebyside;f=SL%2FController%2FPart.pm;h=5dc37b45a2b4e20b147f45d05c4eac951e8b9086;hb=aa63ebae1c0a758ec438c594acb328b1f0e5e001;hp=6b40493f415126423796b3123a6deba09ccf0f95;hpb=77807bf531a9c3f945b2de1fc970439be5e95e70;p=kivitendo-erp.git diff --git a/SL/Controller/Part.pm b/SL/Controller/Part.pm index 6b40493f4..5dc37b45a 100644 --- a/SL/Controller/Part.pm +++ b/SL/Controller/Part.pm @@ -13,6 +13,7 @@ use SL::Helper::Flash; use Data::Dumper; use DateTime; use SL::DB::History; +use SL::DB::Helper::ValidateAssembly qw(validate_assembly); use SL::CVar; use Carp; @@ -250,7 +251,7 @@ sub action_update_item_totals { ->html('#items_sum_diff', $::form->format_amount(\%::myconfig, $sum_diff, 2, 0)) ->html('#items_sellprice_sum_basic', $::form->format_amount(\%::myconfig, $sellprice_sum, 2, 0)) ->html('#items_lastcost_sum_basic', $::form->format_amount(\%::myconfig, $lastcost_sum, 2, 0)) - ->render(); + ->no_flash_clear->render(); } sub action_add_multi_assortment_items { @@ -270,7 +271,14 @@ sub action_add_multi_assembly_items { my ($self) = @_; my $item_objects = $self->parse_add_items_to_objects(part_type => 'assembly'); - my $html = $self->render_assembly_items_to_html($item_objects); + my @checked_objects; + foreach my $item (@{$item_objects}) { + my $errstr = validate_assembly($item->part,$self->part); + $self->js->flash('error',$errstr) if $errstr; + push (@checked_objects,$item) unless $errstr; + } + + my $html = $self->render_assembly_items_to_html(\@checked_objects); $self->js->run('kivi.Part.close_multi_items_dialog') ->append('#assembly_rows', $html) @@ -313,6 +321,7 @@ sub action_add_assortment_item { ->html('#items_lastcost_sum_basic', $::form->format_amount(\%::myconfig, $items_lastcost_sum, 2, 0)) ->render; } + sub action_add_assembly_item { my ($self) = @_; @@ -321,6 +330,7 @@ sub action_add_assembly_item { carp('Too many objects passed to add_assembly_item') if @{$::form->{add_items}} > 1; my $add_item_id = $::form->{add_items}->[0]->{parts_id}; + my $duplicate_warning = 0; # duplicates are allowed, just warn if ( $add_item_id && grep { $add_item_id == $_->parts_id } @{ $self->assembly_items } ) { $duplicate_warning++; @@ -328,6 +338,14 @@ sub action_add_assembly_item { my $number_of_items = scalar @{$self->assembly_items}; my $item_objects = $self->parse_add_items_to_objects(part_type => 'assembly'); + if ($add_item_id ) { + foreach my $item (@{$item_objects}) { + my $errstr = validate_assembly($item->part,$self->part); + return $self->js->flash('error',$errstr)->render if $errstr; + } + } + + my $html = $self->render_assembly_items_to_html($item_objects, $number_of_items); $self->js->flash('info', t8("This part has already been added.")) if $duplicate_warning; @@ -457,20 +475,23 @@ sub action_reorder_items { sub action_warehouse_changed { my ($self) = @_; - $self->warehouse(SL::DB::Manager::Warehouse->find_by_or_create(id => $::form->{warehouse_id})); - die unless ref($self->warehouse) eq 'SL::DB::Warehouse'; + if ($::form->{warehouse_id} ) { + $self->warehouse(SL::DB::Manager::Warehouse->find_by_or_create(id => $::form->{warehouse_id})); + die unless ref($self->warehouse) eq 'SL::DB::Warehouse'; - if ( $self->warehouse->id and @{$self->warehouse->bins} ) { - $self->bin($self->warehouse->bins->[0]); - $self->js - ->html('#bin', $self->build_bin_select) - ->focus('#part_bin_id'); - } else { - # no warehouse was selected, empty the bin field and reset the id - $self->js - ->val('#part_bin_id', undef) - ->html('#bin', ''); - }; + if ( $self->warehouse->id and @{$self->warehouse->bins} ) { + $self->bin($self->warehouse->bins->[0]); + $self->js + ->html('#bin', $self->build_bin_select) + ->focus('#part_bin_id'); + return $self->js->render; + } + } + + # no warehouse was selected, empty the bin field and reset the id + $self->js + ->val('#part_bin_id', undef) + ->html('#bin', ''); return $self->js->render; } @@ -488,6 +509,7 @@ sub action_ajax_autocomplete { query => [ obsolete => 0, SL::DB::Manager::Part->type_filter($::form->{filter}{part_type}), + SL::DB::Manager::PartClassification->classification_filter($::form->{filter}{classification_id}), or => [ description => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, partnumber => { ilike => $::form->{filter}{'all:substr:multi::ilike'} }, @@ -647,8 +669,8 @@ sub parse_form { my $params = delete($::form->{part}) || { }; delete $params->{id}; - # never overwrite existing partnumber, should be a read-only field anyway - delete $params->{partnumber} if $self->part->partnumber; + # never overwrite existing partnumber for parts in use, should be a read-only field in that case anyway + delete $params->{partnumber} if $self->part->partnumber and not $self->orphaned; $self->part->assign_attributes(%{ $params}); $self->part->bin_id(undef) unless $self->part->warehouse_id; @@ -789,7 +811,7 @@ sub init_models { partnumber => t8('Partnumber'), description => t8('Description'), }, - with_objects => [ qw(unit_obj) ], + with_objects => [ qw(unit_obj classification) ], ); } @@ -912,7 +934,7 @@ sub init_multi_items_models { SL::Controller::Helper::GetModels->new( controller => $_[0], model => 'Part', - with_objects => [ qw(unit_obj partsgroup) ], + with_objects => [ qw(unit_obj partsgroup classification) ], disable_plugin => 'paginated', source => $::form->{multi_items}, sorted => {