Revision 0eb8e223
Von Moritz Bunkus vor mehr als 10 Jahren hinzugefügt
SL/DB/RequirementSpecItem.pm | ||
---|---|---|
6 | 6 |
use SL::DB::Manager::RequirementSpecItem; |
7 | 7 |
use SL::DB::Helper::ActsAsList; |
8 | 8 |
use SL::DB::Helper::AttrDuration; |
9 |
use SL::DB::Default; |
|
10 |
use SL::Locale::String; |
|
11 |
use SL::PrefixedNumber; |
|
9 | 12 |
|
10 | 13 |
__PACKAGE__->meta->add_relationship( |
11 | 14 |
children => { |
... | ... | |
32 | 35 |
__PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_id)]); |
33 | 36 |
__PACKAGE__->attr_duration(qw(time_estimation)); |
34 | 37 |
|
38 |
__PACKAGE__->before_save(\&_before_save_create_fb_number); |
|
35 | 39 |
__PACKAGE__->before_delete(\&_before_delete_delete_children); |
36 | 40 |
|
37 | 41 |
sub _before_delete_delete_children { |
... | ... | |
45 | 49 |
1; |
46 | 50 |
} |
47 | 51 |
|
52 |
sub _before_save_create_fb_number { |
|
53 |
my ($self) = @_; |
|
54 |
|
|
55 |
return 1 if $self->fb_number; |
|
56 |
return 0 if !$self->requirement_spec_id; |
|
57 |
|
|
58 |
my $method = 'previous_' . ($self->parent_id ? 'fb' : 'section') . '_number'; |
|
59 |
my $next_number = $self->requirement_spec->$method + 1; |
|
60 |
|
|
61 |
$self->requirement_spec->update_attributes($method => $next_number) || return 0; |
|
62 |
|
|
63 |
my $method = 'requirement_spec_' . ($self->parent_id ? 'function_block' : 'section') . '_number_format'; |
|
64 |
my $format = SL::DB::Default->get->$method; |
|
65 |
|
|
66 |
$self->fb_number(SL::PrefixedNumber->new(number => $format || 0)->set_to($next_number)); |
|
67 |
|
|
68 |
return 1; |
|
69 |
} |
|
70 |
|
|
48 | 71 |
sub validate { |
49 | 72 |
my ($self) = @_; |
50 | 73 |
|
Auch abrufbar als: Unified diff
Pflichtenheftitems (DB): fb_number setzen, falls beim Speichern leer