Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f0ddfbfe

Von Moritz Bunkus vor etwa 3 Jahren hinzugefügt

  • ID f0ddfbfe848f0d94a7a28b8b5593786217c5dd39
  • Vorgänger c488d6f1
  • Nachfolger bebdc2ce

Pflichtenhefte: bei Pflichtenheft → Angebot → Auftrag auch PH mit Auftrag verknüpfen

Unterschiede anzeigen:

SL/Controller/Order.pm
23 23
use SL::DB::Printer;
24 24
use SL::DB::Language;
25 25
use SL::DB::RecordLink;
26
use SL::DB::RequirementSpec;
26 27
use SL::DB::Shipto;
27 28
use SL::DB::Translation;
28 29

  
......
1678 1679
    # link records
1679 1680
    if ($::form->{converted_from_oe_id}) {
1680 1681
      my @converted_from_oe_ids = split ' ', $::form->{converted_from_oe_id};
1682

  
1681 1683
      foreach my $converted_from_oe_id (@converted_from_oe_ids) {
1682 1684
        my $src = SL::DB::Order->new(id => $converted_from_oe_id)->load;
1683 1685
        $src->update_attributes(closed => 1) if $src->type =~ /_quotation$/;
......
1696 1698
          $idx++;
1697 1699
        }
1698 1700
      }
1701

  
1702
      $self->link_requirement_specs_linking_to_created_from_objects(@converted_from_oe_ids);
1699 1703
    }
1700 1704

  
1701 1705
    $self->save_history('SAVED');
......
2309 2313
  return @errors;
2310 2314
}
2311 2315

  
2316
sub link_requirement_specs_linking_to_created_from_objects {
2317
  my ($self, @converted_from_oe_ids) = @_;
2318

  
2319
  return unless @converted_from_oe_ids;
2320

  
2321
  my $rs_orders = SL::DB::Manager::RequirementSpecOrder->get_all(where => [ order_id => \@converted_from_oe_ids ]);
2322
  foreach my $rs_order (@{ $rs_orders }) {
2323
    SL::DB::RequirementSpecOrder->new(
2324
      order_id            => $self->order->id,
2325
      requirement_spec_id => $rs_order->requirement_spec_id,
2326
      version_id          => $rs_order->version_id,
2327
    )->save;
2328
  }
2329
}
2330

  
2312 2331
1;
2313 2332

  
2314 2333
__END__
SL/OE.pm
44 44
use SL::DB::PeriodicInvoicesConfig;
45 45
use SL::DB::Project;
46 46
use SL::DB::ProjectType;
47
use SL::DB::RequirementSpecOrder;
47 48
use SL::DB::Status;
48 49
use SL::DB::Tax;
49 50
use SL::DBUtils;
......
479 480
  my $number_field         = $form->{type} =~ m{order} ? 'ordnumber' : 'quonumber';
480 481
  my $trans_number         = SL::TransNumber->new(type => $form->{type}, dbh => $dbh, number => $form->{$number_field}, id => $form->{id});
481 482
  $form->{$number_field} ||= $trans_number->create_unique; # set $form->{ordnumber} or $form->{quonumber}
483
  my $is_new               = !$form->{id};
482 484

  
483 485
  if ($form->{id}) {
484 486
    $query = qq|DELETE FROM custom_variables
......
832 834
                                       config_yaml => $form->{periodic_invoices_config})
833 835
    if ($form->{type} eq 'sales_order');
834 836

  
837
  $self->_link_created_sales_order_to_requirement_specs_for_sales_quotations(
838
    type               => $form->{type},
839
    converted_from_ids => \@convert_from_oe_ids,
840
    sales_order_id     => $form->{id},
841
    is_new             => $is_new,
842
  );
843

  
835 844
  $main::lxdebug->leave_sub();
836 845

  
837 846
  return 1;
838 847
}
839 848

  
849
sub _link_created_sales_order_to_requirement_specs_for_sales_quotations {
850
  my ($self, %params) = @_;
851

  
852
  # If this is a sales order created from a sales quotation and if
853
  # that sales quotation was created from a requirement spec document
854
  # then link the newly created sales order to the requirement spec
855
  # document, too.
856

  
857
  return if !$params{is_new};
858
  return if  $params{type} ne 'sales_order';
859
  return if !@{ $params{converted_from_ids} };
860

  
861
  my $oe_objects       = SL::DB::Manager::Order->get_all(where => [ id => $params{converted_from_ids} ]);
862
  my @sales_quotations = grep { $_->is_type('sales_quotation') } @{ $oe_objects };
863

  
864
  return if !@sales_quotations;
865

  
866
  my $rs_orders = SL::DB::Manager::RequirementSpecOrder->get_all(where => [ order_id => [ map { $_->id } @sales_quotations ] ]);
867

  
868
  return if !@{ $rs_orders };
869

  
870
  $rs_orders->[0]->db->with_transaction(sub {
871
    foreach my $rs_order (@{ $rs_orders }) {
872
      SL::DB::RequirementSpecOrder->new(
873
        order_id            => $params{sales_order_id},
874
        requirement_spec_id => $rs_order->requirement_spec_id,
875
        version_id          => $rs_order->version_id,
876
      )->save;
877
    }
878

  
879
    1;
880
  });
881
}
882

  
840 883
sub save_periodic_invoices_config {
841 884
  my ($self, %params) = @_;
842 885

  
doc/changelog
29 29
  vom Auftrag her aufgebaut werden
30 30
- SEPA-Überweisungen & -Bankeinzüge nutzen jetzt aktuelle Standard-Versionen, die
31 31
  momentan von der Kreditindustrie unterstützt werden.
32
- Pflichtenhefte: wenn man im Workflow vom Pflichtenheft ein neues
33
  Angebot anlegt und später von diesem Angebot aus einen Auftrag, so
34
  wird auch der Auftrag direkt mit dem Pflichtenheft verknüpft.
32 35

  
33 36
Bugfixes (Tracker: https://www.kivitendo.de/redmine):
34 37

  
sql/Pg-upgrade2/link_requirement_spec_to_orders_created_from_quotations_created_from_requirement_spec.sql
1
-- @tag: link_requirement_spec_to_orders_created_from_quotations_created_from_requirement_spec
2
-- @description: Pflichtenhefte mit Aufträgen verknüpfen, die aus Angeboten erstellt wurden, die wiederum aus einem Pflichtenheft erstellt wurden
3
-- @depends: release_3_2_0
4
CREATE TEMPORARY TABLE temp_link_requirement_spec_to_orders AS
5
SELECT rs_orders.requirement_spec_id, orders.id AS order_id, rs_orders.version_id
6
FROM record_links rl,
7
  requirement_spec_orders rs_orders,
8
  oe quotations,
9
  oe orders
10
WHERE (rl.from_table      = 'oe')
11
  AND (rl.from_id         = quotations.id)
12
  AND (rl.to_table        = 'oe')
13
  AND (rl.to_id           = orders.id)
14
  AND (rs_orders.order_id = quotations.id)
15
  AND     COALESCE(quotations.quotation, FALSE)
16
  AND NOT COALESCE(orders.quotation,     FALSE)
17
  AND (quotations.customer_id IS NOT NULL)
18
  AND (orders.customer_id     IS NOT NULL);
19

  
20
INSERT INTO requirement_spec_orders (requirement_spec_id, order_id, version_id)
21
SELECT requirement_spec_id, order_id, version_id
22
FROM temp_link_requirement_spec_to_orders new_orders
23
WHERE NOT EXISTS (
24
  SELECT existing_orders.id
25
  FROM requirement_spec_orders existing_orders
26
  WHERE (existing_orders.requirement_spec_id = new_orders.requirement_spec_id)
27
    AND (existing_orders.order_id            = new_orders.order_id)
28
  LIMIT 1
29
);

Auch abrufbar als: Unified diff