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));
}
$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 }) {
</tr>
<tr>
<th align="right">[% 'Inventory account' | $T8 %]</th>
- [%- IF SELF.config.id AND linked_parts != 0 %]
+ [%- IF SELF.config.id AND NOT SELF.config.orphaned %]
<td>[%- CHARTLIST.inventory_accno %] -- [%- CHARTLIST.inventory_accno_description %]</td>
- [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %]
+ [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %]
<td>[%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.defaults.inventory_accno_id) %]</td>
[%- ELSE %]
<td>[%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.config.inventory_accno_id) %]</td>
[%- FOREACH tz = TAXZONES %]
<tr>
<th align="right">[% 'Revenue' | $T8 %] [% HTML.escape(tz.description) %]</th>
- [%- IF SELF.config.id AND linked_parts != 0 %]
+ [%- IF SELF.config.id AND NOT SELF.config.orphaned %]
<td>[% CHARTLIST.${tz.id}.income_accno %] -- [% CHARTLIST.${tz.id}.income_accno_description %]</td>
- [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %]
+ [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %]
<td>[%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=SELF.defaults.income_accno_id) %]</td>
[%- ELSE %]
<td>[%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=CHARTLIST.${tz.id}.income_accno_id) %]</td>
</tr>
<tr>
<th align="right">[% 'Expense' | $T8 %] [% HTML.escape(tz.description) %]</th>
- [%- IF SELF.config.id AND linked_parts != 0 %]
+ [%- IF SELF.config.id AND NOT SELF.config.orphaned %]
<td>[% CHARTLIST.${tz.id}.expense_accno %] -- [% CHARTLIST.${tz.id}.expense_accno_description %]</td>
- [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %]
+ [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %]
<td>[%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=SELF.defaults.expense_accno_id) %]</td>
[%- ELSE %]
<td>[%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=CHARTLIST.${tz.id}.expense_accno_id) %]</td>
<p>
[% 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 %]
</p>