1 package SL::Controller::PartsGroup;
5 use parent qw(SL::Controller::Base);
8 use SL::Locale::String;
10 use SL::DB::Manager::PartsGroup;
12 use Rose::Object::MakeMethods::Generic (
13 scalar => [ qw(partsgroup) ],
14 'scalar --get_set_init' => [ qw(all_partsgroups) ],
17 __PACKAGE__->run_before('check_auth');
18 __PACKAGE__->run_before('load_partsgroup', only => [ qw(edit update delete) ]);
27 $self->render('partsgroup/list',
28 title => t8('Partsgroups'),
35 $self->partsgroup( SL::DB::PartsGroup->new );
36 $self->render('partsgroup/form',
37 title => t8('Add partsgroup'),
44 $self->render('partsgroup/form',
45 title => t8('Edit partsgroup'),
52 $self->partsgroup( SL::DB::PartsGroup->new );
53 $self->create_or_update;
58 $self->create_or_update;
64 if ( !$self->partsgroup->orphaned ) {
65 flash_later('error', $::locale->text('The partsgroup has been used and cannot be deleted.'));
66 } elsif ( eval { $self->partsgroup->delete; 1; } ) {
67 flash_later('info', $::locale->text('The partsgroup has been deleted.'));
69 flash_later('error', $::locale->text('The partsgroup has been used and cannot be deleted.'));
71 $self->redirect_to(action => 'list');
77 SL::DB::PartsGroup->reorder_list(@{ $::form->{partsgroup_id} || [] });
78 $self->render(\'', { type => 'json' });
86 $::auth->assert('config');
92 $self->partsgroup( SL::DB::PartsGroup->new(id => $::form->{id})->load );
95 sub init_all_partsgroups { SL::DB::Manager::PartsGroup->get_all_sorted }
101 sub create_or_update {
103 my $is_new = !$self->partsgroup->id;
105 my $params = delete($::form->{partsgroup}) || { };
107 $self->partsgroup->assign_attributes(%{ $params });
109 my @errors = $self->partsgroup->validate;
112 flash('error', @errors);
113 $self->render('partsgroup/form',
114 title => $is_new ? t8('Add partsgroup') : t8('Edit partsgroup'),
119 $self->partsgroup->save;
121 flash_later('info', $is_new ? t8('The partsgroup has been created.') : t8('The partsgroup has been saved.'));
122 $self->redirect_to(action => 'list');
133 SL::Controller::PartsGroup - CRUD controller for partsgroups
137 A new controller to create / edit / delete partsgroups.
139 Partsgroups can only be deleted if they haven't been used anywhere.
141 =head1 OBSOLETE PARTSGROUPS
143 A partsgroup can be deleted if it hasn't been used anywhere / is orphaned.
145 A partsgroup can be set to obsolete, which means new items can't be assigned
146 that partsgroup, but old items with that partsgroup can keep it. And you can
147 also still filter for these obsolete partsgroups in reports.
151 Unlike the old version (pe.pl/PE.pm), there is no way to filter/search the
152 partsgroups in the overview page, it always shows the complete (ordered) list,
157 G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>