Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
simaob committed Nov 1, 2016
2 parents 72e9314 + 4fd135c commit d6fc2ce
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/views/analysis-total_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

var total = (!!analysis) ? this.formatNumbers(analysis[this.model.get('type')]) : null;

var totalCompare = (!!analysisCompare) ? this.formatNumbers(analysisCompare[this.modelCompare.get('type')]) : null;
var totalCompare = (!!analysisCompare && analysisCompare.analysis_changed) ? this.formatNumbers(analysisCompare[this.modelCompare.get('type')]) : null;

var subtraction = (!!analysis) && (!!analysisCompare) ? analysisCompare[this.modelCompare.get('type')] - analysis[this.model.get('type')] : null;

Expand Down
25 changes: 12 additions & 13 deletions app/models/analysis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -350,20 +350,19 @@ def display_crop
crop.gsub("-", " ").titleize
end

def new_record_and_blank_amount?(attributes)
!(attributes["amount"].present? && attributes["amount"].to_f > 0.0) && (new_record? || !attributes["id"])
end

def second_group?
paddy_rice? || crop_management_practices.present? ||
(lime_amount.present? && lime_amount > 0.0) ||
(dolomite_amount.present? && dolomite_amount > 0.0) ||
(agrochemical_amount.present? && agrochemical_amount > 0.0)
def any_change?
# ignore yield_unit
# make sure that yield has changed and is not just converted from kg to tonne
changes.reject{|k,v| k == "yield_unit" || (k == "yield" && v[0]*0.001 == v[1])}.present? ||
fertilizers.any?{ |a| a.changed? } ||
manures.any?{ |a| a.changed? } ||
fuels.any?{ |a| a.changed? } ||
transportation_fuels.any?{ |a| a.changed? } ||
irrigation_fuels.any?{ |a| a.changed? } ||
nutrient_managements.any?{ |a| a.changed? }
end

def third_group?
additions.where(category: [Category::FUEL, Category::TRANSPORTATION_FUEL,
Category::IRRIGATION_FUEL]).
where("amount > 0.0").any?
def new_record_and_blank_amount?(attributes)
!(attributes["amount"].present? && attributes["amount"].to_f > 0.0) && (new_record? || !attributes["id"])
end
end
3 changes: 2 additions & 1 deletion app/serializers/analysis_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ def analysis
{
total: total.to_f,
total_per_yield: (total/per_yield).to_f,
emissions_by_source: emissions_by_source
emissions_by_source: emissions_by_source,
analysis_changed: object.any_change?
}
end
end
7 changes: 4 additions & 3 deletions app/views/analyses/print.js.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
$(function() {
if($('.subtraction').length > 0) {
<% if @analysis.any_change? %>
$('#future-practices').show();
$('#future-practices').removeClass('-is-not-printable');
$('#print-changed').html("<%= escape_javascript(render('printable_inputs', analysis: @analysis)) %>");
} else {
<% else %>
$('#future-practices').hide();
$('#future-practices').addClass('-is-not-printable');
}
<% end %>
window.print();
});

0 comments on commit d6fc2ce

Please sign in to comment.