From: Moritz Bunkus Date: Thu, 11 Jul 2013 07:20:35 +0000 (+0200) Subject: SL::DB::Order: quo/ordnumber in before_save-Hook erzeugen X-Git-Tag: release-3.1.0beta1~198 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1bcb4ec647504c6ac2c310df902c6faae64621a0;p=kivitendo-erp.git SL::DB::Order: quo/ordnumber in before_save-Hook erzeugen --- diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index cf7b07610..194431dcd 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -34,6 +34,23 @@ __PACKAGE__->meta->add_relationship( __PACKAGE__->meta->initialize; +__PACKAGE__->before_save('_before_save_set_ord_quo_number'); + +# hooks + +sub _before_save_set_ord_quo_number { + my ($self) = @_; + + # ordnumber is 'NOT NULL'. Therefore make sure it's always set to at + # least an empty string, even if we're saving a quotation. + $self->ordnumber('') if !$self->ordnumber; + + my $field = $self->quotation ? 'quonumber' : 'ordnumber'; + $self->create_trans_number if !$self->$field; + + return 1; +} + # methods sub items { goto &orderitems; }