Pflichtenhefte -> Angebote: Eintrag in record_links anlegen
authorMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 9 Jan 2014 11:03:24 +0000 (12:03 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Tue, 1 Apr 2014 11:12:24 +0000 (13:12 +0200)
SL/Controller/RequirementSpecOrder.pm
SL/DB/RequirementSpec.pm

index 0e97852..07d3e06 100644 (file)
@@ -63,13 +63,20 @@ sub action_create {
 
   # 2. Create actual quotation/order.
   my $order = $self->create_order(sections => $sections);
-  $order->save;
+  $order->db->with_transaction(sub {
+    $order->save;
+
+    $self->requirement_spec->orders(
+      @{ $self->requirement_spec->orders },
+      SL::DB::RequirementSpecOrder->new(order => $order, version => $self->requirement_spec->version)
+    );
+    $self->requirement_spec->save;
+
+    $self->requirement_spec->link_to_record($order);
+  }) or do {
+    $::lxdebug->message(LXDebug::WARN(), "Error creating the order object: $@");
+  };
 
-  $self->requirement_spec->orders(
-    @{ $self->requirement_spec->orders },
-    SL::DB::RequirementSpecOrder->new(order => $order, version => $self->requirement_spec->version)
-  );
-  $self->requirement_spec->save;
   $self->init_requirement_spec;
 
   # 3. Notify the user and return to list.
@@ -135,7 +142,13 @@ sub action_do_update {
   $order->orderitems([ @{ $order->orderitems }, @new_orderitems ]) if @new_orderitems;
 
   $order->calculate_prices_and_taxes;
-  $order->save;
+
+  $order->db->with_transaction(sub {
+    $order->save;
+    $self->requirement_spec->link_to_record($order);
+  }) or do {
+    $::lxdebug->message(LXDebug::WARN(), "Error updating the order object: $@");
+  };
 
   $self->init_requirement_spec;
 
index 9ec553c..e1298ec 100644 (file)
@@ -8,6 +8,7 @@ use Rose::DB::Object::Helpers;
 
 use SL::DB::MetaSetup::RequirementSpec;
 use SL::DB::Manager::RequirementSpec;
+use SL::DB::Helper::LinkedRecords;
 use SL::Locale::String;
 use SL::Util qw(_hashify);