Consolidation and extended test runs
[kivitendo-erp.git] / SL / DB / Shipto.pm
index 98b7ca1..b8868ab 100644 (file)
@@ -1,14 +1,15 @@
 package SL::DB::Shipto;
 
 use strict;
-use Readonly;
 
 use SL::DB::MetaSetup::Shipto;
+use SL::DB::Manager::Shipto;
+use Rose::DB::Object::Helpers qw(clone_and_reset clone);
 
-Readonly our @SHIPTO_VARIABLES => qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
-                                     shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
+our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact
+                           shiptophone shiptofax shiptoemail shiptodepartment_1 shiptodepartment_2);
 
-__PACKAGE__->meta->make_manager_class;
+__PACKAGE__->meta->initialize;
 
 sub displayable_id {
   my $self = shift;
@@ -20,4 +21,23 @@ sub displayable_id {
   return $text;
 }
 
+sub used {
+  my ($self) = @_;
+
+  return unless $self->shipto_id;
+
+  require SL::DB::Order;
+  require SL::DB::Invoice;
+  require SL::DB::DeliveryOrder;
+
+  return SL::DB::Manager::Order->get_all_count(query => [ shipto_id => $self->shipto_id ])
+      || SL::DB::Manager::Invoice->get_all_count(query => [ shipto_id => $self->shipto_id ])
+      || SL::DB::Manager::DeliveryOrder->get_all_count(query => [ shipto_id => $self->shipto_id ]);
+}
+
+sub detach {
+  $_[0]->trans_id(undef);
+  $_[0];
+}
+
 1;