From 1bcb4ec647504c6ac2c310df902c6faae64621a0 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 11 Jul 2013 09:20:35 +0200 Subject: [PATCH] SL::DB::Order: quo/ordnumber in before_save-Hook erzeugen --- SL/DB/Order.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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; } -- 2.20.1