Class: PurchaseItem

Inherits:
Ekylibre::Record::Base show all
Includes:
PeriodicCalculable
Defined in:
app/models/purchase_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: purchase_items

account_id           :integer          not null
amount               :decimal(19, 4)   default(0.0), not null
annotation           :text
created_at           :datetime         not null
creator_id           :integer
currency             :string           not null
fixed                :boolean          default(FALSE), not null
id                   :integer          not null, primary key
label                :text
lock_version         :integer          default(0), not null
position             :integer
pretax_amount        :decimal(19, 4)   default(0.0), not null
purchase_id          :integer          not null
quantity             :decimal(19, 4)   default(1.0), not null
reduction_percentage :decimal(19, 4)   default(0.0), not null
tax_id               :integer          not null
unit_amount          :decimal(19, 4)   default(0.0), not null
unit_pretax_amount   :decimal(19, 4)   not null
updated_at           :datetime         not null
updater_id           :integer
variant_id           :integer          not null

Constant Summary

Constants included from PeriodicCalculable

PeriodicCalculable::PARAMETERS

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 Method Details

#designationObject


160
161
162
163
164
165
# File 'app/models/purchase_item.rb', line 160

def designation
  d = product_name
  d << "\n" + annotation.to_s unless annotation.blank?
  d << "\n" + tc(:tracking, serial: tracking.serial.to_s) if tracking
  d
end

#payment_ratioObject

know how many percentage of invoiced VAT to declare


172
173
174
175
176
177
178
# File 'app/models/purchase_item.rb', line 172

def payment_ratio
  if purchase.affair.balanced?
    return 1.00
  elsif purchase.affair.debit != 0.0
    return (1 - (purchase.affair.balance / purchase.affair.debit)).to_f
  end
end

#product_nameObject


152
153
154
# File 'app/models/purchase_item.rb', line 152

def product_name
  variant.name
end

#taxes_amountObject


156
157
158
# File 'app/models/purchase_item.rb', line 156

def taxes_amount
  amount - pretax_amount
end

#undelivered_quantityObject


167
168
169
# File 'app/models/purchase_item.rb', line 167

def undelivered_quantity
  self.quantity - parcel_items.sum(:quantity)
end