SL::DB::Order: quo/ordnumber in before_save-Hook erzeugen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 11 Jul 2013 07:20:35 +0000 (09:20 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 11 Jul 2013 07:29:59 +0000 (09:29 +0200)
SL/DB/Order.pm

index cf7b076..194431d 100644 (file)
@@ -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; }