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