SL::DB::Invoice->new_from: auch Leistungsdatum (tax_point) übernehmen
[kivitendo-erp.git] / SL / DB / Part.pm
index 9eb76df..e98b0c4 100644 (file)
@@ -32,7 +32,7 @@ __PACKAGE__->meta->add_relationships(
   assemblies                     => {
     type         => 'one to many',
     class        => 'SL::DB::Assembly',
-    manager_args => { sort_by => 'position, oid' },
+    manager_args => { sort_by => 'position' },
     column_map   => { id => 'id' },
   },
   prices         => {
@@ -61,6 +61,7 @@ __PACKAGE__->meta->add_relationships(
     type         => 'one to many',
     class        => 'SL::DB::AssortmentItem',
     column_map   => { id => 'assortment_id' },
+    manager_args => { sort_by => 'position' },
   },
   history_entries   => {
     type            => 'one to many',
@@ -80,7 +81,8 @@ __PACKAGE__->meta->add_relationships(
 __PACKAGE__->meta->initialize;
 
 __PACKAGE__->attr_html('notes');
-__PACKAGE__->attr_sorted({ unsorted => 'makemodels', position => 'sortorder' });
+__PACKAGE__->attr_sorted({ unsorted => 'makemodels',     position => 'sortorder' });
+__PACKAGE__->attr_sorted({ unsorted => 'customerprices', position => 'sortorder' });
 
 __PACKAGE__->before_save('_before_save_set_partnumber');
 
@@ -373,7 +375,7 @@ sub get_simple_stock_sql {
             LEFT JOIN warehouse w ON (i.warehouse_id = w.id)
             LEFT JOIN bin b       ON (i.bin_id       = b.id)
       WHERE parts_id = ?
-   GROUP BY w.description, b.description, p.unit, i.parts_id
+   GROUP BY w.description, w.sortkey, b.description, p.unit, i.parts_id
      HAVING SUM(qty) != 0
      WINDOW pt AS (PARTITION BY i.parts_id    ORDER BY w.sortkey, b.description, p.unit),
             wh AS (PARTITION by w.description ORDER BY w.sortkey, b.description, p.unit)