Artikelnummernvergabe im TransNumberGenerator
authorMoritz Bunkus <m.bunkus@linet-services.de>
Wed, 2 Mar 2011 13:20:47 +0000 (14:20 +0100)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Thu, 16 Jun 2011 06:44:35 +0000 (08:44 +0200)
SL/DB/Helper/TransNumberGenerator.pm
SL/DB/Part.pm

index 3020029..f7c7793 100644 (file)
@@ -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 {
index fd55e02..79ef2a4 100644 (file)
@@ -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 || '');