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-2019 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

activity_budget_id            :integer
analysis_id                   :integer
created_at                    :datetime         not null
creator_id                    :integer
currency                      :string
delivery_id                   :integer
delivery_mode                 :string
equipment_id                  :integer
id                            :integer          not null, primary key
lock_version                  :integer          default(0), not null
merge_stock                   :boolean          default(TRUE)
non_compliant                 :boolean
non_compliant_detail          :string
parcel_id                     :integer          not null
parted                        :boolean          default(FALSE), not null
population                    :decimal(19, 4)
pretax_amount                 :decimal(19, 4)   default(0.0), not null
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
product_work_number           :string
project_budget_id             :integer
purchase_invoice_item_id      :integer
purchase_order_item_id        :integer
purchase_order_to_close_id    :integer
role                          :string
sale_item_id                  :integer
shape                         :geometry({:srid=>4326, :type=>"multi_polygon"})
source_product_id             :integer
source_product_movement_id    :integer
team_id                       :integer
transporter_id                :integer
type                          :string
unit_pretax_amount            :decimal(19, 4)   default(0.0), not null
unit_pretax_stock_amount      :decimal(19, 4)   default(0.0), not null
updated_at                    :datetime         not null
updater_id                    :integer
variant_id                    :integer

Direct Known Subclasses

ReceptionItem, ShipmentItem

Constant Summary collapse

ALLOWED =
%w[
  product_localization_id
  product_movement_id
  product_enjoyment_id
  product_ownership_id
  unit_pretax_stock_amount
  unit_pretax_amount
  pretax_amount
  purchase_order_item_id
  purchase_invoice_item_id
  sale_item_id
  updated_at
  updater_id
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Ekylibre::Record::Base

#already_updated?, #check_if_destroyable?, #check_if_updateable?, columns_definition, #customizable?, customizable?, #customized?, #destroyable?, #editable?, has_picture, #human_attribute_name, nomenclature_reflections, #old_record, #others, refers_to, #unsuppress, #updateable?

Methods included from Userstamp::Stampable

included

Methods included from Userstamp::Stamper

included

Instance Attribute Details

#product_nature_variant_idObject

Returns the value of attribute product_nature_variant_id


70
71
72
# File 'app/models/parcel_item.rb', line 70

def product_nature_variant_id
  @product_nature_variant_id
end

Instance Method Details

#nameObject


186
187
188
# File 'app/models/parcel_item.rb', line 186

def name
  Maybe(source_product || variant || products).name.or_else(nil)
end

#prepared?Boolean

Returns:

  • (Boolean)

170
171
172
# File 'app/models/parcel_item.rb', line 170

def prepared?
  false
end

#product_is_identifiable?Boolean

Returns:

  • (Boolean)

174
175
176
177
178
# File 'app/models/parcel_item.rb', line 174

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

Returns:

  • (Boolean)

180
181
182
183
184
# File 'app/models/parcel_item.rb', line 180

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

#purchase_invoice_numberObject


196
197
198
199
# File 'app/models/parcel_item.rb', line 196

def purchase_invoice_number
  return nil if purchase_invoice_item.nil?
  purchase_invoice_item.purchase.number
end

#purchase_order_numberObject


190
191
192
193
194
# File 'app/models/parcel_item.rb', line 190

def purchase_order_number
  return nil if purchase_order_item.nil?

  purchase_order_item.purchase.number
end

#statusObject


166
167
168
# File 'app/models/parcel_item.rb', line 166

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

#stock_amountObject


162
163
164
# File 'app/models/parcel_item.rb', line 162

def stock_amount
  population * unit_pretax_stock_amount
end