From: Moritz Bunkus Date: Thu, 18 Nov 2010 07:58:48 +0000 (+0100) Subject: Invoice::post selber ar_id setzen lassen, wenn nicht angegeben X-Git-Tag: release-2.6.3~61^2~7^2~1^2~2^2~48 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=ed3be96543e7f224f5a406a73b61f4dc7e8a31e2;p=kivitendo-erp.git Invoice::post selber ar_id setzen lassen, wenn nicht angegeben --- diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index e9c04ed92..c55a22fc9 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -14,6 +14,7 @@ use SL::DB::Helper::LinkedRecords; use SL::DB::Helper::PriceTaxCalculator; use SL::DB::Helper::TransNumberGenerator; use SL::DB::AccTransaction; +use SL::DB::Chart; use SL::DB::Employee; __PACKAGE__->meta->add_relationship( @@ -123,7 +124,13 @@ sub new_from { sub post { my ($self, %params) = @_; - croak("Missing parameter 'ar_id'") unless $params{ar_id}; + if (!$params{ar_id}) { + my $chart = SL::DB::Manager::Chart->get_all(query => [ SL::DB::Manager::Chart->link_filter('AR') ], + sort_by => 'id ASC', + limit => 1)->[0]; + croak("No AR chart found and no parameter `ar_id' given") unless $chart; + $params{ar_id} = $chart->id; + } my $worker = sub { my %data = $self->calculate_prices_and_taxes; @@ -241,7 +248,8 @@ Posts the invoice. Required parameters are: =item * C The ID of the accounds receivable chart the invoices amounts are -posted to. +posted to. If it is not set then the first chart configured for +accounts receivables is used. =back diff --git a/SL/DB/Order.pm b/SL/DB/Order.pm index 74f713ca0..37fc0fce0 100644 --- a/SL/DB/Order.pm +++ b/SL/DB/Order.pm @@ -91,14 +91,6 @@ sub convert_to_invoice { croak("Conversion to invoices is only supported for sales records") unless $self->customer_id; - if (!$params{ar_id}) { - my $chart = SL::DB::Manager::Chart->get_all(query => [ SL::DB::Manager::Chart->link_filter('AR') ], - sort_by => 'id ASC', - limit => 1)->[0]; - croak("No AR chart found and no parameter `ar_id' given") unless $chart; - $params{ar_id} = $chart->id; - } - my $invoice; if (!$self->db->do_transaction(sub { $invoice = SL::DB::Invoice->new_from($self)->post(%params) || die; @@ -149,11 +141,7 @@ L. That invoice is posted, and C<$self> is linked to the new invoice via L. C<$self>'s C attribute is set to C, and C<$self> is saved. -The arguments in C<%params> are passed to -L. One parameter of note is -C<$paras{ar_id}>. If set it must be the ID of the accounts receivables -chart to post to. If it is not set then the first chart configured for -accounts receivables is used. +The arguments in C<%params> are passed to L. Returns the new invoice instance on success and C on failure. The whole process is run inside a transaction. On failure