From 632f0308562656fd01b8bcf75839f2ce5490c03b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Fri, 1 Oct 2021 17:50:17 +0200 Subject: [PATCH] DeliveryOrder: types im objekt richtig setzen --- SL/DB/DeliveryOrder.pm | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/SL/DB/DeliveryOrder.pm b/SL/DB/DeliveryOrder.pm index 6a6c3b1be..a7c20cb9b 100644 --- a/SL/DB/DeliveryOrder.pm +++ b/SL/DB/DeliveryOrder.pm @@ -17,6 +17,8 @@ use SL::DB::Helper::TransNumberGenerator; use SL::DB::Part; use SL::DB::Unit; +use SL::Controller::DeliveryOrder::TypeData; + use SL::Helper::Number qw(_format_total _round_total); use List::Util qw(first); @@ -77,7 +79,7 @@ sub sales_order { } sub type { - return shift->customer_id ? 'sales_delivery_order' : 'purchase_delivery_order'; + goto &order_type; } sub displayable_type { @@ -150,6 +152,14 @@ sub new_from { $args{shipto_id} = $source->shipto_id; } + # infer type from legacy fields if not given + $params{order_type} //= $source->customer_id ? 'sales_delivery_order' + : $source->vendor_id ? 'purchase_delivery_order' + : undef; + + # overwrite legacy is_sales from type_data + $args{is_sales} = SL::Controller::DeliveryOrder::TypeData::get3($params{order_type}, "properties", "is_customer"); + my $delivery_order = $class->new(%args); $delivery_order->assign_attributes(%{ $params{attributes} }) if $params{attributes}; my $items = delete($params{items}) || $source->items_sorted; @@ -291,6 +301,7 @@ sub new_from_time_recordings { } else { my %args = ( is_sales => 1, + order_type => 'sales_delivery_order', delivered => 0, customer_id => $sources->[0]->customer_id, taxzone_id => $sources->[0]->customer->taxzone_id, @@ -306,8 +317,14 @@ sub new_from_time_recordings { return $delivery_order; } +# legacy for compatibility +# use type_data cusomtervendor and transfer direction instead +sub is_sales { + SL::Controller::DeliveryOrder::TypeData::get3($_[0]->order_type, "properties", "is_customer"); +} + sub customervendor { - $_[0]->is_sales ? $_[0]->customer : $_[0]->vendor; + SL::Controller::DeliveryOrder::TypeData::get3($_[0]->order_type, "properties", "is_customer") ? $_[0]->customer : $_[0]->vendor; } sub convert_to_invoice { -- 2.20.1