Class: ProductGroup

Inherits:
Product show all
Defined in:
app/models/product_group.rb

Overview

Informations

License

Ekylibre - Simple agricultural ERP Copyright (C) 2008-2009 Brice Texier, Thibaud Merigon Copyright (C) 2010-2012 Brice Texier Copyright (C) 2012-2016 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 www.gnu.org/licenses.

Table: products

address_id            :integer
born_at               :datetime
category_id           :integer          not null
created_at            :datetime         not null
creator_id            :integer
custom_fields         :jsonb
dead_at               :datetime
default_storage_id    :integer
derivative_of         :string
description           :text
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=>"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
name                  :string           not null
nature_id             :integer          not null
number                :string           not null
parent_id             :integer
person_id             :integer
picture_content_type  :string
picture_file_name     :string
picture_file_size     :integer
picture_updated_at    :datetime
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

Direct Known Subclasses

AnimalGroup, Building

Instance Method Summary collapse

Methods inherited from Product

#add_content_products, #age, #available?, availables, #born_at_in_interventions, #choose_default_name, #containeds, #container_at, #contains, #contents_name, #dead?, #dead_at_in_interventions, #default_catalog_item, #deliverable?, #evaluated_price, #groups_at, #initial_reading, #initializeable?, #localized_variants, #matching_model, #method_missing, #move!, #nature_name, new_with_cast, #owner, #part_with, #part_with!, #picture_path, #population, #price, #set_default_values, #set_initial_values, #unroll_name, #update_default_values, #variables, #work_name, #working_duration

Methods included from Customizable

#custom_value, #set_custom_value, #validate_custom_fields

Methods included from Versionable

#add_creation_version, #add_destruction_version, #add_update_version, #last_version, #notably_changed?, #version_object

Methods included from Indicateable

#add_and_read, #add_to_readings, #compute_and_read, #copy_readings_of!, #density, #first_reading, #get, #get!, #mark!, #operate_on_readings, #read!, #read_whole_indicators_from!, #reading, #substract_and_read, #substract_to_readings

Methods inherited from Ekylibre::Record::Base

#already_updated?, attr_readonly_with_conditions, #check_if_destroyable?, #check_if_updateable?, columns_definition, complex_scopes, customizable?, #customizable?, #customized?, #destroyable?, #editable?, has_picture, #human_attribute_name, human_attribute_name_with_id, nomenclature_reflections, #old_record, #others, refers_to, scope_with_registration, simple_scopes, #updateable?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Product

Instance Method Details

#add(member, options = {}) ⇒ Object

Add a member to the group


86
87
88
89
90
91
92
93
94
95
96
# File 'app/models/product_group.rb', line 86

def add(member, options = {})
  unless member.is_a?(Product)
    raise ArgumentError, "Product expected, got #{member.class}:#{member.inspect}"
  end
  Intervention.write(:group_inclusion, options) do |i|
    i.cast :group, self, as: 'group_inclusion-target'
    i.cast :member, member, as: 'group_inclusion-includer'
    i.group_inclusion :group, :member
  end
  # self.memberships.create!(member: member, started_at: (options[:at] || Time.zone.now), nature: :interior)
end

#members_at(viewed_at = nil) ⇒ Object

Returns members of the group at a given time (or now by default)


112
113
114
# File 'app/models/product_group.rb', line 112

def members_at(viewed_at = nil)
  Product.members_of(self, viewed_at || Time.zone.now)
end

#remove(member, _options = {}) ⇒ Object

Remove a member from the group


99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/product_group.rb', line 99

def remove(member, _options = {})
  unless member.is_a?(Product)
    raise ArgumentError, "Product expected, got #{member.class}:#{member.inspect}"
  end
  Intervention.write(:group_exclusion, at: started_at, production: production) do |i|
    i.cast :group, self, as: 'group_exclusion-target'
    i.cast :member, member, as: 'group_exclusion-includer'
    i.group_exclusion :group, :member
  end
  # self.memberships.create!(member: member, started_at: (options[:at] || Time.zone.now), nature: :exterior)
end