From: Jan Büren Date: Mon, 17 May 2021 07:26:49 +0000 (+0200) Subject: Erzeugnisse zerlegen über eindeutige trans_id X-Git-Tag: kivitendo-mebil_0.1-0~9^2~223 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=8453789b42c168bbaec52a87527191a25d9b2080;p=kivitendo-erp.git Erzeugnisse zerlegen über eindeutige trans_id Durch 639c7f18be0 ist die Hilfstabelle für die Zerlegung von Erzeugnissen nicht mehr notwendig und das Verfahren kann entsprechend simpler implementiert werden. --- diff --git a/SL/WH.pm b/SL/WH.pm index 722916bf1..3efe8c0fa 100644 --- a/SL/WH.pm +++ b/SL/WH.pm @@ -530,7 +530,7 @@ sub get_warehouse_journal { }; $form->{l_classification_id} = 'Y'; - $form->{l_id} = 'Y'; + $form->{l_trans_id} = 'Y'; $form->{l_part_type} = 'Y'; $form->{l_itime} = 'Y'; $form->{l_invoice_id} = $form->{l_oe_id} if $form->{l_oe_id}; @@ -1346,10 +1346,13 @@ unsuccessfully with a return value of undef. There has to be at least one data set in the table assembly referenced to this assembly_id. -=item Assembly cannot be destroyed or disassembled +=item Assembly can be disassembled Assemblies are like cakes. You cannot disassemble it. NEVER. - No negative nor zero qty's are valid inputs. + But if your assembly is a mechanical cake you may unscrew it. + Assemblies are created in one transaction therefore you can + safely rely on the trans_id in inventory to disassemble the + created assemblies (see action disassemble_assembly in wh.pl). =item The assembly item(s) have to be in the same warehouse diff --git a/bin/mozilla/wh.pl b/bin/mozilla/wh.pl index 26986c723..06d5f8b23 100644 --- a/bin/mozilla/wh.pl +++ b/bin/mozilla/wh.pl @@ -51,7 +51,6 @@ use SL::ReportGenerator; use SL::Presenter::Tag qw(checkbox_tag); use SL::Presenter::Part; -use SL::DB::AssemblyInventoryPart; use SL::DB::Part; use Data::Dumper; @@ -560,37 +559,18 @@ sub disassemble_assembly { croak("No assembly ids") unless scalar @{ $form->{ids}} > 0; - # fail safe, only allow disassemble in certain intervals - my $undo_date = DateTime->today->subtract(days => $::instance_conf->get_undo_transfer_interval); - - foreach my $assembly_id (@{ $::form->{ids}} ) { - my $assembly_parts; - $assembly_parts = SL::DB::Manager::AssemblyInventoryPart->get_all(where => [ inventory_assembly_id => $assembly_id ]); - $form->show_generic_error(t8('No relations found for #1', $assembly_id)) unless $assembly_parts; - # check first entry for insertdate - # everything in one transaction - my $db = SL::DB::Inventory->new->db; - $db->with_transaction(sub { - my ($assembly_entry, $part_entry); - foreach my $assembly_part (@{ $assembly_parts }) { - die("No valid entry found") unless (ref($assembly_part) eq 'SL::DB::AssemblyInventoryPart'); - # fail safe undo date - die("Invalid time interval") unless DateTime->compare($assembly_part->itime, $undo_date); - - $assembly_entry //= $assembly_part->assembly; - $part_entry = $assembly_part->part; - $assembly_part->delete; - $part_entry->delete; - } - flash_later('info', t8("Disassembly successful for #1", $assembly_entry->part->partnumber)); + # everything in one transaction + my $db = SL::DB::Inventory->new->db; + $db->with_transaction(sub { - $assembly_entry->delete; - - 1; + foreach my $trans_id (@{ $::form->{ids}} ) { + SL::DB::Manager::Inventory->delete_all(where => [ trans_id => $trans_id ]); + flash_later('info', t8("Disassembly successful for trans_id #1", $trans_id)); + } - }) || die t8('error while disassembling assembly #1 : #2', $assembly_id) . $db->error . "\n"; + 1; + }) || die t8('error while disassembling for trans_ids #1 : #2', $form->{ids}) . $db->error . "\n"; - } $main::lxdebug->leave_sub(); $form->redirect; } @@ -670,7 +650,10 @@ sub generate_journal { $last_nr = $pages->{per_page}; } + my $old_l_trans_id = $form->{l_trans_id}; my @contents = WH->get_warehouse_journal(%filter); + $form->{l_trans_id} = $old_l_trans_id; + # get maxcount if (!$form->{maxrows}) { $form->{maxrows} = scalar @contents ; @@ -752,7 +735,7 @@ sub generate_journal { ); my $idx = 0; - + my $undo_date = DateTime->today->subtract(days => $::instance_conf->get_undo_transfer_interval); foreach my $entry (@contents) { $entry->{type_and_classific} = SL::Presenter::Part::type_abbreviation($entry->{part_type}) . SL::Presenter::Part::classification_abbreviation($entry->{classification_id}); @@ -768,8 +751,13 @@ sub generate_journal { }; } - $row->{ids}->{raw_data} = checkbox_tag("ids[]", value => $entry->{id}, "data-checkall" => 1) if $entry->{assembled}; - + if ($entry->{assembled}) { + my $insertdate = DateTime->from_kivitendo($entry->{shippingdate}); + if (ref $undo_date eq 'DateTime' && ref $insertdate eq 'DateTime') { + my $undo_assembly = DateTime->compare($insertdate, $undo_date) == 1 ? 1 : 0; + $row->{ids}->{raw_data} = checkbox_tag("ids[]", value => $entry->{trans_id}, "data-checkall" => 1) if $undo_assembly; + } + } $row->{trans_type}->{raw_data} = $entry->{trans_type}; if ($form->{l_oe_id}) { $row->{oe_id}->{data} = '';