+sub _link_created_sales_order_to_requirement_specs_for_sales_quotations {
+ my ($self, %params) = @_;
+
+ # If this is a sales order created from a sales quotation and if
+ # that sales quotation was created from a requirement spec document
+ # then link the newly created sales order to the requirement spec
+ # document, too.
+
+ return if !$params{is_new};
+ return if $params{type} ne 'sales_order';
+ return if !@{ $params{converted_from_ids} };
+
+ my $oe_objects = SL::DB::Manager::Order->get_all(where => [ id => $params{converted_from_ids} ]);
+ my @sales_quotations = grep { $_->is_type('sales_quotation') } @{ $oe_objects };
+
+ return if !@sales_quotations;
+
+ my $rs_orders = SL::DB::Manager::RequirementSpecOrder->get_all(where => [ order_id => [ map { $_->id } @sales_quotations ] ]);
+
+ return if !@{ $rs_orders };
+
+ $rs_orders->[0]->db->with_transaction(sub {
+ foreach my $rs_order (@{ $rs_orders }) {
+ SL::DB::RequirementSpecOrder->new(
+ order_id => $params{sales_order_id},
+ requirement_spec_id => $rs_order->requirement_spec_id,
+ version_id => $rs_order->version_id,
+ )->save;
+ }
+
+ 1;
+ });
+}
+
+sub _set_project_in_linked_requirement_spec {
+ my ($self, %params) = @_;
+
+ return if $params{type} ne 'sales_order';
+ return if !$params{project_id} || !$params{sales_order_id};
+
+ my $query = <<SQL;
+ UPDATE requirement_specs
+ SET project_id = ?
+ WHERE id IN (
+ SELECT so.requirement_spec_id
+ FROM requirement_spec_orders so
+ WHERE so.order_id = ?
+ )
+SQL
+
+ do_query($::form, $::form->get_standard_dbh, $query, $params{project_id}, $params{sales_order_id});
+}
+