Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/models/report_template.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'yaml'

class ReportTemplate < ActiveRecord::Base
belongs_to :ac_filter_def

Expand All @@ -13,7 +15,11 @@ def serialization_params=(value)

def serialization_params
value = read_attribute :serialization_params
value.nil? ? {} : Marshal.load(value)
begin
value.nil? ? {} : Marshal.load(value)
rescue TypeError

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tratamento em relação a nulidade do valor

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aqui você está abafando uma exceção. Isto não é uma boa prática pois apesar de resolver algum caso específico que você precisou resolver poderá abafar exceções que deveriam aparecer para o programador. Isto pode atrapalhar em debugs.
Poderia alterar e somente abafar nos casos em que necessita?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O commit original somente descreve: tratamento de valor nulo.
Se desejar posso remover esta alteração e testar um por um dos relatórios.

No na época(2013) não foi documentado não sei se a alteração
pode tratar situação específicas ou influenciadas pela combinação de filtros.

Se eu remover apesar dos testes locais ainda haverá a possibilidade do erro ocorrer no cliente. Neste caso seria interessante manter esta alteração?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como boa prática peço que remova a alteração. Se for necessário de fato o ideal é criar em seu projeto uma subclasse desta classe que faça isto e a use somente no seu projeto. Como se trata de uma biblioteca usada em vários projetos não temos como aceitar esta mudança na classe comum.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hum. Entendi.
Neste caso irei refatorar e em breve subo as alterações.

No entanto devido a rotina interna irei alinhar um prazo.
Não conseguirei fazer neste momento.

Portanto o pull request vai demorar um tempo para ser realizado novamente.


end
end

end
2 changes: 1 addition & 1 deletion lib/ac_filters_utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def apply_ac_filter(parsed_filter, system_params)
if filter_def.has_sql_query?
sql_to_execute = ActiveRecord::Base.send(:sanitize_sql_array, conditions)
r = []
ActiveRecord::Base.connection.instance_exec(sql_to_execute).each(:as => :hash) {|i| r << i}
ActiveRecord::Base.connection.instance_exec(sql_to_execute).each(as :hash) {|i| r << i}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alteração sem relação direta com o commit portada do nosso fork.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O que faz esta alteração?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Só troca de sintaxe mesmo. Posso remover esta alteração.
Trouxe dos commits legados.

else
find_params[:select] = filter_def.select_sql.to_s unless filter_def.select_sql.nil?
find_params[:order] = filter_def.order_sql.to_s unless filter_def.order_sql.nil?
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddExcluirToReportTemplate < ActiveRecord::Migration
def self.up
add_column :report_templates, :excluir, :boolean
end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Migration relativa a coluna que agora controla a exclusão.

def self.down
remove_column :report_templates, :excluir
end
end

32 changes: 24 additions & 8 deletions lib/prawn_report_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'yaml'


ReportTemplate.delete_all
ReportTemplate.update_all({:ac_filter_def_id => nil, :excluir => true})
AcFilterOption.delete_all
AcFilter.delete_all
AcFilterDef.delete_all
Expand All @@ -20,14 +20,30 @@
Dir.glob("#{Rails.root}/db/reports/*.yml").each do |f|
puts "Parsing file: #{f}"
params = YAML::load(File.open(f, 'r'))
if params["filter_name"]
f = AcFilterDef.find_by_name(params.delete("filter_name"))
if f
params["ac_filter_def_id"] = f.id
r = ReportTemplate.find_by_name(params["name"])

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ajustes para o novo comportamento relativo a "exclusão".

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Favor detalhar esta lógica de exclusão. O que ela resolve? Por que foi implementada?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alterado para atualizar ao invés de excluir. Para não perder relação entre os relatórios e os laboratórios. Só exibir relatórios para laboratórios específicos.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Como se trata de uma implementação específica para o seu projeto peço que realize em classes fora do contexto da biblioteca, no seu projeto por exemplo. Ou então que insira este comportamento porém de forma configurável e mantendo o padrão como era anteriormente.

if r.nil?
if params["filter_name"]
f = AcFilterDef.find_by_name(params.delete("filter_name"))
if f
params["ac_filter_def_id"] = f.id
end
end
params["excluir"] = false
ReportTemplate.create(params)
puts "Criado relatório: " + params["name"]
else
if params["filter_name"]
f = AcFilterDef.find_by_name(params.delete("filter_name"))
if f
params["ac_filter_def_id"] = f.id
end
end
params["excluir"] = false
r.update_attributes(params)
puts "Atualizado relatório: " + params["name"]
end
end
ReportTemplate.create(params)
puts "Criado relatório: " + params["name"]
end
puts "FIM"
ReportTemplate.destroy_all(:excluir => true)
puts "finishing, closing, and going home"

1 change: 1 addition & 0 deletions lib/report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def second_pass
def run_totals(data_row)
@running_totals.each do |rt|
vl = get_raw_field_value(data_row, rt)
vl = (vl.is_a? (String) ? vl.to_f : vl)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gerava problemas com alguns tipos de dados do Mysql.
De acordo com a query e o tipo retornado.

Este ajuste evitou muitos problemas com médias e suas totalizações.

@totals[rt] = (@totals[rt] || 0) + (vl == '' ? 0 : vl)
@group_totals[rt] = (@group_totals[rt] || 0) + (vl == '' ? 0 : vl)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/report_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def line_break(size = TEXT_SIZE)
def format(value, formatter, options = {})
if !value.nil? && value != ''
if (formatter == :currency)
value = value.round(2)
value = value.round(2) rescue sprintf('%.2f', value).to_f

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gera problema com versões do framework mais antigas como no nossa caso.
Um simples rescue resolve o problema mantendo compatibilidade com Ruby antigo.

if value < 0
'-'+((value.to_i*-1).to_s.reverse.gsub(/...(?=.)/,'\&.').reverse) + ',' + ('%02d' % ((value.abs * 100).round % 100))
else
Expand Down
9 changes: 5 additions & 4 deletions prawn_report.gemspec
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Gem::Specification.new do |s|
s.name = %q{prawn_report}
s.version = "1.9.17"
s.date = %q{2015-09-14}
s.authors = ["Ricardo Acras" "Egon Hilgenstieler" "Juliano Andrade" "Vinicius Cubas Brand"]
s.email = %q{ricardo@acras.com.br julianoch@gmail.com egon@acras.com.br viniciuscb@gmail.com}
s.version = "1.9.21"
s.date = %q{2016-11-23}
s.authors = ["Ricardo Acras", "Egon Hilgenstieler", "Juliano Andrade", "Vinicius Cubas Brand", "Wellington Torrejais da Silva"]

@hotsoft-desenv2 hotsoft-desenv2 Nov 24, 2016

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array de emails não estava separado por ","

Agora segue conforme a documentação.

s.email = 'ricardo@acras.com.br'
s.email = %q{ricardo@acras.com.br julianoch@gmail.com egon@acras.com.br viniciuscb@gmail.com wtds.trabalho@gmail.com desenv2@labplus.com.br}
s.summary = %q{Prawn Report makes it easy to create PDF reports.}
s.homepage = %q{http://www.acras.com.br/}
s.description = %q{Prawn report is a class repository wich uses prawn gem capabilities to generate PDF documents in order to make it easy to create real life reports.}
Expand Down
2 changes: 1 addition & 1 deletion repo/reports/listing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
module PrawnReport
class Listing < Report

#alias :super_new_page :new_page
alias :super_new_page :new_page

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supre uso do super_new_page em alguns relatórios.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Não entendi o objetivo desta alteração.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

É utilizado em alguns de nossos relatórios.
Alteração realizada para evitar problema com os relatórios que utilizam este alias.
Conforme o Ticket citado acima.


def initialize(report_params = {})
super(report_params)
Expand Down
15 changes: 7 additions & 8 deletions repo/reports/simple_listing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def initialize(report_params = {})
:groups_running => false}
end

def new_page(print_titles = true)
super(print_titles)
draw_group_header if grouped? and @report_params[:group][:header_reprint_new_page] and !last_group_summary?
if print_titles
draw_column_titles unless (!draw_group_column_titles? && !@printing_internal) || last_group_summary?
end
end

protected

Expand Down Expand Up @@ -106,14 +113,6 @@ def last_group_summary?
@data_end
end

def new_page(print_titles = true)
super(print_titles)
draw_group_header if grouped? and @report_params[:group][:header_reprint_new_page] and !last_group_summary?
if print_titles
draw_column_titles unless (!draw_group_column_titles? && !@printing_internal) || last_group_summary?
end
end

def before_draw_lines
super
draw_column_titles unless draw_group_column_titles?
Expand Down