From: Sven Schöling Date: Mon, 8 Nov 2021 03:19:26 +0000 (+0100) Subject: Inventory: before hooks für trans_id, shippingdate und employee X-Git-Tag: kivitendo-mebil_0.1-0~10^2~2^2~216^2~64 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=14672a1d69298562d8aac987ff2c4eaab3492088;p=kivitendo-erp.git Inventory: before hooks für trans_id, shippingdate und employee --- diff --git a/SL/DB/Inventory.pm b/SL/DB/Inventory.pm index a463db5c6..a2b571ce6 100644 --- a/SL/DB/Inventory.pm +++ b/SL/DB/Inventory.pm @@ -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;