From 30e1cefc44fe755fcfd222e60ba895815420fb66 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 4 Aug 2014 10:39:56 +0200 Subject: [PATCH] =?utf8?q?Pflichtenheftauftr=C3=A4ge:=20Aktualisierung=20z?= =?utf8?q?us=C3=A4tzlicher=20Artikel=20implementiert?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RequirementSpecOrder.pm | 85 +++++++++++++------ locale/de/all | 4 + .../requirement_spec_order/update.html | 9 ++ 3 files changed, 74 insertions(+), 24 deletions(-) diff --git a/SL/Controller/RequirementSpecOrder.pm b/SL/Controller/RequirementSpecOrder.pm index d256396b8..b02c985bc 100644 --- a/SL/Controller/RequirementSpecOrder.pm +++ b/SL/Controller/RequirementSpecOrder.pm @@ -66,7 +66,7 @@ sub action_create { $sections_by_id{ $_->{id} }->update_attributes(order_part_id => $_->{order_part_id}) for @{ $section_attrs }; # 2. Create actual quotation/order. - my $order = $self->create_order(sections => $sections, additional_parts => [ $self->requirement_spec->parts ]); + my $order = $self->create_order(sections => $sections, additional_parts => $self->requirement_spec->parts_sorted); $order->db->with_transaction(sub { $order->save; @@ -120,31 +120,13 @@ sub action_update { } sub action_do_update { - my ($self) = @_; - - my $order = $self->rs_order->order; - my $sections = $self->requirement_spec->sections_sorted; - my %orderitems_by_id = map { ($_->id => $_) } @{ $order->orderitems }; - my %sections_by_id = map { ($_->id => $_) } @{ $sections }; - $self->{parts} = { map { ($_->id => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq map { $_->order_part_id } @{ $sections } ] ]) } }; - my $language_id = $self->requirement_spec->customer->language_id; - - my %sections_seen; - - foreach my $attributes (@{ $::form->{orderitems} || [] }) { - my $orderitem = $orderitems_by_id{ $attributes->{id} }; - my $section = $sections_by_id{ $attributes->{section_id} }; - next unless $orderitem && $section; - - $self->create_order_item(section => $section, item => $orderitem, language_id => $language_id)->save; - $sections_seen{ $section->id } = 1; - } + my ($self) = @_; - my @new_orderitems = map { $self->create_order_item(section => $_, language_id => $language_id) } - grep { !$sections_seen{ $_->id } } - @{ $sections }; + my $order = $self->rs_order->order; + my @new_orderitems = $self->do_update_sections; + push @new_orderitems, $self->do_update_additional_parts; - $order->orderitems([ @{ $order->orderitems }, @new_orderitems ]) if @new_orderitems; + $order->add_orderitems(\@new_orderitems) if @new_orderitems; $order->calculate_prices_and_taxes; @@ -244,6 +226,61 @@ sub init_all_parts_time_unit { # helpers # +sub do_update_sections { + my ($self) = @_; + + my $order = $self->rs_order->order; + my $sections = $self->requirement_spec->sections_sorted; + my %orderitems_by_id = map { ($_->id => $_) } @{ $order->orderitems }; + my %sections_by_id = map { ($_->id => $_) } @{ $sections }; + $self->{parts} = { map { ($_->id => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq map { $_->order_part_id } @{ $sections } ] ]) } }; + my $language_id = $self->requirement_spec->customer->language_id; + + my %sections_seen; + + foreach my $attributes (@{ $::form->{orderitems} || [] }) { + my $orderitem = $orderitems_by_id{ $attributes->{id} }; + my $section = $sections_by_id{ $attributes->{section_id} }; + next unless $orderitem && $section; + + $self->create_order_item(section => $section, item => $orderitem, language_id => $language_id)->save; + $sections_seen{ $section->id } = 1; + } + + my @new_orderitems = map { $self->create_order_item(section => $_, language_id => $language_id) } + grep { !$sections_seen{ $_->id } } + @{ $sections }; + + return @new_orderitems; +} + +sub do_update_additional_parts { + my ($self) = @_; + + my $order = $self->rs_order->order; + my $add_parts = $self->requirement_spec->parts_sorted; + my %orderitems_by = map { (($_->parts_id . '-' . $_->description) => $_) } @{ $order->items }; + $self->{parts} = { map { ($_->id => $_) } @{ SL::DB::Manager::Part->get_all(where => [ id => [ uniq map { $_->part_id } @{ $add_parts } ] ]) } }; + my $language_id = $self->requirement_spec->customer->language_id; + + my %add_part_seen; + my @new_orderitems; + + foreach my $add_part (@{ $add_parts }) { + my $key = $add_part->part_id . '-' . $add_part->description; + my $orderitem = $orderitems_by{$key}; + + if ($orderitem) { + $self->create_additional_part_order_item(additional_part => $add_part, item => $orderitem, language_id => $language_id)->save; + + } else { + push @new_orderitems, $self->create_additional_part_order_item(additional_part => $add_part, language_id => $language_id); + } + } + + return @new_orderitems; +} + sub create_order_item { my ($self, %params) = @_; diff --git a/locale/de/all b/locale/de/all index b29a899e4..05c80185b 100755 --- a/locale/de/all +++ b/locale/de/all @@ -2615,6 +2615,7 @@ $self->{texts} = { 'Therefore several settings that had to be made for each user in the past have been consolidated into the client configuration.' => 'Dazu wurden gewisse Einstellungen, die vorher bei jedem Benutzer vorgenommen werden mussten, in die Konfiguration eines Mandanten verschoben.', 'Therefore the definition of "kg" with the base unit "g" and a factor of 1000 is valid while defining "g" with a base unit of "kg" and a factor of "0.001" is not.' => 'So ist die Definition von "kg" mit der Basiseinheit "g" und dem Faktor 1000 zulässig, die Definition von "g" mit der Basiseinheit "kg" und dem Faktor "0,001" hingegen nicht.', 'These wrong entries cannot be fixed automatically.' => 'Diese Einträge können nicht automatisch bereinigt werden.', + 'They will be updated, new ones for additional parts without a line item added automatically.' => 'Diese Positionen werden automatisch aktualisiert bzw. ergänzt, wenn es noch keine Position zu einem zusätzlichen Artikel gibt.', 'This can be done with the following query:' => 'Dies kann mit der folgenden Datenbankabfrage erreicht werden:', 'This could have happened for two reasons:' => 'Dies kann aus zwei Gründen geschehen sein:', 'This customer number is already in use.' => 'Diese Kundennummer wird bereits verwendet.', @@ -2751,6 +2752,8 @@ $self->{texts} = { 'Update with section' => 'Mit Abschnitt aktualisieren', 'Updated' => 'Erneuert am', 'Updating existing entry in database' => 'Existierenden Eintrag in Datenbank aktualisieren', + 'Updating items with additional parts' => 'Positionen für zusätzliche Artikel aktualisieren', + 'Updating items with sections' => 'Positionen für Abschnitte aktualisieren', 'Updating prices of existing entry in database' => 'Preis des Eintrags in der Datenbank wird aktualisiert', 'Updating the client fields in the database "#1" on host "#2:#3" failed.' => 'Die Aktualisierung der Mandantenfelder in der Datenbank "#1" auf Host "#2:#3" schlug fehl.', 'Uploaded at' => 'Hochgeladen um', @@ -2870,6 +2873,7 @@ $self->{texts} = { 'You cannot continue before all required modules are installed.' => 'Sie können nicht fortfahren, bevor alle benötigten Pakete installiert sind.', 'You cannot create an invoice for delivery orders for different customers.' => 'Sie können keine Rechnung zu Lieferscheinen für verschiedene Kunden erstellen.', 'You cannot create an invoice for delivery orders from different vendors.' => 'Sie können keine Rechnung aus Lieferscheinen von verschiedenen Lieferanten erstellen.', + 'You cannot modify individual assigments from additional articles to line items.' => 'Eine individuelle Zuordnung der zusätzlichen Artikel zu Positionen kann nicht vorgenommen werden.', 'You cannot paste function blocks or sub function blocks if there is no section.' => 'Sie können keine Funktionsblöcke oder Unterfunktionsblöcke einfügen, wenn es noch keinen Abschnitt gibt.', 'You do not have the permissions to access this function.' => 'Sie verfügen nicht über die notwendigen Rechte, um auf diese Funktion zuzugreifen.', 'You have entered or selected the following shipping address for this customer:' => 'Sie haben die folgende Lieferadresse eingegeben oder ausgewählt:', diff --git a/templates/webpages/requirement_spec_order/update.html b/templates/webpages/requirement_spec_order/update.html index 13b37980a..34b890eea 100644 --- a/templates/webpages/requirement_spec_order/update.html +++ b/templates/webpages/requirement_spec_order/update.html @@ -13,6 +13,8 @@
+

[% LxERP.t8("Updating items with sections") %]

+ [% L.hidden_tag("rs_order_id", SELF.rs_order.id, no_id=1) %] @@ -44,6 +46,13 @@ [% LxERP.t8("Sections that are not assigned to any of the items above will be added as new positions.") %]

+

[% LxERP.t8("Updating items with additional parts") %]

+ +

+ [% LxERP.t8("You cannot modify individual assigments from additional articles to line items.") %] + [% LxERP.t8("They will be updated, new ones for additional parts without a line item added automatically.") %] +

+

[% L.button_tag("kivi.requirement_spec.standard_quotation_order_ajax_call('do_update')", LxERP.t8('Update')) %]

-- 2.20.1