From: Moritz Bunkus Date: Tue, 12 Mar 2013 11:53:55 +0000 (+0100) Subject: Pflichtenheftitems (DB): fb_number setzen, falls beim Speichern leer X-Git-Tag: release-3.2.0beta~467^2~221 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=0eb8e2233994c12c3fc2f560bb1fac1428e9156e;p=kivitendo-erp.git Pflichtenheftitems (DB): fb_number setzen, falls beim Speichern leer --- diff --git a/SL/DB/RequirementSpecItem.pm b/SL/DB/RequirementSpecItem.pm index 8f7874da4..dc7f5c1e6 100644 --- a/SL/DB/RequirementSpecItem.pm +++ b/SL/DB/RequirementSpecItem.pm @@ -6,6 +6,9 @@ use SL::DB::MetaSetup::RequirementSpecItem; use SL::DB::Manager::RequirementSpecItem; use SL::DB::Helper::ActsAsList; use SL::DB::Helper::AttrDuration; +use SL::DB::Default; +use SL::Locale::String; +use SL::PrefixedNumber; __PACKAGE__->meta->add_relationship( children => { @@ -32,6 +35,7 @@ __PACKAGE__->meta->initialize; __PACKAGE__->configure_acts_as_list(group_by => [qw(requirement_spec_id parent_id)]); __PACKAGE__->attr_duration(qw(time_estimation)); +__PACKAGE__->before_save(\&_before_save_create_fb_number); __PACKAGE__->before_delete(\&_before_delete_delete_children); sub _before_delete_delete_children { @@ -45,6 +49,25 @@ sub _before_delete_delete_children { 1; } +sub _before_save_create_fb_number { + my ($self) = @_; + + return 1 if $self->fb_number; + return 0 if !$self->requirement_spec_id; + + my $method = 'previous_' . ($self->parent_id ? 'fb' : 'section') . '_number'; + my $next_number = $self->requirement_spec->$method + 1; + + $self->requirement_spec->update_attributes($method => $next_number) || return 0; + + my $method = 'requirement_spec_' . ($self->parent_id ? 'function_block' : 'section') . '_number_format'; + my $format = SL::DB::Default->get->$method; + + $self->fb_number(SL::PrefixedNumber->new(number => $format || 0)->set_to($next_number)); + + return 1; +} + sub validate { my ($self) = @_;