From 1b18f0aa0914699d5ef4372243ebb8872d1bdc20 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 24 Aug 2020 11:15:27 +0200 Subject: [PATCH] =?utf8?q?Mandanteneinstellung:=20Projekt=20zum=20Auftrag?= =?utf8?q?=20erzeugen=20auch=20f=C3=BCr=20Order-Controller?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/Order.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index 8d7088f49..657252f8a 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -57,6 +57,7 @@ __PACKAGE__->attr_html('notes'); __PACKAGE__->attr_sorted('items'); __PACKAGE__->before_save('_before_save_set_ord_quo_number'); +__PACKAGE__->before_save('_before_save_create_new_project'); # hooks @@ -72,6 +73,30 @@ sub _before_save_set_ord_quo_number { return 1; } +sub _before_save_create_new_project { + my ($self) = @_; + + # force new project, if not set yet + if ($::instance_conf->get_order_always_project && !$self->globalproject_id && ($self->type eq 'sales_order')) { + + die t8("Error while creating project with project number of new order number, project number #1 already exists!", $self->ordnumber) + if SL::DB::Manager::Project->find_by(projectnumber => $self->ordnumber); + + eval { + my $new_project = SL::DB::Project->new( + projectnumber => $self->ordnumber, + description => $self->customer->name, + customer_id => $self->customer->id, + active => 1, + project_type_id => $::instance_conf->get_project_type_id, + project_status_id => $::instance_conf->get_project_status_id, + ); + $new_project->save; + $self->globalproject_id($new_project->id); + } or die t8('Could not create new project #1', $@); + } + return 1; +} # methods -- 2.20.1