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);
->render($self);
}
+sub action_delete {
+ my ($self) = @_;
+
+ my $order = $self->rs_order->order;
+
+ $order->delete;
+ $self->init_requirement_spec;
+
+ my $html = $self->render('requirement_spec_order/list', { output => 0 });
+ $self->js->html('#' . TAB_ID(), $html)
+ ->flash('info', $order->quotation ? t8('Sales quotation #1 has been deleted.', $order->quonumber) : t8('Sales order #1 has been deleted.', $order->ordnumber))
+ ->render($self);
+}
+
sub action_cancel {
my ($self) = @_;
my ($self) = @_;
$::auth->assert('sales_quotation_edit');
- $::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec);
+ $::request->{layout}->use_stylesheet("${_}.css") for qw(jquery.contextMenu requirement_spec autocomplete_part);
$::request->{layout}->use_javascript("${_}.js") for qw(jquery.jstree jquery/jquery.contextMenu client_js requirement_spec);
return 1;
}
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
#
if (!$section->{keep_description}) {
$description = '<%fb_number%> <%title%>' unless $description =~ m{<%};
- $description =~ s{<% (.+?) %>}{$section->$1}egx;
+ $description =~ s{<% (.+?) %>}{ $section->can($1) ? $section->$1 : '<' . t8('Invalid variable #1', $1) . '>' }egx;
}
$item->assign_attributes(