Revision 98c122d1
Von Tamino Steinert vor etwa 1 Jahr hinzugefügt
SL/Controller/DeliveryOrder.pm | ||
---|---|---|
32 | 32 |
use SL::DB::TransferType; |
33 | 33 |
use SL::DB::ValidityToken; |
34 | 34 |
use SL::DB::Warehouse; |
35 |
use SL::Model::Record; |
|
35 | 36 |
|
36 | 37 |
use SL::Helper::CreatePDF qw(:all); |
37 | 38 |
use SL::Helper::PrintOptions; |
... | ... | |
103 | 104 |
|
104 | 105 |
my $order = SL::DB::Order->new(id => $self->{converted_from_oe_id})->load; |
105 | 106 |
|
106 |
$self->order(SL::DB::DeliveryOrder->new_from($order, type => $::form->{type})); |
|
107 |
my $target_type = $::form->{type}; |
|
108 |
my $delivery_order = SL::Model::Record->new_from_workflow($order, $target_type); |
|
109 |
$self->order($delivery_order); |
|
107 | 110 |
|
108 | 111 |
$self->action_add; |
109 | 112 |
} |
... | ... | |
112 | 115 |
my ($self) = @_; |
113 | 116 |
|
114 | 117 |
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load; |
115 |
my $delivery_order = SL::DB::DeliveryOrder->new_from($reclamation); |
|
118 |
my $target_type = $reclamation->is_sales ? 'rma_delivery_order' |
|
119 |
: 'supplier_delivery_order'; |
|
120 |
my $delivery_order = SL::Model::Record->new_from_workflow($reclamation, $target_type); |
|
116 | 121 |
$self->{converted_from_reclamation_id} = $::form->{from_id}; |
117 | 122 |
$self->order($delivery_order); |
118 | 123 |
|
... | ... | |
1755 | 1760 |
|
1756 | 1761 |
my $destination_type = $self->type_data->workflow("to_quotation_type"); |
1757 | 1762 |
|
1758 |
$self->order(SL::DB::DeliveryOrder->new_from($self->order, destination_type => $destination_type)); |
|
1763 |
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, $destination_type, {}); |
|
1764 |
$self->order($delivery_order); |
|
1759 | 1765 |
$self->{converted_from_oe_id} = delete $::form->{id}; |
1760 | 1766 |
|
1761 | 1767 |
# set item ids to new fake id, to identify them as new items |
... | ... | |
1804 | 1810 |
$custom_shipto = $self->order->shipto->clone('SL::DB::DeliveryOrder'); |
1805 | 1811 |
} |
1806 | 1812 |
|
1807 |
$self->order(SL::DB::DeliveryOrder->new_from($self->order, destination_type => $destination_type)); |
|
1813 |
my $delivery_order = SL::Model::Record->new_from_workflow($self->order, $destination_type, {}); |
|
1814 |
$self->order($delivery_order); |
|
1808 | 1815 |
$self->{converted_from_oe_id} = delete $::form->{id}; |
1809 | 1816 |
|
1810 | 1817 |
# set item ids to new fake id, to identify them as new items |
SL/Controller/Order.pm | ||
---|---|---|
33 | 33 |
use SL::DB::Shipto; |
34 | 34 |
use SL::DB::Translation; |
35 | 35 |
use SL::DB::ValidityToken; |
36 |
use SL::Model::Record; |
|
36 | 37 |
|
37 | 38 |
use SL::Helper::CreatePDF qw(:all); |
38 | 39 |
use SL::Helper::PrintOptions; |
... | ... | |
107 | 108 |
|
108 | 109 |
my $reclamation = SL::DB::Reclamation->new(id => $::form->{from_id})->load; |
109 | 110 |
my %params; |
110 |
$params{destination_type} = $reclamation->is_sales ? 'sales_order'
|
|
111 |
: 'purchase_order';
|
|
112 |
my $order = SL::DB::Order->new_from($reclamation, %params);
|
|
111 |
my $target_type = $reclamation->is_sales ? 'sales_order'
|
|
112 |
: 'purchase_order'; |
|
113 |
my $order = SL::Model::Record->new_from_workflow($reclamation, $target_type);
|
|
113 | 114 |
$self->{converted_from_reclamation_id} = $::form->{from_id}; |
114 | 115 |
|
115 | 116 |
$self->order($order); |
SL/Controller/Reclamation.pm | ||
---|---|---|
34 | 34 |
|
35 | 35 |
use SL::Controller::Helper::GetModels; |
36 | 36 |
|
37 |
use SL::DB::Order; |
|
38 |
use SL::DB::DeliveryOrder; |
|
39 |
use SL::DB::Invoice; |
|
40 |
use SL::Model::Record; |
|
41 |
|
|
37 | 42 |
use List::Util qw(first sum0); |
38 | 43 |
use List::UtilsBy qw(sort_by uniq_by); |
39 | 44 |
use List::MoreUtils qw(any none pairwise first_index); |
... | ... | |
116 | 121 |
return $self->js->render(); |
117 | 122 |
} |
118 | 123 |
|
119 |
require SL::DB::Order; |
|
120 | 124 |
my $order = SL::DB::Order->new(id => $::form->{from_id})->load; |
121 |
my $reclamation = $order->convert_to_reclamation(); |
|
125 |
my $target_type = $order->is_sales ? 'sales_reclamation' |
|
126 |
: 'purchase_reclamation'; |
|
127 |
my $reclamation = SL::Model::Record->new_from_workflow($order, $target_type); |
|
122 | 128 |
|
123 | 129 |
$self->reclamation($reclamation); |
124 | 130 |
|
... | ... | |
143 | 149 |
return $self->js->render(); |
144 | 150 |
} |
145 | 151 |
|
146 |
require SL::DB::DeliveryOrder; |
|
147 | 152 |
my $delivery_order = SL::DB::DeliveryOrder->new(id => $::form->{from_id})->load; |
148 |
my $reclamation = $delivery_order->convert_to_reclamation(); |
|
153 |
my $target_type = $delivery_order->is_sales ? 'sales_reclamation' |
|
154 |
: 'purchase_reclamation'; |
|
155 |
my $reclamation = SL::Model::Record->new_from_workflow($delivery_order, $target_type); |
|
149 | 156 |
|
150 | 157 |
$self->reclamation($reclamation); |
151 | 158 |
|
... | ... | |
170 | 177 |
return $self->js->render(); |
171 | 178 |
} |
172 | 179 |
|
173 |
require SL::DB::Invoice; |
|
174 | 180 |
my $invoice = SL::DB::Invoice->new(id => $::form->{from_id})->load; |
175 |
my $reclamation = $invoice->convert_to_reclamation(); |
|
181 |
my $target_type = 'sales_reclamation'; |
|
182 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type); |
|
176 | 183 |
|
177 | 184 |
$self->reclamation($reclamation); |
178 | 185 |
|
... | ... | |
200 | 207 |
require SL::DB::PurchaseInvoice; |
201 | 208 |
my $invoice = SL::DB::PurchaseInvoice->new(id => $::form->{from_id})->load; |
202 | 209 |
$invoice->{type} = $invoice->invoice_type; #can't add type → invoice_type in SL/DB/PurchaseInvoice |
203 |
my $reclamation = $invoice->convert_to_reclamation(); |
|
210 |
my $target_type = 'purchase_reclamation'; |
|
211 |
my $reclamation = SL::Model::Record->new_from_workflow($invoice, $target_type); |
|
204 | 212 |
|
205 | 213 |
$self->reclamation($reclamation); |
206 | 214 |
|
SL/DB/DeliveryOrder.pm | ||
---|---|---|
152 | 152 |
employee => SL::DB::Manager::Employee->current, |
153 | 153 |
closed => 0, |
154 | 154 |
delivered => 0, |
155 |
order_type => $params{type}, |
|
155 |
order_type => $params{destination_type},
|
|
156 | 156 |
transdate => DateTime->today_local, |
157 | 157 |
); |
158 | 158 |
|
SL/Model/Record.pm | ||
---|---|---|
2 | 2 |
|
3 | 3 |
use strict; |
4 | 4 |
|
5 |
use SL::Locale::String qw(t8); |
|
5 |
use Carp; |
|
6 |
|
|
7 |
use SL::DB::Order; |
|
8 |
use SL::DB::DeliveryOrder; |
|
9 |
use SL::DB::Reclamation; |
|
10 |
use SL::DB::Invoice; |
|
6 | 11 |
|
12 |
use SL::Locale::String qw(t8); |
|
7 | 13 |
|
8 | 14 |
sub new { |
9 | 15 |
my ($class, $target_type, %flags) = @_; |
... | ... | |
18 | 24 |
} |
19 | 25 |
|
20 | 26 |
sub new_from_workflow { |
21 |
my ($class, $source_objects, $target_type, %flags) = @_;
|
|
27 |
my ($class, $source_object, $target_subtype, %flags) = @_;
|
|
22 | 28 |
|
23 |
# source: entweder das einzelne quellobjekt oder ein arrayref von quellobjekten. |
|
24 |
# - wenn ein arrayref übergeben wurde muss der code testen ob die objekte alle subtype gleich sind und evtl customer/vendor gleich sind |
|
29 |
# source: ein quellobjekt |
|
25 | 30 |
# target type: sollte ein subtype sein. wer das hier implementiert, sollte auch eine subtype registratur bauen in der man subtypes nachschlagen kann |
26 | 31 |
# flags: welche extra behandlungen sollen gemacht werden, z.B. record_links setzen |
27 | 32 |
|
28 |
# muss prüfen ob diese umwandlung korrekt ist
|
|
33 |
# (muss prüfen ob diese umwandlung korrekt ist)
|
|
29 | 34 |
# muss das entsprechende new_from in den objekten selber benutzen |
30 | 35 |
# und dann evtl nachbearbeitung machen (die bisher im controller stand) |
31 | 36 |
|
... | ... | |
33 | 38 |
|
34 | 39 |
# fehlerfall: exception aus unterliegendem code bubblen oder neue exception werfen |
35 | 40 |
# rückgabe: das neue objekt |
41 |
|
|
42 |
$flags{destination_type} = $target_subtype; |
|
43 |
my %defaults_flags = ( |
|
44 |
no_linked_records => 0, |
|
45 |
); |
|
46 |
%flags = (%flags, %defaults_flags); |
|
47 |
|
|
48 |
my %subtype_to_type = ( |
|
49 |
# Order |
|
50 |
"request_quotation" => "SL::DB::Order", |
|
51 |
"purchase_order" => "SL::DB::Order", |
|
52 |
"sales_quotation" => "SL::DB::Order", |
|
53 |
"sales_order" => "SL::DB::Order", |
|
54 |
# DeliveryOrder |
|
55 |
"sales_delivery_order" => "SL::DB::DeliveryOrder", |
|
56 |
"purchase_delivery_order" => "SL::DB::DeliveryOrder", |
|
57 |
"rma_delivery_order" => "SL::DB::DeliveryOrder", |
|
58 |
"supplier_delivery_order" => "SL::DB::DeliveryOrder", |
|
59 |
# Reclamation |
|
60 |
"sales_reclamation" => "SL::DB::Reclamation", |
|
61 |
"purchase_reclamation" => "SL::DB::Reclamation", |
|
62 |
); |
|
63 |
my $target_type = $subtype_to_type{$target_subtype}; |
|
64 |
unless ($target_type) { |
|
65 |
croak("Conversion not supported to $target_subtype"); |
|
66 |
} |
|
67 |
|
|
68 |
my $target_object = ${target_type}->new_from($source_object, %flags); |
|
69 |
return $target_object; |
|
36 | 70 |
} |
37 | 71 |
|
38 | 72 |
# im Moment nur bei Aufträgen |
Auch abrufbar als: Unified diff
Model::Record: new_from_workflow implementiert