From: Bernd Bleßmann Date: Fri, 24 Jul 2020 09:25:42 +0000 (+0200) Subject: Auftrags-Controller: Wechselkurs pro Beleg … X-Git-Tag: release-3.5.6.1~93 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=598383b3b6b63428fcabc5fb6e5595ec59de28e3;p=kivitendo-erp.git Auftrags-Controller: Wechselkurs pro Beleg … - Wechselkurs wird pro Beleg gespeichert - Wechselkurs ist immer änderbar - vorausgefüllt aus "alter" Tages-Wechselkurstabelle Bezieht sich auch auf #135 Refs #135 --- diff --git a/SL/Controller/Order.pm b/SL/Controller/Order.pm index caa3f918d..5d3049267 100644 --- a/SL/Controller/Order.pm +++ b/SL/Controller/Order.pm @@ -934,7 +934,7 @@ sub action_update_exchangerate { my $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, + exchangerate => $self->order->daily_exchangerate_as_null_number, }; $self->render(\SL::JSON::to_json($data), { type => 'json', process => 0 }); @@ -1375,7 +1375,6 @@ sub make_order { my $form_orderitems = delete $::form->{order}->{orderitems}; my $form_periodic_invoices_config = delete $::form->{order}->{periodic_invoices_config}; - my $form_exchangerate_as_null_number = delete $::form->{order}->{exchangerate_as_null_number}; $order->assign_attributes(%{$::form->{order}}); @@ -1384,9 +1383,6 @@ sub make_order { $periodic_invoices_config->assign_attributes(%$periodic_invoices_config_attrs); } - # set exchangerate after transdate and currency_id - $order->assign_attributes(exchangerate_as_null_number => $form_exchangerate_as_null_number) if $order->currency_id; - # remove deleted items $self->item_ids_to_delete([]); foreach my $idx (reverse 0..$#{$order->orderitems}) { diff --git a/SL/DB/Helper/FlattenToForm.pm b/SL/DB/Helper/FlattenToForm.pm index a7198946c..9523c3579 100644 --- a/SL/DB/Helper/FlattenToForm.pm +++ b/SL/DB/Helper/FlattenToForm.pm @@ -42,7 +42,7 @@ sub flatten_to_form { ($vc eq 'customer')? 'c_vendor_id': 'v_customer_id'); my @vc_prefixed_fields = qw(email fax notes number phone); - _copy($self, $form, '', '', 1, qw(amount netamount marge_total marge_percent container_remaining_weight container_remaining_volume paid)); + _copy($self, $form, '', '', 1, qw(amount netamount marge_total marge_percent container_remaining_weight container_remaining_volume paid exchangerate)); _copy($self->$vc, $form, '', '', 0, @vc_fields); _copy($self->$vc, $form, $vc, '', 0, @vc_prefixed_fields); _copy($self->contact, $form, '', '', 0, grep { /^cp_/ } map { $_->name } SL::DB::Contact->meta->columns) if _has($self, 'cp_id'); diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index 1aa92b0fb..8d7088f49 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -277,7 +277,7 @@ sub new_from { } my %args = ( map({ ( $_ => $source->$_ ) } qw(amount cp_id currency_id cusordnumber customer_id delivery_customer_id delivery_term_id delivery_vendor_id - department_id employee_id globalproject_id intnotes marge_percent marge_total language_id netamount notes + department_id employee_id exchangerate globalproject_id intnotes marge_percent marge_total language_id netamount notes ordnumber payment_id quonumber reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id transaction_description vendor_id )), @@ -392,7 +392,7 @@ sub new_from_multi { } foreach my $attr (qw(cp_id currency_id employee_id salesman_id department_id delivery_customer_id delivery_vendor_id shipto_id - globalproject_id)) { + globalproject_id exchangerate)) { $attributes{$attr} = undef if any { ($sources->[0]->$attr||0) != ($_->$attr||0) } @$sources; } diff --git a/bin/mozilla/io.pl b/bin/mozilla/io.pl index a89a31197..62f16d7f3 100644 --- a/bin/mozilla/io.pl +++ b/bin/mozilla/io.pl @@ -56,6 +56,7 @@ use SL::PriceSource; use SL::Presenter::Part; use SL::DB::Contact; +use SL::DB::Currency; use SL::DB::Customer; use SL::DB::Default; use SL::DB::Language; @@ -910,9 +911,18 @@ sub order { _order(); if ($::instance_conf->get_feature_experimental_order) { + + # At this point, the record is saved and the exchangerate contains + # an unformatted value. _make_record uses RDBO attributes (i.e. _as_number) + # to assign values and thus expects an formatted value. + $::form->{exchangerate} = $::form->format_amount(\%::myconfig, $::form->{exchangerate}); + my $order = _make_record(); - $order->globalproject_id(undef) if !$order->globalproject_id; - $order->payment_id(undef) if !$order->payment_id; + + $order->currency(SL::DB::Currency->new(name => $::form->{currency})->load) if $::form->{currency}; + $order->globalproject_id(undef) if !$order->globalproject_id; + $order->payment_id(undef) if !$order->payment_id; + my $row = 1; foreach my $item (@{$order->items_sorted}) { $item->custom_variables([]); diff --git a/js/kivi.Order.js b/js/kivi.Order.js index 907e15bd3..592909686 100644 --- a/js/kivi.Order.js +++ b/js/kivi.Order.js @@ -174,6 +174,13 @@ namespace('kivi.Order', function(ns) { $(event.target).val(kivi.format_amount(kivi.parse_amount($(event.target).val()), -2)); }; + ns.reformat_number_as_null_number = function(event) { + if ($(event.target).val() === '') { + return; + } + ns.reformat_number(event); + }; + ns.update_exchangerate = function(event) { if (!ns.check_cv()) { $('#order_currency_id').val($('#old_currency_id').val()); @@ -181,7 +188,15 @@ namespace('kivi.Order', function(ns) { } var rate_input = $('#order_exchangerate_as_null_number'); - rate_input.prop('disabled', true); + // unset exchangerate if currency changed + if ($('#order_currency_id').val() !== $('#old_currency_id').val()) { + rate_input.val(''); + } + + // only set exchangerate if unset + if (rate_input.val() !== '') { + return; + } var data = $('#order_form').serializeArray(); data.push({ name: 'action', value: 'Order/update_exchangerate' }); @@ -194,17 +209,14 @@ namespace('kivi.Order', function(ns) { success: function(data){ if (!data.is_standard) { $('#currency_name').text(data.currency_name); - var rate_text = $('#exchangerate_text'); if (data.exchangerate) { - rate_text.text(data.exchangerate); - rate_input.hide(); + rate_input.val(data.exchangerate); } else { - rate_text.text(''); - rate_input.prop('disabled', false); - rate_input.show().val(''); + rate_input.val(''); } $('#exchangerate_settings').show(); } else { + rate_input.val(''); $('#exchangerate_settings').hide(); } if ($('#order_currency_id').val() != $('#old_currency_id').val() || @@ -892,4 +904,6 @@ $(function() { return false; }); + $('.reformat_number_as_null_number').change(kivi.Order.reformat_number_as_null_number); + }); diff --git a/templates/webpages/order/tabs/basic_data.html b/templates/webpages/order/tabs/basic_data.html index 94728b77c..f3806ff63 100644 --- a/templates/webpages/order/tabs/basic_data.html +++ b/templates/webpages/order/tabs/basic_data.html @@ -50,29 +50,17 @@ [% 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=currency_id, value_key='id', title_key='name') %] - + [% 'Exchangerate' | $T8 %] 1 [% SELF.order.currency.name %] = - - [% IF exchangerate %] - [% HTML.escape(exchangerate) %] - [% END %] - - [% IF currency_id==INSTANCE_CONF.get_currency_id || SELF.order.exchangerate %] - [% L.input_tag('order.exchangerate_as_null_number', '', size="15", class="reformat_number numeric", style='display:none', disabled=1) %] - [% ELSE %] - [% L.input_tag('order.exchangerate_as_null_number', '', size="15", class="reformat_number numeric") %] - [% END %] + [% L.input_tag('order.exchangerate_as_null_number', SELF.order.exchangerate_as_null_number, size="15", class="reformat_number_as_null_number numeric") %] [% INSTANCE_CONF.default_currency %] [% L.hidden_tag('old_currency_id', currency_id) %] - [% L.hidden_tag('old_exchangerate', exchangerate) %] + [% L.hidden_tag('old_exchangerate', SELF.order.exchangerate_as_null_number) %]