Skip to content

Commit

Permalink
Fixes bad validations due to bad conflict resolutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Brice TEXIER committed Feb 26, 2015
1 parent 0d2d364 commit f5b67ad
Show file tree
Hide file tree
Showing 16 changed files with 637 additions and 682 deletions.
1 change: 0 additions & 1 deletion Gemfile
Expand Up @@ -136,7 +136,6 @@ gem 'agric'
# Idele webservices
gem 'mechanize'
gem 'savon', '~> 2.5.1'
#gem 'savon', github: 'savonrb/savon'

group :development do
gem 'quiet_assets'
Expand Down
10 changes: 0 additions & 10 deletions app/models/crumb.rb
Expand Up @@ -40,24 +40,14 @@
#

class Crumb < Ekylibre::Record::Base
#[VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates_datetime :read_at, allow_blank: true, on_or_after: Time.new(1, 1, 1, 0, 0, 0, '+00:00')
validates_numericality_of :accuracy, allow_nil: true
validates_presence_of :accuracy, :device_uid, :geolocation, :nature, :read_at
#]VALIDATORS]
enumerize :nature, in: [:point, :start, :stop, :pause, :resume, :scan, :hard_start, :hard_stop], predicates: true
belongs_to :user
belongs_to :intervention_cast
has_one :worker, through: :user
#[VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates_datetime :read_at, allow_blank: true, on_or_after: Time.new(1, 1, 1, 0, 0, 0, '+00:00')
validates_numericality_of :accuracy, allow_nil: true
# <<<<<<< HEAD
validates_length_of :device_uid, :nature, allow_nil: true, maximum: 255
validates_presence_of :accuracy, :device_uid, :geolocation, :nature, :read_at
# =======
validates_presence_of :accuracy, :device_uid, :nature, :read_at
# >>>>>>> Replaces production_support_markers with production_budgets
#]VALIDATORS]
serialize :metadata, Hash

Expand Down
9 changes: 0 additions & 9 deletions app/models/production.rb
Expand Up @@ -41,10 +41,6 @@
# working_unit :string
#
class Production < Ekylibre::Record::Base
#[VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates_datetime :started_at, :stopped_at, allow_blank: true, on_or_after: Time.new(1, 1, 1, 0, 0, 0, '+00:00')
validates_presence_of :activity, :campaign, :name, :state
#]VALIDATORS]
enumerize :state, in: [:draft, :validated], default: :draft
enumerize :working_unit, in: Nomen::Units.all
enumerize :working_indicator, in: Nomen::Indicators.where(datatype: :measure).map(&:name) + [:population, :working_duration]
Expand All @@ -69,11 +65,6 @@ class Production < Ekylibre::Record::Base

#[VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates_datetime :started_at, :stopped_at, allow_blank: true, on_or_after: Time.new(1, 1, 1, 0, 0, 0, '+00:00')
# <<<<<<< HEAD
validates_length_of :name, :state, :working_indicator, :working_unit, allow_nil: true, maximum: 255
validates_inclusion_of :static_support, in: [true, false]
# =======
# >>>>>>> Replaces production_support_markers with production_budgets
validates_presence_of :activity, :campaign, :name, :state
#]VALIDATORS]
# validates_presence_of :product_nature, if: :activity_main?
Expand Down
9 changes: 0 additions & 9 deletions app/models/production_budget.rb
Expand Up @@ -43,10 +43,6 @@
#

class ProductionBudget < Ekylibre::Record::Base
#[VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates_numericality_of :amount, :quantity, :unit_amount, :unit_population, allow_nil: true
validates_presence_of :computation_method, :currency, :direction, :production, :unit_currency
#]VALIDATORS]
# enumerize :currency, in: Nomen::Currencies.all, default: Preference[:currency]
enumerize :direction, in: [:revenue, :expense], predicates: true
enumerize :computation_method, in: [:per_production, :per_production_support, :per_working_unit], default: :per_working_unit, predicates: true
Expand All @@ -58,13 +54,8 @@ class ProductionBudget < Ekylibre::Record::Base
has_many :supports, through: :production, class_name: 'ProductionSupport'

#[VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
# <<<<<<< HEAD:app/models/budget.rb
validates_numericality_of :global_amount, :global_quantity, :unit_amount, allow_nil: true
validates_length_of :computation_method, :currency, :direction, :name, :working_indicator, :working_unit, allow_nil: true, maximum: 255
# =======
validates_numericality_of :amount, :quantity, :unit_amount, :unit_population, allow_nil: true
validates_presence_of :computation_method, :currency, :direction, :production, :unit_currency
# >>>>>>> Replaces production_support_markers with production_budgets:app/models/production_budget.rb
#]VALIDATORS]
validates_presence_of :variant, :production

Expand Down
12 changes: 12 additions & 0 deletions lib/exchanges/exchange.rb
Expand Up @@ -46,6 +46,18 @@ def reset!
@cursor = 0
end

def debug?
ENV["DEBUG"].to_i > 0
end

def log(*args)
puts(*args) if debug?
end

def notice(*args)
puts(*args)
end

def tmp_dir(*subdirs)
number = (1000 * Time.now.to_f).to_i.to_s(36) + 3.times.collect{ rand(1679616) }.sum.to_s(36)
dir = Rails.root.join("tmp", "exchanges", number, *subdirs)
Expand Down
2 changes: 1 addition & 1 deletion lib/exchanges/exchangers/ekylibre/budgets.rb
Expand Up @@ -82,7 +82,7 @@
if Nomen::ProductNatureVariants[r.item_code_variant]
item_variant = ProductNatureVariant.import_from_nomenclature(r.item_code_variant)
else
puts "Cannot import budget for: #{r.item_code_variant}".red
w.notice "Cannot import budget for: #{r.item_code_variant}".red
next
end
end
Expand Down
3 changes: 0 additions & 3 deletions lib/exchanges/exchangers/ekylibre/cultivable_zones.rb
Expand Up @@ -51,9 +51,6 @@
end
end
end
#if zc_products_around = zone_shape.actors_matching(nature: CultivableZone)
#puts zc_products_around.inspect.red
#end
end
end

Expand Down
65 changes: 32 additions & 33 deletions lib/exchanges/exchangers/ekylibre/interventions.rb
Expand Up @@ -124,21 +124,20 @@
duration = (duration_in_seconds * (cultivable_zone.shape_area.to_d / production_supports_area.to_d).to_d).round(2)


puts "----------- #{r.intervention_number} / #{support.name} -----------".blue
# puts r.product_name.inspect.green
puts " procedure : " + r.procedure_name.inspect.green
puts " started_at : " + intervention_started_at.inspect.yellow if intervention_started_at
puts " global duration : " + duration_in_seconds.inspect.yellow if duration_in_seconds
puts " duration : " + duration.to_f.inspect.yellow if duration
puts " first product : " + first_product.name.inspect.red if first_product
puts " first product quantity : " + r.first_product_input_population.to_s + " " + r.first_product_input_unit_name.to_s.inspect.red if r.first_product_input_population
puts " second product : " + second_product.name.inspect.red if second_product
puts " third product : " + third_product.name.inspect.red if third_product
puts " cultivable_zone : " + cultivable_zone.name.inspect.yellow + " - " + cultivable_zone.work_number.inspect.yellow if cultivable_zone
puts " plant : " + plant.name.inspect.yellow if plant
puts " support : " + support.name.inspect.yellow if support
puts " workers_name : " + workers.pluck(:name).inspect.yellow if workers
puts " equipments_name : " + equipments.pluck(:name).inspect.yellow if equipments
w.log "----------- #{r.intervention_number} / #{support.name} -----------".blue
w.log " procedure : " + r.procedure_name.inspect.green
w.log " started_at : " + intervention_started_at.inspect.yellow if intervention_started_at
w.log " global duration : " + duration_in_seconds.inspect.yellow if duration_in_seconds
w.log " duration : " + duration.to_f.inspect.yellow if duration
w.log " first product : " + first_product.name.inspect.red if first_product
w.log " first product quantity : " + r.first_product_input_population.to_s + " " + r.first_product_input_unit_name.to_s.inspect.red if r.first_product_input_population
w.log " second product : " + second_product.name.inspect.red if second_product
w.log " third product : " + third_product.name.inspect.red if third_product
w.log " cultivable_zone : " + cultivable_zone.name.inspect.yellow + " - " + cultivable_zone.work_number.inspect.yellow if cultivable_zone
w.log " plant : " + plant.name.inspect.yellow if plant
w.log " support : " + support.name.inspect.yellow if support
w.log " workers_name : " + workers.pluck(:name).inspect.yellow if workers
w.log " equipments_name : " + equipments.pluck(:name).inspect.yellow if equipments



Expand Down Expand Up @@ -189,11 +188,11 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
if r.procedure_name == :double_spraying_on_cultivation and plant and first_product and second_product

working_measure = plant.shape_area
puts working_measure.inspect.green
w.log working_measure.inspect.green
first_product_input_population = population_conversion(first_product, r.first_product_input_population, r.first_product_input_unit_name, r.first_product_input_unit_target_dose, working_measure)
puts first_product_input_population.inspect.green
w.log first_product_input_population.inspect.green
second_product_input_population = population_conversion(second_product, r.second_product_input_population, r.second_product_input_unit_name, r.second_product_input_unit_target_dose, working_measure)
puts second_product_input_population.inspect.green
w.log second_product_input_population.inspect.green

# Double spraying on cultivation
intervention = Ekylibre::FirstRun::Booker.force(:double_spraying_on_cultivation, intervention_started_at, (duration / 3600), support: support) do |i|
Expand All @@ -210,11 +209,11 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
elsif r.procedure_name == :double_spraying_on_land_parcel and cultivable_zone and first_product and second_product

working_measure = cultivable_zone.shape_area
puts working_measure.inspect.green
w.log working_measure.inspect.green
first_product_input_population = population_conversion(first_product, r.first_product_input_population, r.first_product_input_unit_name, r.first_product_input_unit_target_dose, working_measure)
puts first_product_input_population.inspect.green
w.log first_product_input_population.inspect.green
second_product_input_population = population_conversion(second_product, r.second_product_input_population, r.second_product_input_unit_name, r.second_product_input_unit_target_dose, working_measure)
puts second_product_input_population.inspect.green
w.log second_product_input_population.inspect.green

# Double spraying on cultivation
intervention = Ekylibre::FirstRun::Booker.force(:double_spraying_on_land_parcel, intervention_started_at, (duration / 3600), support: support) do |i|
Expand All @@ -233,9 +232,9 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
elsif r.procedure_name == :spraying_on_cultivation and plant and first_product

working_measure = plant.shape_area
puts working_measure.inspect.green
w.log working_measure.inspect.green
first_product_input_population = population_conversion(first_product, r.first_product_input_population, r.first_product_input_unit_name, r.first_product_input_unit_target_dose, working_measure)
puts first_product_input_population.inspect.green
w.log first_product_input_population.inspect.green

# Spraying on cultivation
intervention = Ekylibre::FirstRun::Booker.force(:spraying_on_cultivation, intervention_started_at, (duration / 3600), support: support) do |i|
Expand All @@ -250,9 +249,9 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
elsif r.procedure_name == :spraying_on_land_parcel and cultivable_zone and first_product

working_measure = cultivable_zone.shape_area
puts working_measure.inspect.green
w.log working_measure.inspect.green
first_product_input_population = population_conversion(first_product, r.first_product_input_population, r.first_product_input_unit_name, r.first_product_input_unit_target_dose, working_measure)
puts first_product_input_population.inspect.green
w.log first_product_input_population.inspect.green

# Spraying on cultivation
intervention = Ekylibre::FirstRun::Booker.force(:spraying_on_land_parcel, intervention_started_at, (duration / 3600), support: support) do |i|
Expand Down Expand Up @@ -313,9 +312,9 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
elsif r.procedure_name == :organic_fertilizing and cultivable_zone and first_product

working_measure = cultivable_zone.shape_area
puts working_measure.inspect.green
w.log working_measure.inspect.green
first_product_input_population = population_conversion(first_product, r.first_product_input_population, r.first_product_input_unit_name, r.first_product_input_unit_target_dose, working_measure)
puts first_product_input_population.inspect.green
w.log first_product_input_population.inspect.green

# Organic fertilizing
intervention = Ekylibre::FirstRun::Booker.force(:organic_fertilizing, intervention_started_at, (duration / 3600), support: support) do |i|
Expand All @@ -331,9 +330,9 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
elsif r.procedure_name == :mineral_fertilizing and cultivable_zone and first_product

working_measure = cultivable_zone.shape_area
puts working_measure.inspect.green
w.log working_measure.inspect.green
first_product_input_population = population_conversion(first_product, r.first_product_input_population, r.first_product_input_unit_name, r.first_product_input_unit_target_dose, working_measure)
puts first_product_input_population.inspect.green
w.log first_product_input_population.inspect.green

# Organic fertilizing
intervention = Ekylibre::FirstRun::Booker.force(:mineral_fertilizing, intervention_started_at, (duration / 3600), support: support) do |i|
Expand All @@ -353,9 +352,9 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
elsif r.procedure_name == :plastic_mulching and cultivable_zone and first_product

working_measure = cultivable_zone.shape_area
puts working_measure.inspect.green
w.log working_measure.inspect.green
first_product_input_population = population_conversion(first_product, r.first_product_input_population, r.first_product_input_unit_name, r.first_product_input_unit_target_dose, working_measure)
puts first_product_input_population.inspect.green
w.log first_product_input_population.inspect.green

# Plastic mulching
intervention = Ekylibre::FirstRun::Booker.force(:plastic_mulching, intervention_started_at, (duration / 3600), support: support) do |i|
Expand Down Expand Up @@ -384,9 +383,9 @@ def population_conversion(product, population, unit, unit_target_dose, working_a
if intervention
intervention.description = information_import_context + " - N° : " + r.intervention_number.to_s + " - " + support.name
intervention.save!
puts "Intervention n°#{intervention.id} - #{intervention.name} has been created".green
w.log "Intervention n°#{intervention.id} - #{intervention.name} has been created".green
else
puts "Intervention is in a black hole".red
w.log "Intervention is in a black hole".red
end

# for the same intervention session
Expand Down
6 changes: 2 additions & 4 deletions lib/exchanges/exchangers/ekylibre/original_purchase_files.rb
@@ -1,10 +1,9 @@
# Create or updates purchases
Exchanges.add_importer :ekylibre_original_purchase_files do |file, w|

# Unzip file
dir = w.tmp_dir
Zip::File.open(file) do |zile|
#w.count = zile.count
w.count = zile.entries.size
zile.each do |entry|
e = entry.extract(dir.join(entry.name))
# set parameter
Expand All @@ -16,7 +15,6 @@
key = e.time.to_s(:number) + "-" + e.size.to_s + "-" + reference_number

# TODO add a method to detect before importing the same key in order to avoid bad validation on key
# puts " #{key} - #{e.name}".red
# create document
if path and extension and e.name and key
document = Document.create!(key: key, name: e.name, nature: "purchases_original")
Expand All @@ -29,6 +27,6 @@
purchase = Purchase.where(reference_number: reference_number).first
purchase.attachments.create!(document: document) if document and purchase
end
#w.check_point
w.check_point
end
end
4 changes: 2 additions & 2 deletions lib/exchanges/exchangers/ekylibre/settings.rb
Expand Up @@ -35,7 +35,7 @@ def manifest.create_records(records, *args)
if record.save(attributes)
@records[records][identifier.to_s] = record
else
puts "\nError on #{record.inspect.red}"
w.log "\nError on #{record.inspect.red}"
raise ActiveRecord::RecordInvalid, record
end
end
Expand Down Expand Up @@ -156,7 +156,7 @@ def manifest.get_record(records, identifier)
else
attributes[:password] = User.give_password(8, :normal)
unless Rails.env.test?
puts "New password for account #{attributes[:email]}: #{attributes[:password]}"
w.notice "New password for account #{attributes[:email]}: #{attributes[:password]}"
end
end
end
Expand Down

0 comments on commit f5b67ad

Please sign in to comment.