Revision 2f7c7cd5
Von Sven Schöling vor mehr als 7 Jahren hinzugefügt
SL/Dev/Inventory.pm | ||
---|---|---|
338 | 338 |
|
339 | 339 |
Creates a new warehouse and bins, and immediately saves them. Returns the |
340 | 340 |
warehouse and the first bin object. |
341 |
|
|
341 | 342 |
my ($wh, $bin) = SL::Dev::Inventory::create_warehouse_and_bins(); |
342 | 343 |
|
343 | 344 |
Create named warehouse with 10 bins: |
344 |
my ($wh, $bin) = SL::Dev::Inventory::create_warehouse_and_bins(warehouse_description => 'Testlager', |
|
345 |
bin_description => 'Testlagerplatz', |
|
346 |
number_of_bins => 10, |
|
347 |
); |
|
345 |
|
|
346 |
my ($wh, $bin) = SL::Dev::Inventory::create_warehouse_and_bins( |
|
347 |
warehouse_description => 'Test warehouse', |
|
348 |
bin_description => 'Test bin', |
|
349 |
number_of_bins => 10, |
|
350 |
); |
|
351 |
|
|
348 | 352 |
To access the second bin: |
353 |
|
|
349 | 354 |
my $bin2 = $wh->bins->[1]; |
350 | 355 |
|
351 | 356 |
=head2 C<set_stock %PARAMS> |
... | ... | |
353 | 358 |
Change the stock level of a certain part by creating an inventory event. |
354 | 359 |
To access the updated onhand the part object needs to be loaded afterwards. |
355 | 360 |
|
356 |
Mandatory params: |
|
357 |
part - an SL::DB::Part object or a parts_id |
|
358 |
qty | abs_qty |
|
359 |
qty : the qty to increase of decrease the stock level by |
|
360 |
abs_qty : sets stock level for a certain part to abs_qty by creating |
|
361 |
a stock event with the current difference |
|
361 |
Parameter: |
|
362 |
|
|
363 |
=over 4 |
|
364 |
|
|
365 |
=item C<part> |
|
366 |
|
|
367 |
Mandatory. An SL::DB::Part object or a parts_id. |
|
368 |
|
|
369 |
=item C<qty> |
|
370 |
|
|
371 |
The qty to increase of decrease the stock level by. |
|
372 |
|
|
373 |
Exactly one of C<qty> and C<abs_qty> is mandatory. |
|
374 |
|
|
375 |
=item C<abs_qty> |
|
376 |
|
|
377 |
Sets stock level for a certain part to abs_qty by creating a stock event with |
|
378 |
the current difference. |
|
379 |
|
|
380 |
Exactly one of C<qty> and C<abs_qty> is mandatory. |
|
381 |
|
|
382 |
=item C<bin_id> |
|
362 | 383 |
|
363 |
Optional params: |
|
364 |
bin_id | bin |
|
365 |
shippingdate : may be a DateTime object or a string that needs to be parsed by parse_date_to_object. |
|
366 |
unit : SL::DB::Unit object, or the name of an SL::DB::Unit object |
|
384 |
=item C<bin> |
|
385 |
|
|
386 |
Optional. The bin for inventory entry. |
|
367 | 387 |
|
368 | 388 |
If no bin is passed the default bin of the part is used, if that doesn't exist |
369 | 389 |
either there will be an error. |
370 | 390 |
|
391 |
=item C<shippingdate> |
|
392 |
|
|
393 |
Optional. May be a DateTime object or a string that needs to be parsed by |
|
394 |
parse_date_to_object. |
|
395 |
|
|
396 |
=item C<unit> |
|
397 |
|
|
398 |
Optional. SL::DB::Unit object, or the name of an SL::DB::Unit object. |
|
399 |
|
|
400 |
=back |
|
401 |
|
|
371 | 402 |
C<set_stock> creates the SL::DB::Inventory object from scratch, rather |
372 | 403 |
than passing params to WH->transfer_in or WH->transfer_out. |
373 | 404 |
|
374 | 405 |
Examples: |
406 |
|
|
375 | 407 |
my $part = SL::DB::Manager::Part->find_by(partnumber => '1'); |
376 |
SL::Dev::Inventory::set_stock(part => $part, qty => 5);
|
|
408 |
SL::Dev::Inventory::set_stock(part => $part, abs_qty => 5);
|
|
377 | 409 |
SL::Dev::Inventory::set_stock(part => $part, qty => -2); |
378 | 410 |
$part->load; |
379 | 411 |
$part->onhand; # 3 |
380 | 412 |
|
381 | 413 |
Set stock level of a part in a certain bin_id to 10: |
414 |
|
|
382 | 415 |
SL::Dev::Inventory::set_stock(part => $part, bin_id => 99, abs_qty => 10); |
383 | 416 |
|
384 | 417 |
Create 10 warehouses with 5 bins each, then create 100 parts and increase the |
385 | 418 |
stock qty in a random bin by a random positive qty for each of the parts: |
386 | 419 |
|
387 |
SL::Dev::Inventory::create_warehouse_and_bins(warehouse_description => "Testlager $_") for ( 1 .. 10 ); |
|
388 |
SL::Dev::Part::create_part(description => "Testpart $_")->save for ( 1 .. 100 ); |
|
420 |
SL::Dev::Inventory::create_warehouse_and_bins( |
|
421 |
warehouse_description => "Test Warehouse $_" |
|
422 |
) for 1 .. 10; |
|
423 |
SL::Dev::Part::create_part( |
|
424 |
description => "Test Part $_" |
|
425 |
)->save for 1 .. 100; |
|
389 | 426 |
my $bins = SL::DB::Manager::Bin->get_all; |
390 |
SL::Dev::Inventory::set_stock(part => $_, |
|
391 |
qty => int(rand(99))+1, |
|
392 |
bin => $bins->[ rand @{$bins} ], |
|
393 |
) foreach @{ SL::DB::Manager::Part->get_all() }; |
|
427 |
SL::Dev::Inventory::set_stock( |
|
428 |
part => $_, |
|
429 |
qty => int(rand(99))+1, |
|
430 |
bin => $bins->[ rand @{$bins} ], |
|
431 |
) for @{ SL::DB::Manager::Part->get_all }; |
|
394 | 432 |
|
395 | 433 |
=head2 C<transfer_stock %PARAMS> |
396 | 434 |
|
397 | 435 |
Transfers parts from one bin to another. |
398 | 436 |
|
399 |
Mandatory params: |
|
400 |
part | parts_id - an SL::DB::Part object or a parts_id |
|
401 |
from_bin - an SL::DB::Bin object |
|
402 |
to_bin qty - an SL::DB::Bin object |
|
437 |
Parameters: |
|
438 |
|
|
439 |
=over 4 |
|
440 |
|
|
441 |
=item C<part> |
|
442 |
|
|
443 |
=item C<part_id> |
|
444 |
|
|
445 |
Mandatory. An SL::DB::Part object or a parts_id. |
|
446 |
|
|
447 |
=item C<from_bin> |
|
448 |
|
|
449 |
=item C<to_bin> |
|
403 | 450 |
|
404 |
Optional params: shippingdate |
|
451 |
Mandatory. SL::DB::Bin objects. |
|
452 |
|
|
453 |
=item C<qty> |
|
454 |
|
|
455 |
Mandatory. |
|
456 |
|
|
457 |
=item C<shippingdate> |
|
458 |
|
|
459 |
Optional. |
|
460 |
|
|
461 |
=back |
|
405 | 462 |
|
406 | 463 |
The unit is always base_unit and there is no check for negative stock values. |
407 | 464 |
|
... | ... | |
410 | 467 |
|
411 | 468 |
my ($wh, $bin) = SL::Dev::Inventory::create_warehouse_and_bins(); |
412 | 469 |
my $part = SL::Dev::Part::create_part->save; |
413 |
SL::Dev::Inventory::set_stock(part => $part, bin_id => $wh->bins->[2]->id, qty => 5); |
|
414 |
SL::Dev::Inventory::transfer_stock(part => $part, |
|
415 |
from_bin => $wh->bins->[2], |
|
416 |
to_bin => $wh->bins->[4], |
|
417 |
qty => 3 |
|
418 |
); |
|
470 |
SL::Dev::Inventory::set_stock( |
|
471 |
part => $part, |
|
472 |
bin_id => $wh->bins->[2]->id, |
|
473 |
qty => 5, |
|
474 |
); |
|
475 |
SL::Dev::Inventory::transfer_stock( |
|
476 |
part => $part, |
|
477 |
from_bin => $wh->bins->[2], |
|
478 |
to_bin => $wh->bins->[4], |
|
479 |
qty => 3, |
|
480 |
); |
|
419 | 481 |
$part->get_stock(bin_id => $wh->bins->[4]->id); # 3.00000 |
420 | 482 |
$part->get_stock(bin_id => $wh->bins->[2]->id); # 2.00000 |
421 | 483 |
|
... | ... | |
434 | 496 |
As this is just Dev it doesn't check for negative stocks etc. |
435 | 497 |
|
436 | 498 |
Usage: |
499 |
|
|
437 | 500 |
my $sales_delivery_order = SL::DB::Manager::DeliveryOrder->find_by(donumber => 112); |
438 | 501 |
SL::Dev::Inventory::transfer_sales_delivery_order($sales_delivery_order1); |
439 | 502 |
|
... | ... | |
449 | 512 |
Doesn't check for available qty. |
450 | 513 |
|
451 | 514 |
Usage: |
515 |
|
|
452 | 516 |
SL::Dev::Inventory::transfer_delivery_order_item($doi, $wh, $bin, $trans_type); |
453 | 517 |
|
454 | 518 |
=head2 C<transfer_in %PARAMS> |
... | ... | |
458 | 522 |
|
459 | 523 |
Does some param checking, sets some defaults, but otherwise uses WH->transfer. |
460 | 524 |
|
461 |
Mandatory params: |
|
462 |
part - an SL::DB::Part object |
|
463 |
qty - a number |
|
525 |
Parameters: |
|
526 |
|
|
527 |
=over 4 |
|
528 |
|
|
529 |
=item C<part> |
|
530 |
|
|
531 |
Mandatory. An SL::DB::Part object. |
|
532 |
|
|
533 |
=item C<qty> |
|
534 |
|
|
535 |
Mandatory. |
|
536 |
|
|
537 |
=item C<bin> |
|
538 |
|
|
539 |
Optional. An SL::DB::Bin object, defaults to $part->bin. |
|
464 | 540 |
|
465 |
Optional params: shippingdate |
|
466 |
bin - an SL::DB::Bin object, defaults to $part->bin |
|
467 |
wh - an SL::DB::Bin object, defaults to $part->warehouse |
|
468 |
unit - a string such as 't', 'Stck', defaults to $part->unit->name |
|
469 |
shippingdate - a DateTime object, defaults to today |
|
470 |
transfer_type - a string such as 'correction', defaults to 'stock' |
|
471 |
comment |
|
541 |
=item C<wh> |
|
542 |
|
|
543 |
Optional. An SL::DB::Bin object, defaults to $part->warehouse. |
|
544 |
|
|
545 |
=item C<unit> |
|
546 |
|
|
547 |
Optional. A string such as 't', 'Stck', defaults to $part->unit->name. |
|
548 |
|
|
549 |
=item C<shippingdate> |
|
550 |
|
|
551 |
Optional. A DateTime object, defaults to today. |
|
552 |
|
|
553 |
=item C<transfer_type> |
|
554 |
|
|
555 |
Optional. A string such as 'correction', defaults to 'stock'. |
|
556 |
|
|
557 |
=item C<comment> |
|
558 |
|
|
559 |
Optional. |
|
560 |
|
|
561 |
=back |
|
472 | 562 |
|
473 | 563 |
Example minimal usage using part default warehouse and bin: |
564 |
|
|
474 | 565 |
my ($wh, $bin) = SL::Dev::Inventory::create_warehouse_and_bins(); |
475 |
my $part = SL::Dev::Part::create_part(unit => 'kg', warehouse => $wh, bin => $bin)->save; |
|
476 |
SL::Dev::Inventory::transfer_in(part => $part, qty => '0.9', unit => 't', comment => '900 kg in t'); |
|
566 |
my $part = SL::Dev::Part::create_part( |
|
567 |
unit => 'kg', |
|
568 |
warehouse => $wh, |
|
569 |
bin => $bin, |
|
570 |
)->save; |
|
571 |
SL::Dev::Inventory::transfer_in( |
|
572 |
part => $part, |
|
573 |
qty => 0.9, |
|
574 |
unit => 't', |
|
575 |
comment => '900 kg in t', |
|
576 |
); |
|
477 | 577 |
|
478 | 578 |
Example with specific transfer_type and warehouse and bin and shipping_date: |
579 |
|
|
479 | 580 |
my $shipping_date = DateTime->today->subtract( days => 20 ); |
480 |
SL::Dev::Inventory::transfer_in(part => $part, |
|
481 |
qty => 5, |
|
482 |
transfer_type => 'correction', |
|
483 |
bin => $bin, |
|
484 |
shipping_date => $shipping_date, |
|
485 |
); |
|
581 |
SL::Dev::Inventory::transfer_in( |
|
582 |
part => $part, |
|
583 |
qty => 5, |
|
584 |
transfer_type => 'correction', |
|
585 |
bin => $bin, |
|
586 |
shipping_date => $shipping_date, |
|
587 |
); |
|
486 | 588 |
|
487 | 589 |
=head2 C<transfer_out %PARAMS> |
488 | 590 |
|
Auch abrufbar als: Unified diff
SL::Dev::Inventory: POD Formatierung