Class: ProductNatureCategory

Inherits:
Ekylibre::Record::Base show all
Includes:
Customizable
Defined in:
app/models/product_nature_category.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: product_nature_categories

active                              :boolean          default(FALSE), not null
charge_account_id                   :integer
created_at                          :datetime         not null
creator_id                          :integer
custom_fields                       :jsonb
depreciable                         :boolean          default(FALSE), not null
description                         :text
fixed_asset_account_id              :integer
fixed_asset_allocation_account_id   :integer
fixed_asset_depreciation_method     :string
fixed_asset_depreciation_percentage :decimal(19, 4)   default(0.0)
fixed_asset_expenses_account_id     :integer
id                                  :integer          not null, primary key
lock_version                        :integer          default(0), not null
name                                :string           not null
number                              :string           not null
pictogram                           :string
product_account_id                  :integer
purchasable                         :boolean          default(FALSE), not null
reductible                          :boolean          default(FALSE), not null
reference_name                      :string
saleable                            :boolean          default(FALSE), not null
stock_account_id                    :integer
storable                            :boolean          default(FALSE), not null
subscribing                         :boolean          default(FALSE), not null
updated_at                          :datetime         not null
updater_id                          :integer

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Customizable

#custom_value, #set_custom_value, #validate_custom_fields

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?

Class Method Details

.import_all_from_nomenclatureObject

Load.all product nature from product nature nomenclature


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

def import_all_from_nomenclature
  Nomen::ProductNatureCategory.find_each do |product_nature_category|
    import_from_nomenclature(product_nature_category)
  end
end

.import_from_nomenclature(reference_name, force = false) ⇒ Object

Load a product nature category from product nature category nomenclature


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'app/models/product_nature_category.rb', line 129

def import_from_nomenclature(reference_name, force = false)
  unless item = Nomen::ProductNatureCategory.find(reference_name)
    raise ArgumentError, "The product_nature_category #{reference_name.inspect} is unknown"
  end
  if !force && category = ProductNatureCategory.find_by_reference_name(reference_name)
    return category
  end
  attributes = {
    active: true,
    name: item.human_name,
    reference_name: item.name,
    pictogram: item.pictogram,
    depreciable: item.depreciable,
    purchasable: item.purchasable,
    reductible: item.reductible,
    saleable: item.saleable,
    storable: item.storable,
    fixed_asset_depreciation_percentage: (item.depreciation_percentage.present? ? item.depreciation_percentage : 20),
    fixed_asset_depreciation_method: :simplified_linear
  }.with_indifferent_access
  for  in [:fixed_asset, :fixed_asset_allocation, :fixed_asset_expenses, :charge, :product, :stock]
    name = item.send("#{}_account")
    unless name.blank?
      attributes["#{}_account"] = Account.find_or_import_from_nomenclature(name)
    end
  end
  # TODO: add in rake clean method a way to detect same translation in nomenclatures by locale (to avoid conflict with validation on uniq name for example)
  # puts "#{item.human_name} - #{item.name}".red
  create!(attributes)
end

Instance Method Details

#deliverable?Boolean

Returns:

  • (Boolean)

119
120
121
# File 'app/models/product_nature_category.rb', line 119

def deliverable?
  storable?
end

#labelObject


123
124
125
# File 'app/models/product_nature_category.rb', line 123

def label
  name # tc('label', :product_nature_category => self["name"])
end

#toObject


111
112
113
114
115
116
117
# File 'app/models/product_nature_category.rb', line 111

def to
  to = []
  to << :sales if saleable?
  to << :purchases if purchasable?
  # to << :produce if self.producible?
  to.collect { |x| tc('to.' + x.to_s) }.to_sentence
end