Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7f883269

Von Sven Schöling vor mehr als 1 Jahr hinzugefügt

  • ID 7f88326964103b033b9749ed2951d446c4c3dbb7
  • Vorgänger f3c44e37
  • Nachfolger e8ec3d9b

RecordLinks: Reclamation after save hook in ein SL::DB::Helper modul verschoben

RecordLinks werden in reclamations in einem after save hook behandelt,
und sind damit deutlich robuster als die manuelle Behandlung. Die
ausgelagerte Variante hat jetzt auch Konstanten für die magischen
Strings in den Objekten.

Unterschiede anzeigen:

SL/DB/Reclamation.pm
18 18
use SL::DB::Helper::PriceTaxCalculator;
19 19
use SL::DB::Helper::PriceUpdater;
20 20
use SL::DB::Helper::TransNumberGenerator;
21
use SL::DB::Helper::RecordLink qw(RECORD_ID RECORD_TYPE_REF);
21 22
use SL::Locale::String qw(t8);
22 23
use SL::RecordLinks;
23 24
use Rose::DB::Object::Helpers qw(as_tree strip);
......
85 86

  
86 87
sub _after_save_link_records {
87 88
  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 89

  
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
  }
90
  my @allowed_record_sources = qw(SL::DB::Reclamation SL::DB::Order SL::DB::DeliveryOrder SL::DB::Invoice SL::DB::PurchaseInvoice);
91
  my @allowed_item_sources = qw(SL::DB::ReclamationItem SL::DB::OrderItem SL::DB::DeliveryOrderItem SL::DB::InvoiceItem);
129 92

  
130
  return 1;
93
  SL::DB::Helper::RecordLink::link_records(
94
    $self,
95
    \@allowed_record_sources,
96
    \@allowed_item_sources,
97
  );
131 98
}
132 99

  
133 100
# methods
......
509 476
  $reclamation->assign_attributes(%{ $params{attributes} }) if $params{attributes};
510 477

  
511 478
  unless ($params{no_linked_records}) {
512
    $reclamation->{"converted_from_record_type_ref"} = ref($source);
513
    $reclamation->{"converted_from_record_id"} = $source->id;
479
    $reclamation->{RECORD_TYPE_REF()} = ref($source);
480
    $reclamation->{RECORD_ID()} = $source->id;
514 481
  };
515 482

  
516 483
  my $items = delete($params{items}) || $source->items;

Auch abrufbar als: Unified diff