use Rose::Object::MakeMethods::Generic
(
scalar => [ qw(parts) ],
- 'scalar --get_set_init' => [ qw(requirement_spec rs_order js h_unit_name all_customers all_parts) ],
+ 'scalar --get_set_init' => [ qw(requirement_spec rs_order js h_unit_name all_customers all_parts_time_unit) ],
);
__PACKAGE__->run_before('setup');
sub action_new {
my ($self) = @_;
+ if (!@{ $self->all_parts_time_unit }) {
+ return $self->js->flash('error', t8('This function requires the presence of articles with a time-based unit such as "h" or "min".'))->render($self);
+ }
+
my $html = $self->render('requirement_spec_order/new', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description });
$self->js->html('#' . TAB_ID(), $html)
->render($self);
sub action_edit_assignment {
my ($self) = @_;
+ if (!@{ $self->all_parts_time_unit }) {
+ return $self->js->flash('error', t8('This function requires the presence of articles with a time-based unit such as "h" or "min".'))->render($self);
+ }
+
my $html = $self->render('requirement_spec_order/edit_assignment', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description });
$self->js->html('#' . TAB_ID(), $html)
->render($self);
}
sub init_all_customers { SL::DB::Manager::Customer->get_all_sorted }
-sub init_all_parts { SL::DB::Manager::Part->get_all_sorted }
sub init_h_unit_name { first { SL::DB::Manager::Unit->find_by(name => $_) } qw(Std h Stunde) };
sub init_rs_order { SL::DB::RequirementSpecOrder->new(id => $::form->{rs_order_id})->load };
+sub init_all_parts_time_unit {
+ my ($self) = @_;
+
+ return [] unless $self->h_unit_name;
+
+ my @convertible_unit_names = map { $_->name } @{ SL::DB::Manager::Unit->find_by(name => $self->h_unit_name)->convertible_units };
+
+ return SL::DB::Manager::Part->get_all_sorted(where => [ unit => \@convertible_unit_names ]);
+}
+
#
# helpers
#