Revision cd42ade3
Von Tamino Steinert vor mehr als 2 Jahren hinzugefügt
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 |
|
Auch abrufbar als: Unified diff
Reclamation: set record_links automatic after reclamation->save