Revision 9b5b900b
Von Tamino Steinert vor fast 2 Jahren hinzugefügt
SL/DB/DeliveryOrder.pm | ||
---|---|---|
124 | 124 |
return $cloned; |
125 | 125 |
} |
126 | 126 |
|
127 |
sub convert_to_reclamation { |
|
128 |
my ($self, %params) = @_; |
|
129 |
|
|
130 |
$params{destination_type} = $self->is_sales ? 'sales_reclamation' |
|
131 |
: 'purchase_reclamation'; |
|
132 |
|
|
133 |
my $reclamation = SL::DB::Reclamation->new_from($self, %params); |
|
134 |
|
|
135 |
return $reclamation; |
|
136 |
} |
|
137 |
|
|
127 | 138 |
sub new_from { |
128 | 139 |
my ($class, $source, %params) = @_; |
129 | 140 |
|
130 |
croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) eq 'SL::DB::Order'; |
|
141 |
my %allowed_sources = map { $_ => 1 } qw( |
|
142 |
SL::DB::Reclamation |
|
143 |
SL::DB::Order |
|
144 |
); |
|
145 |
unless( $allowed_sources{ref $source} ) { |
|
146 |
croak("Unsupported source object type '" . ref($source) . "'"); |
|
147 |
} |
|
131 | 148 |
|
132 |
my ($item_parent_id_column, $item_parent_column); |
|
149 |
my %record_args = ( |
|
150 |
donumber => undef, |
|
151 |
employee => SL::DB::Manager::Employee->current, |
|
152 |
closed => 0, |
|
153 |
delivered => 0, |
|
154 |
order_type => $params{type}, |
|
155 |
transdate => DateTime->today_local, |
|
156 |
); |
|
133 | 157 |
|
134 |
if (ref($source) eq 'SL::DB::Order') { |
|
135 |
$item_parent_id_column = 'trans_id'; |
|
136 |
$item_parent_column = 'order'; |
|
158 |
if ( ref($source) eq 'SL::DB::Order' ) { |
|
159 |
map{ ( $record_args{$_} = $source->$_ ) } # {{{ for vim folds |
|
160 |
qw( |
|
161 |
billing_address_id |
|
162 |
cp_id |
|
163 |
currency_id |
|
164 |
cusordnumber |
|
165 |
customer_id |
|
166 |
delivery_term_id |
|
167 |
department_id |
|
168 |
globalproject_id |
|
169 |
intnotes |
|
170 |
language_id |
|
171 |
notes |
|
172 |
ordnumber |
|
173 |
payment_id |
|
174 |
reqdate |
|
175 |
salesman_id |
|
176 |
shippingpoint |
|
177 |
shipvia |
|
178 |
taxincluded |
|
179 |
taxzone_id |
|
180 |
transaction_description |
|
181 |
vendor_id |
|
182 |
); |
|
183 |
# }}} for vim folds |
|
184 |
} elsif ( ref($source) eq 'SL::DB::Reclamation' ) { |
|
185 |
map{ ( $record_args{$_} = $source->$_ ) } # {{{ for vim folds |
|
186 |
#billing_address_id #TODO(Tamino): add billing_address_id to reclamation |
|
187 |
qw( |
|
188 |
currency_id |
|
189 |
customer_id |
|
190 |
delivery_term_id |
|
191 |
department_id |
|
192 |
globalproject_id |
|
193 |
intnotes |
|
194 |
language_id |
|
195 |
notes |
|
196 |
payment_id |
|
197 |
reqdate |
|
198 |
salesman_id |
|
199 |
shippingpoint |
|
200 |
shipvia |
|
201 |
taxincluded |
|
202 |
taxzone_id |
|
203 |
transaction_description |
|
204 |
vendor_id |
|
205 |
); |
|
206 |
$record_args{cp_id} = $source->contact_id; |
|
207 |
$record_args{cusordnumber} = $source->cv_record_number; |
|
208 |
# }}} for vim folds |
|
137 | 209 |
} |
138 | 210 |
|
139 |
my %args = ( map({ ( $_ => $source->$_ ) } qw(cp_id currency_id customer_id cusordnumber delivery_term_id department_id employee_id globalproject_id intnotes language_id notes |
|
140 |
ordnumber payment_id reqdate salesman_id shippingpoint shipvia taxincluded taxzone_id transaction_description vendor_id billing_address_id |
|
141 |
)), |
|
142 |
closed => 0, |
|
143 |
delivered => 0, |
|
144 |
order_type => $params{type}, |
|
145 |
transdate => DateTime->today_local, |
|
146 |
); |
|
147 |
|
|
148 | 211 |
# Custom shipto addresses (the ones specific to the sales/purchase |
149 | 212 |
# record and not to the customer/vendor) are only linked from |
150 | 213 |
# shipto → delivery_orders. Meaning delivery_orders.shipto_id |
151 | 214 |
# will not be filled in that case. |
152 | 215 |
if (!$source->shipto_id && $source->id) { |
153 |
$args{custom_shipto} = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto; |
|
154 |
|
|
216 |
$record_args{custom_shipto} = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto; |
|
155 | 217 |
} else { |
156 |
$args{shipto_id} = $source->shipto_id; |
|
218 |
$record_args{shipto_id} = $source->shipto_id;
|
|
157 | 219 |
} |
158 | 220 |
|
159 | 221 |
# infer type from legacy fields if not given |
160 |
$args{order_type} //= $source->customer_id ? 'sales_delivery_order' |
|
222 |
$record_args{order_type} //= $source->customer_id ? 'sales_delivery_order'
|
|
161 | 223 |
: $source->vendor_id ? 'purchase_delivery_order' |
162 | 224 |
: $source->is_sales ? 'sales_delivery_order' |
163 | 225 |
: croak "need some way to set delivery order type from source"; |
164 | 226 |
|
165 |
my $delivery_order = $class->new(%args); |
|
227 |
my $delivery_order = $class->new(%record_args);
|
|
166 | 228 |
$delivery_order->assign_attributes(%{ $params{attributes} }) if $params{attributes}; |
167 |
my $items = delete($params{items}) || $source->items_sorted; |
|
168 |
my %item_parents; |
|
169 |
|
|
170 |
# do not copy items when converting to supplier delivery order |
|
171 |
my @items = $delivery_order->is_type(SUPPLIER_DELIVERY_ORDER_TYPE) ? () : map { |
|
172 |
my $source_item = $_; |
|
173 |
my $source_item_id = $_->$item_parent_id_column; |
|
174 |
my @custom_variables = map { _clone_orderitem_cvar($_) } @{ $source_item->custom_variables }; |
|
175 |
|
|
176 |
$item_parents{$source_item_id} ||= $source_item->$item_parent_column; |
|
177 |
my $item_parent = $item_parents{$source_item_id}; |
|
178 |
|
|
179 |
my $current_do_item = SL::DB::DeliveryOrderItem->new(map({ ( $_ => $source_item->$_ ) } |
|
180 |
qw(base_qty cusordnumber description discount lastcost longdescription marge_price_factor parts_id price_factor price_factor_id |
|
181 |
project_id qty reqdate sellprice serialnumber transdate unit active_discount_source active_price_source |
|
182 |
)), |
|
183 |
custom_variables => \@custom_variables, |
|
184 |
ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, |
|
185 |
); |
|
186 |
$current_do_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; |
|
187 |
$current_do_item; |
|
188 |
} @{ $items }; |
|
229 |
|
|
230 |
my $items = delete($params{items}) || $source->items_sorted; |
|
231 |
my @items = $delivery_order->is_type(SUPPLIER_DELIVERY_ORDER_TYPE) ? () |
|
232 |
: map { SL::DB::DeliveryOrderItem->new_from($_) } @{ $items }; |
|
189 | 233 |
|
190 | 234 |
@items = grep { $params{item_filter}->($_) } @items if $params{item_filter}; |
191 | 235 |
@items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty}; |
Auch abrufbar als: Unified diff
Workflow: delivery_order ↔ reclamation