cirandas.net

commit c1fee0fd159a90618f451967438ee3cb8eaf7161

Author: Hugo Melo <hugo@riseup.net>

Merge branch 'master' of https://github.com/samasti/noosfero

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/plugins/orders/lib/orders_plugin/report.rb b/plugins/orders/lib/orders_plugin/report.rb
index 36d0b3efec5405baf7db44f88a162e77de026dd0..b511bc0ee081bac277dff78390a154e96e52f039 100644
--- a/plugins/orders/lib/orders_plugin/report.rb
+++ b/plugins/orders/lib/orders_plugin/report.rb
@@ -194,7 +194,7 @@         sheet.add_row [order.code, order.consumer_data[:name], '',order.consumer_data[:contact_phone],'',order.consumer_data[:email],''], style: default
         ["B#{sbs}:C#{sbs}", "D#{sbs}:E#{sbs}", "F#{sbs}:G#{sbs}"].each{ |c| sheet.merge_cells c }
 
         sbs += 1
-        sheet.add_row [t('lib.report.hub'), t('lib.report.payment_method'), t('lib.report.delivery_option'), '','',t('lib.report.created'), t('lib.report.modified')],
+        sheet.add_row [t('lib.report.payment_method'), t('lib.report.hub'), t('lib.report.delivery_option'), '','',t('lib.report.created'), t('lib.report.modified')],
           style: bluecell
         ["D#{sbs}:E#{sbs}"].each{ |c| sheet.merge_cells c }
         # sp = index of the start of the products list / ep = index of the end of the products list
@@ -208,11 +208,11 @@           payment_method = order.payment_data[:method]
           payment_method = payment_method.nil? ? '' : t("payments_plugin.models.payment_methods."+payment_method)
         end
 
-        sheet.add_row [order.suppliers_consumer&.hub_name, payment_method, order.supplier_delivery_data[:name], '','',order.created_at, order.updated_at],
+        sheet.add_row [payment_method, order.suppliers_consumer&.hub_name, order.supplier_delivery_data[:name], '','',order.created_at, order.updated_at],
           style: [default, default, default, default, default, date, date]
         sbs += 1
         sheet.add_row [t('lib.report.product_cod'), t('lib.report.supplier'), t('lib.report.product_name'),
-                       t('lib.report.qty_ordered'),t('lib.report.un'),t('lib.report.price_un'), t('lib.report.value')], style: greencell
+                       t('lib.report.qty_ordered'),t('lib.report.unit'),t('lib.report.price_un'), t('lib.report.value')], style: greencell
         ["D#{sbs}:E#{sbs}"].each{ |c| sheet.merge_cells c }
 
         sbe = sp
@@ -245,8 +245,9 @@           sum += formula_value
         end # closes order.items.each
 
         sum = CurrencyFields.number_as_currency_number(sum)
-        sheet.add_row ['','','','',t('lib.report.total_value'),"=SUM(G#{sp}:G#{ep})", ''], style: [default]*4+[bluecell,currency, default],
-          formula_values: [nil,nil,nil,nil,nil,sum, nil]
+        formula = if sp <= ep then "=SUM(G#{sp}:G#{ep})" else "=0" end
+        sheet.add_row ['','','','','',t('lib.report.total_value'),formula], style: [default]*5+[bluecell,currency],
+          formula_values: [nil,nil,nil,nil,nil,nil, sum]
 
         sheet.add_row [""]
         sbs = sbe + 2




diff --git a/plugins/orders/locales/pt-BR.yml b/plugins/orders/locales/pt-BR.yml
index 242f62d4923ce88f9a4c546b15c8d25556156dc5..efc0e035bc571084a07b99a19f8487de0aba2561 100644
--- a/plugins/orders/locales/pt-BR.yml
+++ b/plugins/orders/locales/pt-BR.yml
@@ -90,6 +90,7 @@         total_selled_value: "Valor total vendido"
         total_price_without_margin: "Valor total sem a margem"
         total_value: "total pago"
         un: un.
+        unit: unidade
         value: Valor
         value_parcel: "Valor usando estoque"
         phone: 'Telefone'




diff --git a/plugins/orders/models/orders_plugin/item.rb b/plugins/orders/models/orders_plugin/item.rb
index 546d4705b6e5a4be7293c96aa76621b919d41ffa..1f6faee11331785bc8a952c98a832aaf5df5c4cf 100644
--- a/plugins/orders/models/orders_plugin/item.rb
+++ b/plugins/orders/models/orders_plugin/item.rb
@@ -277,7 +277,7 @@     end
 
     # Set flags according to past/future data
     # Present flags are used as classes
-    statuses_data.each.with_index do |(status, status_data), i|
+    statuses_data.each.with_index do |(_status, status_data), i|
       prev_status_data = statuses_data[statuses[i-1]] unless i.zero?
 
       if prev_status_data
@@ -295,7 +295,7 @@       end
     end
 
     # reverse_each is necessary to set overwritten with intermediate not_modified
-    statuses_data.reverse_each.with_index do |(status, status_data), i|
+    statuses_data.reverse_each.with_index do |(_status, status_data), i|
       prev_status_data = statuses_data[statuses[-i-1]]
       if status_data[:not_modified] or
           (prev_status_data and prev_status_data[:flags][:filled] and status_data[:quantity] != prev_status_data[:quantity])




diff --git a/plugins/orders/public/javascripts/views/item-quantity-price.tag.slim b/plugins/orders/public/javascripts/views/item-quantity-price.tag.slim
index 1d7fb7cf8f40ca535e3926d0d181a436821a02c1..afb02c8ea1f2326250296e4f83c2f68eee72396b 100644
--- a/plugins/orders/public/javascripts/views/item-quantity-price.tag.slim
+++ b/plugins/orders/public/javascripts/views/item-quantity-price.tag.slim
@@ -79,7 +79,7 @@           }
         }
         var orderTag = this.parent.parent
         orderTag.updateOrder(order)
-        if (order.errors.length > 0)
+        if (order.errors && order.errors.length > 0)
           display_notice(this.t('views.item._edit.error'))
         else
           display_notice(this.t('views.item._edit.saved'))