package SL::DB::Inventory;
use strict;
+use Carp;
+use DateTime;
+use SL::DBUtils qw(selectrow_query);
use SL::DB::MetaSetup::Inventory;
use SL::DB::Manager::Inventory;
goto &parts;
}
+sub new_from {
+ my ($class, $obj) = @_;
+
+ if ('SL::DB::DeliveryOrderItemsStock' eq ref $obj) {
+ return $class->new_from_delivery_order_stock($obj);
+ }
+
+ croak "unknown obj type (@{[ ref $obj ]}) for SL::DB::Inventory::new_from";
+}
+
+sub new_from_delivery_order_stock {
+ my ($stock) = @_;
+
+ my $project = $stock->delivery_order_item->effective_project;
+
+ return __PACKAGE__->new(
+ delivery_order_items_stock_id => $stock->id,
+ parts_id => $stock->delivery_order_item->parts_id,
+ qty => $stock->unit->convert_to($stock->qty => $stock->delivery_order_item->part->unit_obj),
+ unit => $stock->delivery_order_item->part->unit_obj,
+ warehouse_id => $stock->warehouse_id,
+ bin_id => $stock->bin_id,
+ chargenumber => $stock->chargenumber,
+ bestbefore => $stock->bestbefore,
+ project_id => $project ? $project->id : undef,
+ # trans_type - not set here, set in controller
+ );
+}
+
sub _before_save_create_trans_id {
my ($self, %params) = @_;