Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 98bdc3f1

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID 98bdc3f1706bcd35c6261734f372bf000b922953
  • Vorgänger a5c1b85d
  • Nachfolger 00a6bdd7

CsvImport Lieferscheine: Zusammenfassen von Lieferpositionen

Wenn in mehreren Positionen Teilmengen einer Position eines Auftrags
geliefert werden, dann diese Zusammenfassen.

Unterschiede anzeigen:

SL/Controller/CsvImport/DeliveryOrder.pm
711 711
    push @{ $entry->{errors} }, $::locale->text('Error: More than one source order found');
712 712
  }
713 713

  
714
  foreach my $order (@$orders) {
715
    $self->{remaining_source_qtys_by_item_id} = { map { $_->id => $_->qty } @{ $order->items } };
716
  }
717

  
714 718
  $record->{source_orders} = $orders;
715 719
}
716 720

  
......
722 726

  
723 727
  return if !@{ $record->{source_orders} };
724 728

  
729
  # Todo: units?
730

  
725 731
  foreach my $order (@{ $record->{source_orders} }) {
726
    $item->{source_item} = first { $item->parts_id == $_->parts_id && $item->qty == $_->qty} @{ $order->items_sorted };
727
    last if $item->{source_item};
732
    # First: Excact matches and source order position is still complete.
733
    $item->{source_item} = first {
734
         $item->parts_id                                     == $_->parts_id
735
      && $item->qty                                          == $_->qty
736
      && $self->{remaining_source_qtys_by_item_id}->{$_->id} == $_->qty
737
    } @{ $order->items_sorted };
738
    if ($item->{source_item}) {
739
      $self->{remaining_source_qtys_by_item_id}->{$item->{source_item}->id} -= $item->qty;
740
      last;
741
    }
742

  
743
    # Second: Smallest remaining order qty greater or equal delivery order qty.
744
    $item->{source_item} = first {
745
         $item->parts_id                                     == $_->parts_id
746
      && $self->{remaining_source_qtys_by_item_id}->{$_->id} >= $item->qty
747
    } sort { $self->{remaining_source_qtys_by_item_id}->{$a->id} <=> $self->{remaining_source_qtys_by_item_id}->{$b->id} } @{ $order->items_sorted };
748
    if ($item->{source_item}) {
749
      $self->{remaining_source_qtys_by_item_id}->{$item->{source_item}->id} -= $item->qty;
750
      last;
751
    }
752

  
753
    # Last: Overdelivery?
754
    # $item->{source_item} = first {
755
    #      $item->parts_id == $_->parts_id
756
    # } @{ $order->items_sorted };
757
    # if ($item->{source_item}) {
758
    #   $self->{remaining_source_qtys_by_item_id}->{$item->{source_item}->id} -= $item->qty;
759
    #   last;
760
    # }
728 761
  }
729 762
}
730 763

  
t/controllers/csvimport/delivery_orders.t
1
use Test::More tests => 15;
1
use Test::More tests => 28;
2 2

  
3 3
use strict;
4 4

  
......
117 117
    ordnumber  => '1234',
118 118
    orderitems => [ create_order_item(part => $parts[0], qty =>  3, sellprice => 70),
119 119
                    create_order_item(part => $parts[1], qty => 10, sellprice => 50),
120
                    create_order_item(part => $parts[2], qty =>  8, sellprice => 80)
120
                    create_order_item(part => $parts[2], qty =>  8, sellprice => 80),
121
                    create_order_item(part => $parts[2], qty => 11, sellprice => 80)
121 122
    ]
122 123
  )
123 124
);
......
131 132
OrderItem;TestPart2;10
132 133
OrderItem;TestPart3;7
133 134
OrderItem;TestPart3;1
135
OrderItem;TestPart3;11
134 136
EOL
135 137

  
138
  1;                            # make emacs happy
139

  
140
# should be:
141
# delivery oder pos/qty <- order pos/qty
142
#       1/5             <-       -
143
#       2/10            <-      2/10
144
#       3/7             <-      3/7
145
#       4/1             <-      3/1
146
#       5/11            <-      4/11
147

  
136 148
$entries = do_import($file);
149
$orders[0]->load;               # reload order to get correct delivered status
137 150

  
138 151
$entry = $entries->[0];
139

  
140 152
is $entry->{object}->ordnumber, '1234', 'with source order: ordnumber';
141 153

  
142 154
my $linked = $orders[0]->linked_records(to => 'DeliveryOrder');
......
159 171

  
160 172
$entry = $entries->[3];
161 173
$linked = $entry->{object}->linked_records(from => 'OrderItem');
162
ok(scalar @$linked == 0, 'with source order: delivered qty < ordered qty: delivery order item not linked');
174
ok(scalar @$linked == 1, 'with source order: delivered qty < ordered qty: delivery order item linked (fill up)');
175
ok($linked->[0]->position == 3, 'with source order: delivered qty < ordered qty: order position ok (fill up)');
176

  
177
$entry = $entries->[4];
178
$linked = $entry->{object}->linked_records(from => 'OrderItem');
179
ok(scalar @$linked == 1, 'with source order: delivered qty < ordered qty: delivery order item linked (fill up) 2');
180
ok($linked->[0]->position == 3, 'with source order: delivered qty < ordered qty: order position ok (fill up) 2');
181

  
182
$entry = $entries->[5];
183
$linked = $entry->{object}->linked_records(from => 'OrderItem');
184
ok(scalar @$linked == 1, 'with source order: delivered qty == ordered qty: found exact match after fill up');
185
ok($linked->[0]->position == 4, 'with source order: delivered qty == ordered qty: order position ok after fill up');
186

  
187
ok(!$orders[0]->delivered, 'with source order: order not completely delivered');
188

  
189
$entries = undef;
190
clear_up;
163 191

  
164 192
#####
193
@customers = (new_customer(name => 'TestCustomer1', discount => 0)->save);
194
@parts = (
195
  new_part(description => 'TestPart1', ean => '')->save,
196
  new_part(description => 'TestPart2', ean => '')->save,
197
  new_part(description => 'TestPart3', ean => '')->save
198
);
199
@orders = (
200
  create_sales_order(
201
    save       => 1,
202
    customer   => $customers[0],
203
    ordnumber  => '1234',
204
    orderitems => [ create_order_item(part => $parts[0], qty =>  3, sellprice => 70),
205
                    create_order_item(part => $parts[1], qty => 10, sellprice => 50),
206
                    create_order_item(part => $parts[2], qty =>  8, sellprice => 80),
207
                    create_order_item(part => $parts[2], qty => 11, sellprice => 80)
208
    ]
209
  )
210
);
211

  
212
$file = \<<EOL;
213
datatype;customer;ordnumber
214
datatype;description;qty
215
datatype
216
DeliveryOrder;TestCustomer1;1234
217
OrderItem;TestPart1;1
218
OrderItem;TestPart2;10
219
OrderItem;TestPart1;2
220
OrderItem;TestPart3;7
221
OrderItem;TestPart3;11
222
OrderItem;TestPart3;1
223

  
224
EOL
225

  
226
  1;                            # make emacs happy
227

  
228
# should be:
229
# delivery oder pos/qty <- order pos/qty
230
#       1/1             <-      1/1
231
#       2/10            <-      2/10
232
#       3/2             <-      1/2
233
#       4/7             <-      3/7
234
#       5/11            <-      4/11
235
#       6/1             <-      3/1
236

  
237
$entries = do_import($file);
238
$orders[0]->load;               # reload order to get correct delivered status
239

  
240
$entry = $entries->[1];
241
$linked = $entry->{object}->linked_records(from => 'OrderItem');
242
ok($linked->[0]->position == 1, 'with source order: mixed qtys and fill up: order position ok 1');
243

  
244
$entry = $entries->[2];
245
$linked = $entry->{object}->linked_records(from => 'OrderItem');
246
ok($linked->[0]->position == 2, 'with source order: mixed qtys and fill up: order position ok 2');
247

  
248
$entry = $entries->[3];
249
$linked = $entry->{object}->linked_records(from => 'OrderItem');
250
ok($linked->[0]->position == 1, 'with source order: mixed qtys and fill up: order position ok 3');
251

  
252
$entry = $entries->[4];
253
$linked = $entry->{object}->linked_records(from => 'OrderItem');
254
ok($linked->[0]->position == 3, 'with source order: mixed qtys and fill up: order position ok 4');
255

  
256
$entry = $entries->[5];
257
$linked = $entry->{object}->linked_records(from => 'OrderItem');
258
ok($linked->[0]->position == 4, 'with source order: mixed qtys and fill up: order position ok 5');
259

  
260
$entry = $entries->[6];
261
$linked = $entry->{object}->linked_records(from => 'OrderItem');
262
ok($linked->[0]->position == 3, 'with source order: mixed qtys and fill up: order position ok 6');
263

  
264
ok(!!$orders[0]->delivered, 'with source order: mixed qtys and fill up: order completely delivered');
265

  
266
#####
267
$entries = undef;
165 268
clear_up;
166 269

  
270
#####
271

  
167 272
$::myconfig{numberformat} = $old_numberformat;
168 273
$::locale                 = $old_locale;
169 274

  

Auch abrufbar als: Unified diff