Artikelstamm: "Erneuert am" aus parts_price_history holen …
authorBernd Bleßmann <bernd@kivitendo-premium.de>
Fri, 26 Feb 2021 17:33:53 +0000 (18:33 +0100)
committerBernd Bleßmann <bernd@kivitendo-premium.de>
Tue, 9 Mar 2021 12:39:16 +0000 (13:39 +0100)
… und in "Preisänderung am" umbenennen.

Das ganze ist mit Rose gelöst und holt die Preise aus parts_price_history.
Das hat den Nachteil, dass im Artikelbericht nicht nach der Preisanpassung
sortiert werden kann und es wahrscheinlich nicht performant ist.

Der aktuelle Trigger für parts.priceupdate funktionierte nicht, und hätte
auch bei jeder Änderung eines Artikels das Datum angepasst. Dafür kann man auch
mtime nehmen.

Todo 1: Spalte priceupdate (und den Trigger) aus parts löschen (und alle
Vorkommen finden).
Todo 2: Query auf SQL umschreiben und soriteren wieder ermöglichen.

Refs #254 (redmine)

SL/DB/Part.pm
SL/IC.pm
bin/mozilla/ic.pl
locale/de/all
locale/en/all
templates/webpages/ic/search.html
templates/webpages/part/_basic_data.html

index e98b0c4..0f85523 100644 (file)
@@ -76,6 +76,12 @@ __PACKAGE__->meta->add_relationships(
     column_map   => { id => 'part_id' },
     manager_args => { with_objects => [ 'shop' ] },
   },
+  last_price_update => {
+    type         => 'one to one',
+    class        => 'SL::DB::PartsPriceHistory',
+    column_map   => { id => 'part_id' },
+    manager_args => { sort_by => 'valid_from DESC', limit => 1 },
+  },
 );
 
 __PACKAGE__->meta->initialize;
index a09d740..5ddf2c8 100644 (file)
--- a/SL/IC.pm
+++ b/SL/IC.pm
@@ -481,7 +481,7 @@ sub all_parts {
 
   my $token_builder = $make_token_builder->(\%joins_needed);
 
-  my @sort_cols    = (@simple_filters, qw(id priceupdate onhand invnumber ordnumber quonumber name serialnumber soldtotal deliverydate insertdate shop));
+  my @sort_cols    = (@simple_filters, qw(id onhand invnumber ordnumber quonumber name serialnumber soldtotal deliverydate insertdate shop));
      $form->{sort} = 'id' unless grep { $form->{"l_$_"} } grep { $form->{sort} eq $_ } @sort_cols; # sort by id if unknown or invisible column
   my $sort_order   = ($form->{revers} ? ' DESC' : ' ASC');
   my $order_clause = " ORDER BY " . $token_builder->($form->{sort}) . ($form->{revers} ? ' DESC' : ' ASC');
@@ -567,7 +567,7 @@ sub all_parts {
       qq|SELECT p.id, p.partnumber, p.description, a.qty AS onhand,
            p.unit, p.notes, p.itime::DATE as insertdate,
            p.sellprice, p.listprice, p.lastcost,
-           p.rop, p.weight, p.priceupdate,
+           p.rop, p.weight,
            p.image, p.drawing, p.microfiche,
            pfac.factor
          FROM parts p
index f00ce08..450d124 100644 (file)
@@ -188,7 +188,7 @@ sub generate_report {
     'ordnumber'          => { 'text' => $locale->text('Order Number'), },
     'partnumber'         => { 'text' => $locale->text('Part Number'), },
     'partsgroup'         => { 'text' => $locale->text('Partsgroup'), },
-    'priceupdate'        => { 'text' => $locale->text('Updated'), },
+    'priceupdate'        => { 'text' => $locale->text('Price updated'), },
     'quonumber'          => { 'text' => $locale->text('Quotation'), },
     'rop'                => { 'text' => $locale->text('ROP'), },
     'sellprice'          => { 'text' => $locale->text('Sell Price'), },
@@ -435,7 +435,7 @@ sub generate_report {
   my $callback         = build_std_url('action=generate_report', grep { $form->{$_} } @hidden_variables);
 
   my @sort_full        = qw(partnumber description onhand soldtotal deliverydate insertdate shop);
-  my @sort_no_revers   = qw(partsgroup priceupdate invnumber ordnumber quonumber name image drawing serialnumber);
+  my @sort_no_revers   = qw(partsgroup invnumber ordnumber quonumber name image drawing serialnumber);
 
   foreach my $col (@sort_full) {
     $column_defs{$col}->{link} = join '&', $callback, "sort=$col", map { "$_=" . E($form->{$_}) } qw(revers lastsort);
@@ -582,6 +582,9 @@ sub generate_report {
     $row->{type_and_classific}{data} = SL::Presenter::Part::type_abbreviation($ref->{part_type}).
                                        SL::Presenter::Part::classification_abbreviation($ref->{classification_id});
 
+    # last price update
+    $row->{priceupdate}{data} = SL::DB::Part->new(id => $ref->{id})->load->last_price_update->valid_from->to_kivitendo;
+
     $report->add_data($row);
 
     my $next_ref = $form->{parts}[$idx + 1];
index ef2994b..3f16ec3 100755 (executable)
@@ -2501,6 +2501,7 @@ $self->{texts} = {
   'Price sources deactivated in this client' => 'Preisquellen die in diesem Mandanten deaktiviert sind',
   'Price type'                  => 'Preistyp',
   'Price type explanation'      => 'Preistyp Erklärung',
+  'Price updated'               => 'Preisänderung am',
   'Pricegroup'                  => 'Preisgruppe',
   'Pricegroups'                 => 'Preisgruppen',
   'Prices'                      => 'Preise',
index d79401c..f9d1c2c 100644 (file)
@@ -2501,6 +2501,7 @@ $self->{texts} = {
   'Price sources deactivated in this client' => '',
   'Price type'                  => '',
   'Price type explanation'      => '',
+  'Price updated'               => '',
   'Pricegroup'                  => '',
   'Pricegroups'                 => '',
   'Prices'                      => '',
index 42ec5fb..91f665c 100644 (file)
          </tr>
 
          <tr>
-          <td>[%- L.checkbox_tag('l_priceupdate', label=LxERP.t8('Updated'), value='Y') %]</td>
+          <td>[%- L.checkbox_tag('l_priceupdate', label=LxERP.t8('Price updated'), value='Y') %]</td>
           <td>[%- L.checkbox_tag('l_deliverydate', label=LxERP.t8('Delivery Date'), value='Y') %]</td>
           <td>[%- L.checkbox_tag('l_rop', label=LxERP.t8('ROP'), value='Y') %]</td>
           <td>[%- L.checkbox_tag('l_weight', label=LxERP.t8('Weight'), value='Y') %]</td>
index 9e7fcee..90d5eec 100644 (file)
@@ -84,9 +84,9 @@
         <td>
          <table id="ic5">
           <tr>
-           <th align="right" nowrap="true">[% 'Updated' | $T8 %]</th>
+           <th align="right" nowrap="true">[% 'Price updated' | $T8 %]</th>
            <td>
-           [% SELF.part.priceupdate.to_kivitendo | html %]
+           [% SELF.part.last_price_update.valid_from.to_kivitendo | html %]
            </td>
           </tr>