From 8d87ea5750980847720a4dd48f7f62e378416895 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 2 Mar 2011 14:20:47 +0100 Subject: [PATCH] Artikelnummernvergabe im TransNumberGenerator --- SL/DB/Helper/TransNumberGenerator.pm | 35 +++++++++++++++++----------- SL/DB/Part.pm | 10 ++++++++ 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/SL/DB/Helper/TransNumberGenerator.pm b/SL/DB/Helper/TransNumberGenerator.pm index 302002981..f7c779305 100644 --- a/SL/DB/Helper/TransNumberGenerator.pm +++ b/SL/DB/Helper/TransNumberGenerator.pm @@ -10,23 +10,30 @@ use List::Util qw(max); use SL::DB::Default; -my $oe_scoping = sub { +sub oe_scoping { SL::DB::Manager::Order->type_filter($_[0]); -}; +} -my $do_scoping = sub { +sub do_scoping { SL::DB::Manager::DeliveryOrder->type_filter($_[0]); -}; - -my %specs = ( ar => { number_column => 'invnumber', fill_holes_in_range => 1 }, - sales_quotation => { number_column => 'quonumber', number_range_column => 'sqnumber', scoping => $oe_scoping, }, - sales_order => { number_column => 'ordnumber', number_range_column => 'sonumber', scoping => $oe_scoping, }, - request_quotation => { number_column => 'quonumber', number_range_column => 'rfqnumber', scoping => $oe_scoping, }, - purchase_order => { number_column => 'ordnumber', number_range_column => 'ponumber', scoping => $oe_scoping, }, - sales_delivery_order => { number_column => 'donumber', number_range_column => 'sdonumber', scoping => $do_scoping, fill_holes_in_range => 1 }, - purchase_delivery_order => { number_column => 'donumber', number_range_column => 'pdonumber', scoping => $do_scoping, fill_holes_in_range => 1 }, - customer => { number_column => 'customernumber', number_range_column => 'customernumber', }, - vendor => { number_column => 'vendornumber', number_range_column => 'vendornumber', }, +} + +sub parts_scoping { + SL::DB::Manager::Part->type_filter($_[0]); +} + +my %specs = ( ar => { number_column => 'invnumber', fill_holes_in_range => 1 }, + sales_quotation => { number_column => 'quonumber', number_range_column => 'sqnumber', scoping => \&oe_scoping, }, + sales_order => { number_column => 'ordnumber', number_range_column => 'sonumber', scoping => \&oe_scoping, }, + request_quotation => { number_column => 'quonumber', number_range_column => 'rfqnumber', scoping => \&oe_scoping, }, + purchase_order => { number_column => 'ordnumber', number_range_column => 'ponumber', scoping => \&oe_scoping, }, + sales_delivery_order => { number_column => 'donumber', number_range_column => 'sdonumber', scoping => \&do_scoping, fill_holes_in_range => 1 }, + purchase_delivery_order => { number_column => 'donumber', number_range_column => 'pdonumber', scoping => \&do_scoping, fill_holes_in_range => 1 }, + customer => { number_column => 'customernumber', number_range_column => 'customernumber', }, + vendor => { number_column => 'vendornumber', number_range_column => 'vendornumber', }, + part => { number_column => 'partnumber', number_range_column => 'articlenumber', scoping => \&parts_scoping }, + service => { number_column => 'partnumber', number_range_column => 'servicenumber', scoping => \&parts_scoping }, + assembly => { number_column => 'partnumber', number_range_column => 'articlenumber', scoping => \&parts_scoping }, ); sub get_next_trans_number { diff --git a/SL/DB/Part.pm b/SL/DB/Part.pm index fd55e0207..79ef2a482 100644 --- a/SL/DB/Part.pm +++ b/SL/DB/Part.pm @@ -9,6 +9,7 @@ use SL::DBUtils; use SL::DB::MetaSetup::Part; use SL::DB::Manager::Part; use SL::DB::Chart; +use SL::DB::Helper::TransNumberGenerator; __PACKAGE__->meta->add_relationships( unit_obj => { @@ -40,6 +41,15 @@ __PACKAGE__->meta->add_relationships( __PACKAGE__->meta->initialize; +__PACKAGE__->before_save('_before_save_set_partnumber'); + +sub _before_save_set_partnumber { + my ($self) = @_; + + $self->create_trans_number if $self->partnumber eq ''; + return 1; +} + sub is_type { my $self = shift; my $type = lc(shift || ''); -- 2.20.1