From 14672a1d69298562d8aac987ff2c4eaab3492088 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Mon, 8 Nov 2021 04:19:26 +0100 Subject: [PATCH] =?utf8?q?Inventory:=20before=20hooks=20f=C3=BCr=20trans?= =?utf8?q?=5Fid,=20shippingdate=20und=20employee?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/Inventory.pm | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) 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; -- 2.20.1