Refactoring: Code für OrderItem-Manager von DB-Datei in eigene Manager-Datei ausgelagert
authorMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 3 Sep 2012 07:29:22 +0000 (09:29 +0200)
committerMoritz Bunkus <m.bunkus@linet-services.de>
Mon, 3 Sep 2012 07:29:22 +0000 (09:29 +0200)
SL/DB/Manager/OrderItem.pm [new file with mode: 0644]
SL/DB/OrderItem.pm

diff --git a/SL/DB/Manager/OrderItem.pm b/SL/DB/Manager/OrderItem.pm
new file mode 100644 (file)
index 0000000..000369e
--- /dev/null
@@ -0,0 +1,36 @@
+package SL::DB::Manager::OrderItem;
+
+use strict;
+
+use SL::DB::Helper::Manager;
+use base qw(SL::DB::Helper::Manager);
+
+use SL::DB::Helper::Paginated;
+use SL::DB::Helper::Sorted;
+
+sub object_class { 'SL::DB::OrderItem' }
+
+__PACKAGE__->make_manager_methods;
+
+sub _sort_spec {
+  return ( columns => { delivery_date => [ 'deliverydate',        ],
+                        description   => [ 'lower(orderitems.description)',  ],
+                        partnumber    => [ 'part.partnumber',     ],
+                        qty           => [ 'qty'                  ],
+                        ordnumber     => [ 'order.ordnumber'      ],
+                        customer      => [ 'lower(customer.name)', ],
+                        position      => [ 'trans_id', 'runningnumber' ],
+                        reqdate       => [ 'COALESCE(orderitems.reqdate, order.reqdate)' ],
+                        orddate       => [ 'order.orddate' ],
+                        sellprice     => [ 'sellprice' ],
+                        discount      => [ 'discount' ],
+                        transdate     => [ 'transdate::date', 'order.reqdate' ],
+                      },
+           default => [ 'position', 1 ],
+           nulls   => { }
+         );
+}
+
+sub default_objects_per_page { 40 }
+
+1;
index f24abca..3b868d3 100644 (file)
@@ -6,6 +6,7 @@ use List::Util qw(sum);
 use SL::AM;
 
 use SL::DB::MetaSetup::OrderItem;
+use SL::DB::Manager::OrderItem;
 use SL::DB::Helper::CustomVariables (
   sub_module  => 'orderitems',
   cvars_alias => 1,
@@ -37,9 +38,6 @@ __PACKAGE__->meta->add_relationship(
   },
 );
 
-# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
-__PACKAGE__->meta->make_manager_class;
-
 __PACKAGE__->meta->initialize;
 
 sub is_price_update_available {
@@ -56,30 +54,4 @@ sub shipped_qty {
   return sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi);
 }
 
-package SL::DB::Manager::OrderItem;
-
-use SL::DB::Helper::Paginated;
-use SL::DB::Helper::Sorted;
-
-sub _sort_spec {
-  return ( columns => { delivery_date => [ 'deliverydate',        ],
-                        description   => [ 'lower(orderitems.description)',  ],
-                        partnumber    => [ 'part.partnumber',     ],
-                        qty           => [ 'qty'                  ],
-                        ordnumber     => [ 'order.ordnumber'      ],
-                        customer      => [ 'lower(customer.name)', ],
-                        position      => [ 'trans_id', 'runningnumber' ],
-                        reqdate       => [ 'COALESCE(orderitems.reqdate, order.reqdate)' ],
-                        orddate       => [ 'order.orddate' ],
-                        sellprice     => [ 'sellprice' ],
-                        discount      => [ 'discount' ],
-                        transdate     => [ 'transdate::date', 'order.reqdate' ],
-                      },
-           default => [ 'position', 1 ],
-           nulls   => { }
-         );
-}
-
-sub default_objects_per_page { 40 }
-
 1;