From b7afa934d4ce656536645a97253e4d7ec27e380c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Mon, 9 Nov 2020 16:21:15 +0100 Subject: [PATCH] =?utf8?q?Neuer=20Angebots-/Auftragscontroller:=20Unterst?= =?utf8?q?=C3=BCtzung=20f=C3=BCr=20Artikel=C3=BCbersetzungen=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bisher nur beim Hinzfügen von Artikeln. --- SL/Controller/Order.pm | 41 ++++++++++++++++++++++++++++++++++++----- js/kivi.Order.js | 9 +++++---- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 9f1ca0ec5..780e80ea2 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -22,6 +22,7 @@ use SL::DB::Printer; use SL::DB::Language; use SL::DB::RecordLink; use SL::DB::Shipto; +use SL::DB::Translation; use SL::Helper::CreatePDF qw(:all); use SL::Helper::PrintOptions; @@ -1005,7 +1006,7 @@ sub action_get_item_longdescription { if ($::form->{item_id}) { $longdescription = SL::DB::OrderItem->new(id => $::form->{item_id})->load->longdescription; } elsif ($::form->{parts_id}) { - $longdescription = SL::DB::Part->new(id => $::form->{parts_id})->load->notes; + $longdescription = get_part_texts($::form->{parts_id}, $::form->{language_id})->{longdescription}; } $_[0]->render(\ $longdescription, { type => 'text' }); } @@ -1459,9 +1460,13 @@ sub make_item { $item ||= SL::DB::OrderItem->new(custom_variables => []); $item->assign_attributes(%$attr); - $item->longdescription($item->part->notes) if $is_new && !defined $attr->{longdescription}; - $item->project_id($record->globalproject_id) if $is_new && !defined $attr->{project_id}; - $item->lastcost($record->is_sales ? $item->part->lastcost : 0) if $is_new && !defined $attr->{lastcost_as_number}; + + if ($is_new) { + my $texts = get_part_texts($item->part, $record->language_id); + $item->longdescription($texts->{longdescription}) if !defined $attr->{longdescription}; + $item->project_id($record->globalproject_id) if !defined $attr->{project_id}; + $item->lastcost($record->is_sales ? $item->part->lastcost : 0) if !defined $attr->{lastcost_as_number}; + } return $item; } @@ -1533,7 +1538,9 @@ sub new_item { # saved. Adding empty custom_variables to new orderitem here solves this problem. $new_attr{custom_variables} = []; - $item->assign_attributes(%new_attr); + my $texts = get_part_texts($part, $record->language_id, description => $new_attr{description}, longdescription => $new_attr{longdescription}); + + $item->assign_attributes(%new_attr, %{ $texts }); return $item; } @@ -2069,6 +2076,30 @@ sub get_item_cvpartnumber { } } +sub get_part_texts { + my ($part_or_id, $language_or_id, %defaults) = @_; + + my $part = ref($part_or_id) ? $part_or_id : SL::DB::Part->load_cached($part_or_id); + my $language_id = ref($language_or_id) ? $language_or_id->id : $language_or_id; + my $texts = { + description => $defaults{description} // $part->description, + longdescription => $defaults{longdescription} // $part->notes, + }; + + return $texts unless $language_id; + + my $translation = SL::DB::Manager::Translation->get_first( + where => [ + parts_id => $part->id, + language_id => $language_id, + ]); + + $texts->{description} = $translation->translation if $translation && $translation->translation; + $texts->{longdescription} = $translation->longdescription if $translation && $translation->longdescription; + + return $texts; +} + sub sales_order_type { 'sales_order'; } diff --git a/js/kivi.Order.js b/js/kivi.Order.js index e57d00937..c23466eab 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -586,10 +586,11 @@ namespace('kivi.Order', function(ns) { if (!longdescription_elt.length) { var data = [ - { name: 'action', value: 'Order/get_item_longdescription' }, - { name: 'type', value: $('#type').val() }, - { name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() }, - { name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() } + { name: 'action', value: 'Order/get_item_longdescription' }, + { name: 'type', value: $('#type').val() }, + { name: 'language_id', value: $('#order_language_id').val() }, + { name: 'item_id', value: $(row).find('[name="order.orderitems[+].id"]').val() }, + { name: 'parts_id', value: $(row).find('[name="order.orderitems[].parts_id"]').val() } ]; $.ajax({ -- 2.20.1