-
Notifications
You must be signed in to change notification settings - Fork 154
/
animal.rb
140 lines (130 loc) · 5.11 KB
/
animal.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# = Informations
#
# == License
#
# Ekylibre - Simple agricultural ERP
# Copyright (C) 2008-2009 Brice Texier, Thibaud Merigon
# Copyright (C) 2010-2012 Brice Texier
# Copyright (C) 2012-2017 Brice Texier, David Joulin
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# == Table: products
#
# address_id :integer
# birth_date_completeness :string
# birth_farm_number :string
# born_at :datetime
# category_id :integer not null
# codes :jsonb
# country :string
# created_at :datetime not null
# creator_id :integer
# custom_fields :jsonb
# dead_at :datetime
# default_storage_id :integer
# derivative_of :string
# description :text
# end_of_life_reason :string
# father_country :string
# father_identification_number :string
# father_variety :string
# filiation_status :string
# first_calving_on :datetime
# fixed_asset_id :integer
# id :integer not null, primary key
# identification_number :string
# initial_born_at :datetime
# initial_container_id :integer
# initial_dead_at :datetime
# initial_enjoyer_id :integer
# initial_father_id :integer
# initial_geolocation :geometry({:srid=>4326, :type=>"st_point"})
# initial_mother_id :integer
# initial_movement_id :integer
# initial_owner_id :integer
# initial_population :decimal(19, 4) default(0.0)
# initial_shape :geometry({:srid=>4326, :type=>"multi_polygon"})
# lock_version :integer default(0), not null
# member_variant_id :integer
# mother_country :string
# mother_identification_number :string
# mother_variety :string
# name :string not null
# nature_id :integer not null
# number :string not null
# origin_country :string
# origin_identification_number :string
# originator_id :integer
# parent_id :integer
# person_id :integer
# picture_content_type :string
# picture_file_name :string
# picture_file_size :integer
# picture_updated_at :datetime
# team_id :integer
# tracking_id :integer
# type :string
# updated_at :datetime not null
# updater_id :integer
# uuid :uuid
# variant_id :integer not null
# variety :string not null
# work_number :string
#
class Animal < Bioproduct
refers_to :variety, scope: :animal
belongs_to :initial_father, class_name: 'Animal'
belongs_to :initial_mother, class_name: 'Animal'
belongs_to :originator, class_name: 'SynchronizationOperation'
validates :identification_number, presence: true
validates :identification_number, uniqueness: true
scope :fathers, -> { indicate(sex: 'male', reproductor: true).order(:name) }
scope :mothers, -> { indicate(sex: 'female', reproductor: true).order(:name) }
enumerize :birth_date_completeness, in: %i[year month_year full_date]
enumerize :filiation_status, in: %i[unknown certified uncertified]
enumerize :end_of_life_reason, in: %i[death slaughter cutting_up calculated_date]
def status
if dead_at?
:stop
elsif indicators_list.include? :healthy
(healthy ? :go : :caution)
else
:go
end
end
# Compute daily nitrogen production based on indicator of product
# The indicator is the reference for now.
def daily_nitrogen_production(at = nil)
at ||= Time.zone.now
quantity = 0.in_kilogram_per_day
if has_indicator?(:daily_nitrogen_production)
quantity = daily_nitrogen_production(at: at)
end
quantity
end
def sex_text
"nomenclatures.sexes.items.#{sex}".t
end
def variety_text
"nomenclatures.varieties.items.#{variety}".t
end
def best_activity_production(options = {})
at = options[:at] || Time.zone.now
ActivityProduction.where(support: groups_at(at)).at(at).first || super
end
def synchronization_operations
SynchronizationOperation.of_product(self)
end
end