From: Felix Eichler Date: Mon, 19 Aug 2019 07:04:41 +0000 (+0200) Subject: Auftragsschnellerfassung: Korrekturen für Währung/Wechselkurs X-Git-Tag: release-3.5.6.1~104 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=0956f2d427fe43c70fca245bc55ce85423b76ce8;p=kivitendo-erp.git Auftragsschnellerfassung: Korrekturen für Währung/Wechselkurs - Feld auf disabled setzen wenn nicht gebraucht - _as_null_number damit undef nicht zu 0 wird - Übersetzte Fehlermeldungen ticket #9491 (cherry picked from commit c581e4685a217bdd5b73380b1f808037a473dd9f) (cherry pick von odyn) --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index 5363e18a9..17b88fde6 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -929,12 +929,13 @@ sub action_recalc_amounts_and_taxes { sub action_update_exchangerate { my ($self) = @_; my $data = {}; - if ($self->order->currency_id != $::instance_conf->get_currency_id) { - $data = { - currency_name => $self->order->currency->name, - exchangerate => $self->order->exchangerate_as_number, - }; - } + + $data = { + is_standard => $self->order->currency_id == $::instance_conf->get_currency_id, + currency_name => $self->order->currency->name, + exchangerate => $self->order->exchangerate_as_null_number, + }; + $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 }); } @@ -1372,7 +1373,7 @@ sub make_order { my $form_orderitems = delete $::form->{order}->{orderitems}; my $form_periodic_invoices_config = delete $::form->{order}->{periodic_invoices_config}; - my $exchangerate = delete $::form->{order}->{exchangerate}; + my $exchangerate_as_null_number = delete $::form->{order}->{exchangerate_as_null_number}; $order->assign_attributes(%{$::form->{order}}); @@ -1382,7 +1383,7 @@ sub make_order { } # set exchangerate after transdate and currency_id - $order->assign_attributes(exchangerate => $exchangerate); + $order->assign_attributes(exchangerate_as_null_number => $exchangerate_as_null_number) if $order->currency_id; # remove deleted items $self->item_ids_to_delete([]); diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index 98a8c5a91..dac89d30e 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -18,6 +18,7 @@ use SL::DB::Helper::LinkedRecords; use SL::DB::Helper::PriceTaxCalculator; use SL::DB::Helper::PriceUpdater; use SL::DB::Helper::TransNumberGenerator; +use SL::Locale::String qw(t8); use SL::RecordLinks; use Rose::DB::Object::Helpers qw(as_tree); @@ -124,10 +125,13 @@ sub exchangerate { return 1 if $self->currency_id == $::instance_conf->get_currency_id; + # unable to determine if sales or purchase + return undef if !$self->has_customervendor; + my $rate = $self->is_sales ? 'buy' : 'sell'; if (defined $val) { - croak 'exchange rate has to be positive' if $val <= 0; + croak t8('exchange rate has to be positive') if $val <= 0; if (!$self->exchangerate_obj) { $self->exchangerate_obj(SL::DB::Exchangerate->new( currency_id => $self->currency_id, @@ -137,7 +141,7 @@ sub exchangerate { } elsif (!defined $self->exchangerate_obj->$rate) { $self->exchangerate_obj->$rate($val); } else { - croak 'exchange rate already exists, no update allowed'; + croak t8('exchange rate already exists, no update allowed'); } } return $self->exchangerate_obj->$rate if $self->exchangerate_obj; diff --git a/js/kivi.Order.js b/js/kivi.Order.js index 016212875..5f83a79fd 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -175,8 +175,8 @@ namespace('kivi.Order', function(ns) { }; ns.update_exchangerate = function(event) { - var rate_input = $('#order_exchangerate_as_number'); - rate_input.attr('name', ''); + var rate_input = $('#order_exchangerate_as_null_number'); + rate_input.prop('disabled', true); var data = $('#order_form').serializeArray(); data.push({ name: 'action', value: 'Order/update_exchangerate' }); @@ -187,7 +187,7 @@ namespace('kivi.Order', function(ns) { method: 'POST', dataType: 'json', success: function(data){ - if (data.currency_name) { + if (!data.is_standard) { $('#currency_name').text(data.currency_name); var rate_text = $('#exchangerate_text'); if (data.exchangerate) { @@ -195,13 +195,18 @@ namespace('kivi.Order', function(ns) { rate_input.hide(); } else { rate_text.text(''); - rate_input.show().attr('name', rate_input.data('name')).val(0); + rate_input.prop('disabled', false); + rate_input.show().val(0); } $('#exchangerate_settings').show(); } else { $('#exchangerate_settings').hide(); } - if ($('#order_currency_id').val() != $('#old_currency_id').val() || data.exchangerate != $('#old_exchangerate').val()) { + console.log(data.is_standard); + console.log(data.exchangerate); + console.log($('#old_exchangerate').val()); + if ($('#order_currency_id').val() != $('#old_currency_id').val() || + !data.is_standard && data.exchangerate != $('#old_exchangerate').val()) { kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please update prices.')); } $('#old_currency_id').val($('#order_currency_id').val()); @@ -211,9 +216,9 @@ namespace('kivi.Order', function(ns) { }; ns.exchangerate_changed = function(event) { - if (kivi.parse_amount($('#order_exchangerate_as_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) { + if (kivi.parse_amount($('#order_exchangerate_as_null_number').val()) != kivi.parse_amount($('#old_exchangerate').val())) { kivi.display_flash('warning', kivi.t8('You have changed the currency or exchange rate. Please update prices.')); - $('#old_exchangerate').val($('#order_exchangerate_as_number').val()); + $('#old_exchangerate').val($('#order_exchangerate_as_null_number').val()); } }; @@ -837,7 +842,7 @@ $(function() { $('#order_currency_id').change(kivi.Order.update_exchangerate); $('#order_transdate_as_date').change(kivi.Order.update_exchangerate); - $('#order_exchangerate_as_number').change(kivi.Order.exchangerate_changed); + $('#order_exchangerate_as_null_number').change(kivi.Order.exchangerate_changed); if ($('#type').val() == 'sales_order' || $('#type').val() == 'sales_quotation' ) { $('#add_item_parts_id').on('set_item:PartPicker', function(e,o) { $('#add_item_sellprice_as_number').val(kivi.format_amount(o.sellprice, -2)) }); diff --git a/locale/de/all b/locale/de/all index d08a24f5a..67240c10c 100755 --- a/locale/de/all +++ b/locale/de/all @@ -4135,6 +4135,8 @@ $self->{texts} = { 'error while unlinking payment #1 : ' => 'Fehler beim Zurücksetzen von Zahlung #1:', 'every third month' => 'vierteljährlich', 'every time' => 'immer', + 'exchange rate already exists, no update allowed' => 'Wechselkurs existiert bereits und kann nicht geändert werden', + 'exchange rate has to be positive' => 'Wechselkurs muss positiv sein', 'executed' => 'ausgeführt', 'execution as user \'#1\'' => 'Ausführung als User »#1«', 'failed' => 'fehlgeschlagen', diff --git a/templates/webpages/order/tabs/basic_data.html b/templates/webpages/order/tabs/basic_data.html index c54b8f30e..21377fef4 100644 --- a/templates/webpages/order/tabs/basic_data.html +++ b/templates/webpages/order/tabs/basic_data.html @@ -49,26 +49,30 @@ [% L.select_tag('order.taxzone_id', SELF.all_taxzones, default=SELF.order.taxzone_id, title_key='description', style='width: 300px', class='recalc') %] + [% SET currency_id = SELF.order.currency_id || INSTANCE_CONF.get_currency_id # use default currency for new order %] + [% IF SELF.order.exchangerate %] + [% SET exchangerate = SELF.order.exchangerate_as_null_number %] + [% END %] [% 'Currency' | $T8 %] - [% L.select_tag('order.currency_id', SELF.all_currencies, default=SELF.order.currency_id, value_key='id', title_key='name') %] + [% L.select_tag('order.currency_id', SELF.all_currencies, default=currency_id, value_key='id', title_key='name') %] - + [% 'Exchangerate' | $T8 %] 1 [% SELF.order.currency.name %] = - [% IF SELF.order.exchangerate %] - [% HTML.escape(SELF.order.exchangerate_as_number) %] + [% IF exchangerate %] + [% HTML.escape(exchangerate) %] [% END %] - [% IF !SELF.order.currency_id || SELF.order.currency_id==INSTANCE_CONF.get_currency_id || SELF.order.exchangerate %] - [% L.input_tag('', '', size="15", id='order_exchangerate_as_number', 'data-name'='order.exchangerate_as_number', style='display:none') %] + [% IF currency_id==INSTANCE_CONF.get_currency_id || SELF.order.exchangerate %] + [% L.input_tag('order.exchangerate_as_null_number', '', size="15", style='display:none', disabled=1) %] [% ELSE %] - [% L.input_tag('order.exchangerate_as_number', 0, size="15") %] + [% L.input_tag('order.exchangerate_as_null_number', 0, size="15") %] [% END %] [% INSTANCE_CONF.default_currency %] - [% L.hidden_tag('old_currency_id', SELF.order.currency_id) %] - [% L.hidden_tag('old_exchangerate', SELF.order.exchangerate_as_number) %] + [% L.hidden_tag('old_currency_id', currency_id) %] + [% L.hidden_tag('old_exchangerate', exchangerate) %]