]> wagnertech.de Git - mfinanz.git/blobdiff - SL/DB/Part.pm
Part makemodels relationship nutzt sortorder
[mfinanz.git] / SL / DB / Part.pm
index 09fdc0d9edee603a96db803c752bfd501873a630..7fd35d80ef2e0120c4da93560b6c0b4a7219e907 100644 (file)
@@ -21,6 +21,7 @@ __PACKAGE__->meta->add_relationships(
   assemblies                     => {
     type         => 'one to many',
     class        => 'SL::DB::Assembly',
+    manager_args => { sort_by => 'position, oid' },
     column_map   => { id => 'id' },
   },
   prices         => {
@@ -31,6 +32,7 @@ __PACKAGE__->meta->add_relationships(
   makemodels     => {
     type         => 'one to many',
     class        => 'SL::DB::MakeModel',
+    manager_args => { sort_by => 'sortorder' },
     column_map   => { id => 'parts_id' },
   },
   translations   => {
@@ -246,6 +248,37 @@ sub displayable_name {
   join ' ', grep $_, map $_[0]->$_, qw(partnumber description);
 }
 
+sub clone_and_reset_deep {
+  my ($self) = @_;
+
+  my $clone = $self->clone_and_reset; # resets id and partnumber (primary key and unique constraint)
+  $clone->makemodels(       map { $_->clone_and_reset } @{$self->makemodels});
+  $clone->translations(     map { $_->clone_and_reset } @{$self->translations});
+
+  if ( $self->is_assortment ) {
+    $clone->assortment_items( map { $_->clone } @{$self->assortment_items} );
+      foreach my $ai ( @{ $clone->assortment_items } ) {
+        $ai->assortment_id(undef);
+      };
+  };
+
+  if ( $self->is_assembly ) {
+    $clone->assemblies( map { $_->clone_and_reset } @{$self->assemblies});
+  };
+
+  if ( $self->prices ) {
+    $clone->prices( map { $_->clone } @{$self->prices}); # pricegroup_id gets reset here because it is part of a unique contraint
+    if ( $clone->prices ) {
+      foreach my $price ( @{$clone->prices} ) {
+        $price->id(undef);
+        $price->parts_id(undef);
+      };
+    };
+  };
+
+  return $clone;
+}
+
 1;
 
 __END__