From: Jan Büren Date: Mon, 24 Aug 2020 09:15:27 +0000 (+0200) Subject: Mandanteneinstellung: Projekt zum Auftrag erzeugen auch für Order-Controller X-Git-Tag: release-3.5.6.1~67 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=1b18f0aa0914699d5ef4372243ebb8872d1bdc20;p=kivitendo-erp.git Mandanteneinstellung: Projekt zum Auftrag erzeugen auch für Order-Controller --- 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