SL::DB::Invoice: invnumber in before_save-Hook erzeugen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 11 Jul 2013 07:25:36 +0000 (09:25 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 11 Jul 2013 07:30:00 +0000 (09:30 +0200)
SL/DB/Invoice.pm

index 526c791..3842af6 100644 (file)
@@ -40,6 +40,18 @@ __PACKAGE__->meta->add_relationship(
 
 __PACKAGE__->meta->initialize;
 
+__PACKAGE__->before_save('_before_save_set_invnumber');
+
+# hooks
+
+sub _before_save_set_invnumber {
+  my ($self) = @_;
+
+  $self->create_trans_number if !$self->invnumber;
+
+  return 1;
+}
+
 # methods
 
 sub items { goto &invoiceitems; }
@@ -156,7 +168,6 @@ sub post {
     my %data = $self->calculate_prices_and_taxes;
 
     $self->_post_create_assemblyitem_entries($data{assembly_items});
-    $self->create_trans_number;
     $self->save;
 
     $self->_post_add_acctrans($data{amounts_cogs});