From 7a1475567922cd777644a36483a89bcaa756eba5 Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Sun, 23 Apr 2017 11:24:58 +0200 Subject: [PATCH] SL/Dev/Record.pm - create_purchase_delivery_order --- SL/Dev/Record.pm | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/SL/Dev/Record.pm b/SL/Dev/Record.pm index 3ec9639f3..649c6b2de 100644 --- a/SL/Dev/Record.pm +++ b/SL/Dev/Record.pm @@ -2,7 +2,7 @@ package SL::Dev::Record; use strict; use base qw(Exporter); -our @EXPORT = qw(create_invoice_item create_sales_invoice create_credit_note create_order_item create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_project); +our @EXPORT = qw(create_invoice_item create_sales_invoice create_credit_note create_order_item create_sales_order create_purchase_order create_delivery_order_item create_sales_delivery_order create_purchase_delivery_order create_project); use SL::DB::Invoice; use SL::DB::InvoiceItem; @@ -114,6 +114,34 @@ sub create_sales_delivery_order { return $delivery_order; } +sub create_purchase_delivery_order { + my (%params) = @_; + + my $record_type = 'purchase_delivery_order'; + my $orderitems = delete $params{orderitems} // _create_two_items($record_type); + _check_items($orderitems, $record_type); + + my $vendor = $params{vendor} // SL::Dev::CustomerVendor::create_vendor(name => 'Testvendor')->save; + die "illegal customer" unless ref($vendor) eq 'SL::DB::Vendor'; + + my $delivery_order = SL::DB::DeliveryOrder->new( + 'is_sales' => 'false', + 'closed' => undef, + vendor_id => $vendor->id, + taxzone_id => $vendor->taxzone_id, + donumber => $params{donumber} // undef, + currency_id => $params{currency_id} // $::instance_conf->get_currency_id, + taxincluded => $params{taxincluded} // 0, + employee_id => $params{employee_id} // SL::DB::Manager::Employee->current->id, + salesman_id => $params{employee_id} // SL::DB::Manager::Employee->current->id, + transdate => $params{transdate} // DateTime->today, + orderitems => $orderitems, + ); + $delivery_order->assign_attributes(%params) if %params; + $delivery_order->save; + return $delivery_order; +} + sub create_sales_order { my (%params) = @_; -- 2.20.1