From 86b6ff8a570d2fdc5fa53ba3dc9b3833e657e2e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Mon, 4 Aug 2014 12:58:59 +0200 Subject: [PATCH] =?utf8?q?Benutzerdef.=20Variablen=20f.=20Waren=20per=20Vo?= =?utf8?q?reinstellung=20f=C3=BCr=20Belege=20aktivieren/deaktivieren.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/CVar.pm | 4 ++- SL/Controller/CustomVariableConfig.pm | 26 ++++++++++++++++++- locale/de/all | 2 ++ locale/en/all | 2 ++ .../webpages/custom_variable_config/form.html | 13 ++++++++++ .../webpages/custom_variable_config/list.html | 2 ++ 6 files changed, 47 insertions(+), 2 deletions(-) diff --git a/SL/CVar.pm b/SL/CVar.pm index b15f82be2..99e46726b 100644 --- a/SL/CVar.pm +++ b/SL/CVar.pm @@ -132,6 +132,8 @@ sub get_custom_variables { $act_var = $h_var->fetchrow_hashref(); $valid = $self->get_custom_variables_validity(config_id => $cvar->{id}, trans_id => $params{trans_id}); + } else { + $valid = !$cvar->{flag_defaults_to_invalid}; } if ($act_var) { @@ -145,7 +147,7 @@ sub get_custom_variables { : $act_var->{text_value}; $cvar->{valid} = $valid; } else { - $cvar->{valid} = 1; + $cvar->{valid} = $valid // 1; if ($cvar->{type} eq 'date') { if ($cvar->{default_value} eq 'NOW') { diff --git a/SL/Controller/CustomVariableConfig.pm b/SL/Controller/CustomVariableConfig.pm index 28ed17929..a56740b8f 100644 --- a/SL/Controller/CustomVariableConfig.pm +++ b/SL/Controller/CustomVariableConfig.pm @@ -7,6 +7,7 @@ use parent qw(SL::Controller::Base); use List::Util qw(first); use SL::DB::CustomVariableConfig; +use SL::DB::CustomVariableValidity; use SL::Helper::Flash; use SL::Locale::String; use Data::Dumper; @@ -103,7 +104,7 @@ sub action_reorder { SL::DB::CustomVariableConfig->reorder_list(@{ $::form->{cvarcfg_id} || [] }); - $self->render(\'', { type => 'json' }); + $self->render(\'', { type => 'json' }); # ' make emacs happy } # @@ -179,10 +180,33 @@ sub create_or_update { return; } + my $dbh = $self->config->db; + $dbh->begin_work; + $self->config->save; + $self->_set_cvar_validity() if $is_new; + + $dbh->commit; flash_later('info', $is_new ? t8('The custom variable has been created.') : t8('The custom variable has been saved.')); $self->redirect_to(action => 'list', module => $self->module); } +sub _set_cvar_validity { + my ($self) = @_; + + my $flags = { + map { split m/=/, $_, 2 } + split m/:/, ($self->config->flags || '') + }; + + # nothing to do to set valid + return if !$flags->{defaults_to_invalid}; + + my $all_parts = SL::DB::Manager::Part->get_all(where => [ or => [ obsolete => 0, obsolete => undef ] ]); + foreach my $part (@{ $all_parts }) { + SL::DB::CustomVariableValidity->new(config_id => $self->config->id, trans_id => $part->id)->save; + } +} + 1; diff --git a/locale/de/all b/locale/de/all index f7f3ec3f0..6d5b183b4 100755 --- a/locale/de/all +++ b/locale/de/all @@ -52,6 +52,7 @@ $self->{texts} = { 'A transaction description is required.' => 'Die Vorgangsbezeichnung muss eingegeben werden.', 'A unit with this name does already exist.' => 'Eine Einheit mit diesem Namen existiert bereits.', 'A valid taxkey is missing!' => 'Einen gültiger Steuerschlüssel fehlt!', + 'A variable marked as \'Deactivate by default\' isn\'t automatically added to all articles, and has to be explicitly added for each desired article in its master data tab. Only then can the variable be used for that article in the records.' => 'Eine als \'Deaktiviert als Voreinstellung\' markierte Variable wird nicht automatisch bei allen Artikeln hinzugefügt, sondern muß explizit für jeden gewünschten Artikel in den Stammdaten aktiviert werden. Erst danach ist die Variable für den Artikel in Belegen bearbeitbar.', 'A variable marked as \'editable\' can be changed in each quotation, order, invoice etc.' => 'Eine als \'Bearbeitbar\' markierte Variable kann in jedem Angebot, Auftrag, jeder Rechnung etc für jede Position geändert werden.', 'ADDED' => 'Hinzugefügt', 'AP' => 'Einkauf', @@ -720,6 +721,7 @@ $self->{texts} = { 'Date the payment is due with discount' => 'Das Datum, bis die Rechnung unter Abzug von Skonto bezahlt werden kann', 'Datevautomatik' => 'Datev-Automatik', 'Datum von' => 'Datum von', + 'Deactivate by default' => 'Deaktiviert als Voreinstellung', 'Debit' => 'Soll', 'Debit (one letter abbreviation)' => 'S', 'Debit Account' => 'Sollkonto', diff --git a/locale/en/all b/locale/en/all index 30a729adc..ee05e7fbe 100644 --- a/locale/en/all +++ b/locale/en/all @@ -45,6 +45,7 @@ $self->{texts} = { 'A special character is required (valid characters: #1).' => '', 'A unit with this name does already exist.' => '', 'A valid taxkey is missing!' => '', + 'A variable marked as \'Deactivate by default\' isn\'t automatically added to all articles, and has to be explicitly added for each desired article in its master data tab. Only then can the variable be used for that article in the records.' => '', 'A variable marked as \'editable\' can be changed in each quotation, order, invoice etc.' => '', 'ADDED' => '', 'AP' => 'Purchases', @@ -633,6 +634,7 @@ $self->{texts} = { 'Date the payment is due with discount' => '', 'Datevautomatik' => '', 'Datum von' => '', + 'Deactivate by default' => '', 'Debit' => '', 'Debit (one letter abbreviation)' => '', 'Debit Account' => '', diff --git a/templates/webpages/custom_variable_config/form.html b/templates/webpages/custom_variable_config/form.html index 2703cdc1d..a34dd5da1 100644 --- a/templates/webpages/custom_variable_config/form.html +++ b/templates/webpages/custom_variable_config/form.html @@ -67,6 +67,13 @@ [% L.radio_button_tag('config.flag_editable', value='0', id='config.flag_editable_0', label=LxERP.t8('No'), checked=(SELF.flags.editable ? '' : 1)) %] + + [% 'Deactivate by default' | $T8 %](7) + + [% L.radio_button_tag('config.flag_defaults_to_invalid', value='1', id='config.flag_defaults_to_invalid_1', label=LxERP.t8('Yes'), checked=(SELF.flags.defaults_to_invalid ? 1 : '')) %] + [% L.radio_button_tag('config.flag_defaults_to_invalid', value='0', id='config.flag_defaults_to_invalid_0', label=LxERP.t8('No'), checked=(SELF.flags.defaults_to_invalid ? '' : 1)) %] + +

@@ -126,6 +133,12 @@ [% 'Otherwise the variable is only available for printing.' | $T8 %]

+

+ (7) + + [%- 'A variable marked as \'Deactivate by default\' isn\'t automatically added to all articles, and has to be explicitly added for each desired article in its master data tab. Only then can the variable be used for that article in the records.' | $T8 %] +

+