Revision 468eee22
Von Tamino Steinert vor mehr als 2 Jahren hinzugefügt
SL/DB/DeliveryOrderItem.pm | ||
---|---|---|
36 | 36 |
|
37 | 37 |
# methods |
38 | 38 |
|
39 |
sub new_from { |
|
40 |
my ($class, $source, %params) = @_; |
|
41 |
|
|
42 |
my %allowed_sources = map { $_ => 1 } qw( |
|
43 |
SL::DB::ReclamationItem |
|
44 |
SL::DB::OrderItem |
|
45 |
); |
|
46 |
unless( $allowed_sources{ref $source} ) { |
|
47 |
croak("Unsupported source object type '" . ref($source) . "'"); |
|
48 |
} |
|
49 |
|
|
50 |
my @custom_variables = map { _clone_cvar_for_delivery_order_item($_) } @{ $source->custom_variables }; |
|
51 |
|
|
52 |
my %item_args; |
|
53 |
if (ref($source) eq 'SL::DB::ReclamationItem') { |
|
54 |
map { $item_args{$_} = $source->$_ } # {{{ for vim folds |
|
55 |
qw( |
|
56 |
active_discount_source |
|
57 |
active_price_source |
|
58 |
base_qty |
|
59 |
description |
|
60 |
discount |
|
61 |
lastcost |
|
62 |
longdescription |
|
63 |
parts_id |
|
64 |
position |
|
65 |
price_factor |
|
66 |
price_factor_id |
|
67 |
pricegroup_id |
|
68 |
project_id |
|
69 |
qty |
|
70 |
reqdate |
|
71 |
sellprice |
|
72 |
serialnumber |
|
73 |
unit |
|
74 |
); |
|
75 |
$item_args{custom_variables} = \@custom_variables; |
|
76 |
# }}} for vim folds |
|
77 |
} elsif (ref($source) eq 'SL::DB::OrderItem') { |
|
78 |
map { $item_args{$_} = $source->$_ } # {{{ for vim folds |
|
79 |
qw( |
|
80 |
active_discount_source |
|
81 |
active_price_source |
|
82 |
base_qty |
|
83 |
cusordnumber |
|
84 |
description |
|
85 |
discount |
|
86 |
lastcost |
|
87 |
longdescription |
|
88 |
marge_price_factor |
|
89 |
parts_id |
|
90 |
price_factor |
|
91 |
price_factor_id |
|
92 |
project_id |
|
93 |
qty |
|
94 |
reqdate |
|
95 |
sellprice |
|
96 |
serialnumber |
|
97 |
transdate |
|
98 |
unit |
|
99 |
); |
|
100 |
$item_args{custom_variables} = \@custom_variables; |
|
101 |
$item_args{ordnumber} = ref($source->record) eq 'SL::DB::Order' ? $source->record->ordnumber : $source->ordnumber; |
|
102 |
# }}} for vim folds |
|
103 |
} |
|
104 |
|
|
105 |
my $item = $class->new(%item_args); |
|
106 |
|
|
107 |
my $source_table = ''; |
|
108 |
if( ref($source) eq 'SL::DB::OrderItem' ) { |
|
109 |
$source_table = 'orderitems'; |
|
110 |
} elsif ( ref($source) eq 'SL::DB::ReclamationItem' ) { |
|
111 |
$source_table = 'reclamation_items'; |
|
112 |
} |
|
113 |
$item->{"converted_from_". $source_table ."_id"} = $_->{id}; |
|
114 |
|
|
115 |
return $item; |
|
116 |
} |
|
117 |
|
|
118 |
sub _clone_cvar_for_delivery_order_item { |
|
119 |
my ($cvar) = @_; |
|
120 |
|
|
121 |
my $cloned = $_->clone_and_reset; |
|
122 |
$cloned->sub_module('delivery_order_items'); |
|
123 |
|
|
124 |
return $cloned; |
|
125 |
} |
|
126 |
|
|
39 | 127 |
sub record { goto &delivery_order } |
40 | 128 |
sub record_id { goto &delivery_order_id } |
41 | 129 |
|
Auch abrufbar als: Unified diff
Workflow: delivery_order ↔ reclamation