Class: ParcelItem

Inherits:
Ekylibre::Record::Base show all
Defined in:
app/models/parcel_item.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: parcel_items

analysis_id                   :integer
created_at                    :datetime         not null
creator_id                    :integer
id                            :integer          not null, primary key
lock_version                  :integer          default(0), not null
parcel_id                     :integer          not null
parted                        :boolean          default(FALSE), not null
population                    :decimal(19, 4)
product_enjoyment_id          :integer
product_id                    :integer
product_identification_number :string
product_localization_id       :integer
product_movement_id           :integer
product_name                  :string
product_ownership_id          :integer
purchase_item_id              :integer
sale_item_id                  :integer
shape                         :geometry({:srid=>4326, :type=>"multi_polygon"})
source_product_id             :integer
source_product_movement_id    :integer
updated_at                    :datetime         not null
updater_id                    :integer
variant_id                    :integer

Constant Summary collapse

ALLOWED =
%w(
  product_localization_id
  product_movement_id
  product_enjoyment_id
  product_ownership_id
  purchase_item_id
  updated_at
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

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?

Instance Attribute Details

#product_nature_variant_idObject

Returns the value of attribute product_nature_variant_id


51
52
53
# File 'app/models/parcel_item.rb', line 51

def product_nature_variant_id
  @product_nature_variant_id
end

Instance Method Details

#checkObject

Set started_at/stopped_at in tasks concerned by preparation of item It takes product in stock


144
145
146
147
148
149
# File 'app/models/parcel_item.rb', line 144

def check
  checked_at = parcel_prepared_at
  check_incoming(checked_at) if parcel_incoming?
  check_outgoing(checked_at) if parcel_outgoing?
  save!
end

#giveObject

Mark items as given, and so change enjoyer and ownership if needed at this moment.


153
154
155
156
# File 'app/models/parcel_item.rb', line 153

def give
  give_outgoing if parcel_outgoing?
  give_incoming if parcel_incoming?
end

#prepared?Boolean


121
122
123
124
# File 'app/models/parcel_item.rb', line 121

def prepared?
  (!parcel_incoming? && source_product.present?) ||
    (parcel_incoming? && variant.present?)
end

#product_is_identifiable?Boolean


130
131
132
133
134
# File 'app/models/parcel_item.rb', line 130

def product_is_identifiable?
  [variant, source_product].reduce(false) do |acc, product_input|
    acc || Maybe(product_input).identifiable?.or_else(false)
  end
end

#product_is_unitary?Boolean


136
137
138
139
140
# File 'app/models/parcel_item.rb', line 136

def product_is_unitary?
  [variant, source_product].reduce(false) do |acc, product_input|
    acc || Maybe(product_input).population_counting_unitary?.or_else(false)
  end
end

#statusObject


126
127
128
# File 'app/models/parcel_item.rb', line 126

def status
  prepared? ? :go : variant.present? ? :caution : :stop
end