Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 8bfef5b2

Von Tamino Steinert vor etwa 2 Jahren hinzugefügt

  • ID 8bfef5b22c4393419a4c75995cf57d99872e0442
  • Vorgänger 961d4fea
  • Nachfolger 0ecd797d

Reclamation: set record_links automatic after reclamation->save

Unterschiede anzeigen:

SL/Controller/Reclamation.pm
83 83
                          save_and_credit_note
84 84
                        )]);
85 85

  
86
__PACKAGE__->run_before('get_record_links_data_from_form',
87
                        only => [qw(
88
                          save save_as_new print preview_pdf send_email
89
                          save_and_show_email_dialog
90
                          workflow_save_and_sales_or_purchase_reclamation
91
                          save_and_order
92
                          save_and_delivery_order
93
                          save_and_credit_note
94
                        )]);
95

  
86 96
#
87 97
# actions
88 98
#
......
1643 1653
  }
1644 1654
}
1645 1655

  
1656
# get data for record_links from form and store it in the object
1657
sub get_record_links_data_from_form {
1658
  my ($self) = @_;
1659

  
1660
  my $reclamation = $self->reclamation;
1661

  
1662
  $reclamation->{converted_from_record_id} = delete $::form->{converted_from_record_id};
1663
  $reclamation->{converted_from_record_type_ref} = delete $::form->{converted_from_record_type_ref};
1664

  
1665
  my $from_record_item_ids = delete $::form->{converted_from_record_item_ids} ;
1666
  my $from_record_item_type_refs = delete $::form->{converted_from_record_item_type_refs} ;
1667

  
1668
  if (scalar @{ $from_record_item_ids || [] }) {
1669
    for my $idx (0 .. $#{ $reclamation->items_sorted }) {
1670
      my $reclamation_item = $reclamation->items_sorted->[$idx];
1671
      $reclamation_item->{converted_from_record_item_id} = $from_record_item_ids->[$idx];
1672
      $reclamation_item->{converted_from_record_item_type_ref} = $from_record_item_type_refs->[$idx];
1673
    }
1674
  }
1675
}
1676

  
1646 1677
# delete the reclamation
1647 1678
#
1648 1679
# And remove related files in the spool directory
......
1689 1720
    SL::DB::ReclamationItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []};
1690 1721
    $self->reclamation->save(cascade => 1);
1691 1722

  
1692
    $self->_link_to_records();
1693

  
1694 1723
    $self->save_history('SAVED');
1695 1724

  
1696 1725
    1;
......
1699 1728
  return $errors;
1700 1729
}
1701 1730

  
1702
sub _link_to_records {
1703
  my ($self) = @_;
1704
  my %allowed_linked_records = map {$_ => 1} qw(
1705
    SL::DB::Reclamation
1706
    SL::DB::Order
1707
    SL::DB::DeliveryOrder
1708
    SL::DB::Invoice
1709
    SL::DB::PurchaseInvoice
1710
  );
1711
  my %allowed_linked_record_items = map {$_ => 1} qw(
1712
    SL::DB::ReclamationItem
1713
    SL::DB::OrderItem
1714
    SL::DB::DeliveryOrderItem
1715
    SL::DB::InvoiceItem
1716
  );
1717

  
1718
  my $from_record_id = delete $::form->{converted_from_record_id};
1719
  $from_record_id ||= $self->reclamation->{converted_from_record_id};
1720
  if ($from_record_id) {
1721
    my $from_record_type = delete $::form->{converted_from_record_type_ref};
1722
    $from_record_type ||= $self->reclamation->{converted_from_record_type_ref};
1723
    unless ($allowed_linked_records{$from_record_type}) {
1724
      croak("Not allowed converted_from_record_type_ref: '" . $from_record_type);
1725
    }
1726
    my $src = ${from_record_type}->new(id => $from_record_id)->load;
1727
    $src->link_to_record($self->reclamation);
1728
    #clear converted_from;
1729
    delete $self->reclamation->{$_} for qw(converted_from_record_id converted_from_record_type_ref);
1730

  
1731
    if (scalar @{ $::form->{converted_from_record_item_ids} || [] }) {
1732
      my $idx = -1;
1733
      my $from_record_item_ids = delete $::form->{converted_from_record_item_ids} ;
1734
      my $from_record_item_type_refs = delete $::form->{converted_from_record_item_type_refs} ;
1735
      for my $idx (0 .. $#{ $self->reclamation->items_sorted }) {
1736
        my $from_item_id = $from_record_item_ids->[$idx];
1737
        my $reclamation_item = $self->reclamation->items_sorted->[$idx];
1738
        $from_item_id ||= $reclamation_item->{converted_from_record_item_id};
1739
        next if !$from_item_id;
1740
        my $from_item_type = $from_record_item_type_refs->[$idx];
1741
        $from_item_type ||= $reclamation_item->{converted_from_record_item_type_ref};
1742
        unless ($allowed_linked_record_items{$from_item_type}) {
1743
          croak("Not allowed converted_from_record_item_type_ref: '" . $from_item_type);
1744
        }
1745
        my $src_item = ${from_item_type}->new(id => $from_item_id)->load;
1746
        $src_item->link_to_record($reclamation_item);
1747
        #clear converted_from;
1748
        delete $reclamation_item->{$_} for qw(converted_from_record_item_id converted_from_record_item_type_ref);
1749
      }
1750
    }
1751
  }
1752
}
1753

  
1754 1731
sub save_with_render_error {
1755 1732
  my ($self) = @_;
1756 1733

  
SL/DB/Reclamation.pm
55 55
__PACKAGE__->before_save('_before_save_set_record_number');
56 56
__PACKAGE__->before_save('_before_save_remove_empty_custom_shipto');
57 57
__PACKAGE__->before_save('_before_save_set_custom_shipto_module');
58
__PACKAGE__->after_save('_after_save_link_records');
58 59

  
59 60
# hooks
60 61

  
......
82 83
  return 1;
83 84
}
84 85

  
86
sub _after_save_link_records {
87
  my ($self) = @_;
88
  my %allowed_linked_records = map {$_ => 1} qw(
89
    SL::DB::Reclamation
90
    SL::DB::Order
91
    SL::DB::DeliveryOrder
92
    SL::DB::Invoice
93
    SL::DB::PurchaseInvoice
94
  );
95
  my %allowed_linked_record_items = map {$_ => 1} qw(
96
    SL::DB::ReclamationItem
97
    SL::DB::OrderItem
98
    SL::DB::DeliveryOrderItem
99
    SL::DB::InvoiceItem
100
  );
101

  
102
  my $from_record_id = $self->{converted_from_record_id};
103
  if ($from_record_id) {
104
    my $from_record_type = $self->{converted_from_record_type_ref};
105
    unless ($allowed_linked_records{$from_record_type}) {
106
      croak("Not allowed converted_from_record_type_ref: '" . $from_record_type);
107
    }
108
    my $src = ${from_record_type}->new(id => $from_record_id)->load;
109
    $src->link_to_record($self);
110
    #clear converted_from;
111
    delete $self->{$_} for qw(converted_from_record_id converted_from_record_type_ref);
112

  
113
    if (scalar @{ $self->items_sorted || [] }) {
114
      for my $idx (0 .. $#{ $self->items_sorted }) {
115
        my $reclamation_item = $self->items_sorted->[$idx];
116
        my $from_item_id = $reclamation_item->{converted_from_record_item_id};
117
        next if !$from_item_id;
118
        my $from_item_type = $reclamation_item->{converted_from_record_item_type_ref};
119
        unless ($allowed_linked_record_items{$from_item_type}) {
120
          croak("Not allowed converted_from_record_item_type_ref: '" . $from_item_type);
121
        }
122
        my $src_item = ${from_item_type}->new(id => $from_item_id)->load;
123
        $src_item->link_to_record($reclamation_item);
124
        #clear converted_from;
125
        delete $reclamation_item->{$_} for qw(converted_from_record_item_id converted_from_record_item_type_ref);
126
      }
127
    }
128
  }
129

  
130
  return 1;
131
}
132

  
85 133
# methods
86 134

  
87 135
sub items { goto &reclamation_items; }

Auch abrufbar als: Unified diff