From: G. Richardson Date: Mon, 4 Aug 2014 10:07:54 +0000 (+0200) Subject: Neue Methode orphaned für Buchungsgruppe X-Git-Tag: release-3.2.0beta~365 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=d3801bc92648bd7284b543162299fa31a0a0eb77;p=kivitendo-erp.git Neue Methode orphaned für Buchungsgruppe Zum Prüfen, ob eine Buchungsgruppe gelöscht oder bearbeitet werden kann. --- diff --git a/SL/Controller/Buchungsgruppen.pm b/SL/Controller/Buchungsgruppen.pm index 3ecba1369..aac6f73ab 100644 --- a/SL/Controller/Buchungsgruppen.pm +++ b/SL/Controller/Buchungsgruppen.pm @@ -61,14 +61,12 @@ sub show_form { sub action_edit { my ($self) = @_; - # Allow editing of Buchungsgruppe if it isn't assigned to any parts. The - # variable is checked in the template, which toggles between L.select_tag and - # text. - - my $number_of_parts_with_buchungsgruppe = SL::DB::Manager::Part->get_objects_count(where => [ buchungsgruppen_id => $self->config->id]); + # Allow editing of the charts of the Buchungsgruppe if it isn't assigned to + # any parts. This is checked inside the template via the Buchungsgruppen + # orphaned method, where an IF-ELSE statement toggles between L.select_tag + # and text. $self->show_form(title => t8('Edit Buchungsgruppe'), - linked_parts => $number_of_parts_with_buchungsgruppe, CHARTLIST => SL::DB::TaxzoneChart->get_all_accounts_by_buchungsgruppen_id($self->config->id)); } @@ -147,11 +145,8 @@ sub create_or_update { $self->config->save; - # check whether there are any assigned parts - my $number_of_parts_with_buchungsgruppe = SL::DB::Manager::Part->get_objects_count(where => [ buchungsgruppen_id => $self->config->id]); - - # Save or update taxzone_charts: - if ($is_new or $number_of_parts_with_buchungsgruppe == 0) { + # Save or update taxzone_charts for new or unused Buchungsgruppen + if ($is_new or $self->config->orphaned) { my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted(); foreach my $tz (@{ $taxzones }) { diff --git a/SL/DB/Buchungsgruppe.pm b/SL/DB/Buchungsgruppe.pm index 3504e2a41..d3ddcccb1 100644 --- a/SL/DB/Buchungsgruppe.pm +++ b/SL/DB/Buchungsgruppe.pm @@ -72,6 +72,15 @@ sub taxzonecharts { my ($self) = @_; return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]); } + +sub orphaned { + my ($self) = @_; + die 'not an accessor' if @_ > 1; + + require SL::DB::Part; + return 0 if SL::DB::Manager::Part->get_all_count(query => [ buchungsgruppen_id => $self->id ]); + return 1; +} 1; __END__ @@ -111,6 +120,10 @@ Return the chart (an instance of L) for the income account for the given taxzone (either the DB id or an instance of L). +=item C + +Checks whether this Buchungsgruppe is assigned to any parts. + =back =head1 BUGS diff --git a/templates/webpages/buchungsgruppen/form.html b/templates/webpages/buchungsgruppen/form.html index 9fe2fd9db..04b7496ac 100644 --- a/templates/webpages/buchungsgruppen/form.html +++ b/templates/webpages/buchungsgruppen/form.html @@ -12,9 +12,9 @@ [% 'Inventory account' | $T8 %] - [%- IF SELF.config.id AND linked_parts != 0 %] + [%- IF SELF.config.id AND NOT SELF.config.orphaned %] [%- CHARTLIST.inventory_accno %] -- [%- CHARTLIST.inventory_accno_description %] - [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %] + [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %] [%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.defaults.inventory_accno_id) %] [%- ELSE %] [%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.config.inventory_accno_id) %] @@ -23,9 +23,9 @@ [%- FOREACH tz = TAXZONES %] [% 'Revenue' | $T8 %] [% HTML.escape(tz.description) %] - [%- IF SELF.config.id AND linked_parts != 0 %] + [%- IF SELF.config.id AND NOT SELF.config.orphaned %] [% CHARTLIST.${tz.id}.income_accno %] -- [% CHARTLIST.${tz.id}.income_accno_description %] - [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %] + [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %] [%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=SELF.defaults.income_accno_id) %] [%- ELSE %] [%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=CHARTLIST.${tz.id}.income_accno_id) %] @@ -33,9 +33,9 @@ [% 'Expense' | $T8 %] [% HTML.escape(tz.description) %] - [%- IF SELF.config.id AND linked_parts != 0 %] + [%- IF SELF.config.id AND NOT SELF.config.orphaned %] [% CHARTLIST.${tz.id}.expense_accno %] -- [% CHARTLIST.${tz.id}.expense_accno_description %] - [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %] + [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %] [%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=SELF.defaults.expense_accno_id) %] [%- ELSE %] [%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=CHARTLIST.${tz.id}.expense_accno_id) %] @@ -47,7 +47,7 @@

[% L.hidden_tag("action", "Buchungsgruppen/dispatch") %] [% L.submit_tag("action_" _ (SELF.config.id ? "update" : "create"), LxERP.t8('Save'), onclick="return check_prerequisites();") %] - [%- IF SELF.config.id AND linked_parts == 0 %] + [%- IF SELF.config.id AND SELF.config.orphaned %] [% L.submit_tag("action_delete", LxERP.t8('Delete'), confirm=LxERP.t8('Are you sure?')) %] [%- END %]