Inventory: before hooks für trans_id, shippingdate und employee
authorSven Schöling <s.schoeling@googlemail.com>
Mon, 8 Nov 2021 03:19:26 +0000 (04:19 +0100)
committerJan Büren <jan@kivitendo.de>
Mon, 14 Feb 2022 14:02:19 +0000 (15:02 +0100)
SL/DB/Inventory.pm

index a463db5..a2b571c 100644 (file)
@@ -10,9 +10,44 @@ use SL::DB::Manager::Inventory;
 
 __PACKAGE__->meta->initialize;
 
+__PACKAGE__->before_save(\&_before_save_create_trans_id);
+__PACKAGE__->before_save(\&_before_save_set_shippingdate);
+__PACKAGE__->before_save(\&_before_save_set_employee);
+
 # part accessor is badly named
 sub part {
   goto &parts;
 }
 
+sub _before_save_create_trans_id {
+  my ($self, %params) = @_;
+
+  return 1 if $self->trans_id;
+
+  my ($trans_id) = selectrow_query($::form, SL::DB->client->dbh, qq|SELECT nextval('id')|);
+
+  $self->trans_id($trans_id);
+
+  return 1;
+}
+
+sub _before_save_set_shippingdate {
+  my ($self, %params) = @_;
+
+  return 1 if $self->shippingdate;
+
+  $self->shippingdate(DateTime->now);
+
+  return 1;
+}
+
+sub _before_save_set_employee {
+  my ($self, %params) = @_;
+
+  return 1 if $self->emplyee_id;
+
+  $self->employee(SL::DB::Manager::Employee->current);
+
+  return 1;
+}
 1;