Skip to content

Commit

Permalink
Adds labels models
Browse files Browse the repository at this point in the history
  • Loading branch information
Brice TEXIER committed Sep 10, 2016
1 parent 859693a commit 70cb67a
Show file tree
Hide file tree
Showing 21 changed files with 424 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/models/intervention.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class Intervention < Ekylibre::Record::Base
belongs_to :request_intervention, -> { where(nature: :request) }, class_name: 'Intervention'
belongs_to :issue
belongs_to :prescription
has_many :labellings, class_name: 'InterventionLabelling', dependent: :destroy
has_many :labels, through: :labellings
has_many :record_interventions, -> { where(nature: :record) }, class_name: 'Intervention', inverse_of: 'request_intervention', foreign_key: :request_intervention_id

with_options inverse_of: :intervention do
has_many :root_parameters, -> { where(group_id: nil) }, class_name: 'InterventionParameter', dependent: :destroy
has_many :parameters, class_name: 'InterventionParameter'
Expand Down
40 changes: 40 additions & 0 deletions app/models/intervention_labelling.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# = 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 http://www.gnu.org/licenses.
#
# == Table: intervention_labellings
#
# created_at :datetime not null
# creator_id :integer
# id :integer not null, primary key
# intervention_id :integer not null
# label_id :integer not null
# lock_version :integer default(0), not null
# updated_at :datetime not null
# updater_id :integer
#
class InterventionLabelling < Ekylibre::Record::Base
belongs_to :intervention
belongs_to :label
# [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates :intervention, :label, presence: true
# ]VALIDATORS]
end
44 changes: 44 additions & 0 deletions app/models/label.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# = 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 http://www.gnu.org/licenses.
#
# == Table: labels
#
# color :string not null
# created_at :datetime not null
# creator_id :integer
# id :integer not null, primary key
# lock_version :integer default(0), not null
# name :string not null
# updated_at :datetime not null
# updater_id :integer
#

class Label < Ekylibre::Record::Base
has_many :intervention_labellings
has_many :interventions, through: :intervention_labellings
has_many :product_labellings
has_many :products, through: :product_labellings
# [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates :color, presence: true, length: { maximum: 500 }
validates :name, presence: true, uniqueness: true, length: { maximum: 500 }
# ]VALIDATORS]
end
2 changes: 2 additions & 0 deletions app/models/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ class Product < Ekylibre::Record::Base
has_many :issues, as: :target, dependent: :destroy
has_many :intervention_product_parameters, -> { unscope(where: :type).of_generic_roles([:input, :output, :target, :doer, :tool]) }, foreign_key: :product_id, inverse_of: :product, dependent: :restrict_with_exception
has_many :interventions, through: :intervention_product_parameters
has_many :labellings, class_name: 'ProductLabelling', dependent: :destroy
has_many :labels, through: :labellings
has_many :linkages, class_name: 'ProductLinkage', foreign_key: :carrier_id, dependent: :destroy
has_many :links, class_name: 'ProductLink', foreign_key: :product_id, dependent: :destroy
has_many :localizations, class_name: 'ProductLocalization', foreign_key: :product_id, dependent: :destroy
Expand Down
40 changes: 40 additions & 0 deletions app/models/product_labelling.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# = 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 http://www.gnu.org/licenses.
#
# == Table: product_labellings
#
# created_at :datetime not null
# creator_id :integer
# id :integer not null, primary key
# label_id :integer not null
# lock_version :integer default(0), not null
# product_id :integer not null
# updated_at :datetime not null
# updater_id :integer
#
class ProductLabelling < Ekylibre::Record::Base
belongs_to :product
belongs_to :label
# [VALIDATORS[ Do not edit these lines directly. Use `rake clean:validations`.
validates :label, :product, presence: true
# ]VALIDATORS]
end
2 changes: 2 additions & 0 deletions config/locales/arb/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1565,6 +1565,8 @@ arb:
journals: "الدفاتر اليومية" #?
key: "المفتاح"
label: "الملصق"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "عدد قطعة أرض"
land_parcels: "الكتل"
language: "اللغة"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/cmn/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ cmn:
journal_entry_items: "日记条目项目"
key: ""
label: "标签"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "地块编号"
land_parcels: "地块"
language: "语言"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/deu/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ deu:
journal_entry_items: "Journaleintrag Artikel"
key: "Taste"
label: "Etikette"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "Land Paketnummer"
land_parcels: "Parzellen"
language: "Sprache"
Expand Down
7 changes: 7 additions & 0 deletions config/locales/eng/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ eng:
intervention_doer: "Intervention doer"
intervention_group_parameter: "Intervention group parameter"
intervention_input: "Intervention input"
# intervention_labelling: "Intervention labelling"
intervention_output: "Intervention output"
intervention_parameter: "Intervention parameter"
intervention_parameter_reading: "Product reading task"
Expand All @@ -231,6 +232,7 @@ eng:
journal: "Journal"
journal_entry: "Journal entry"
journal_entry_item: "Journal entry item"
# label: "Label"
land_parcel: "Land parcel"
listing: "Listing"
listing_node: "Listing node"
Expand Down Expand Up @@ -259,6 +261,7 @@ eng:
product: "Product"
product_enjoyment: "Product enjoyment"
product_group: "Product group"
# product_labelling: "Product labelling"
product_link: "Product link"
product_linkage: "Product linkage"
product_localization: "Product localization"
Expand Down Expand Up @@ -736,6 +739,7 @@ eng:
interpolations: "Interpolations"
intervention: "Intervention"
intervention_cast: "Intervention cast" #?
# intervention_labellings: "Intervention labellings"
intervention_parameter: "Intervention parameter"
intervention_product_parameters: "Intervention casts"
interventions: "Interventions"
Expand Down Expand Up @@ -776,6 +780,8 @@ eng:
journal_entry_items: "Journal entry items"
key: "Key"
label: "Label"
labellings: "Labellings"
labels: "Labels"
land_parcel_number: "Land parcel number"
land_parcels: "Land parcels"
language: "Language"
Expand Down Expand Up @@ -1000,6 +1006,7 @@ eng:
# product_enjoyment: "Product enjoyment"
product_enjoyments: "Product enjoyments" #?
product_identification_number: "Identification number"
# product_labellings: "Product labellings"
product_linkages: "Product linkages" #?
product_localization: "Product localization"
product_localizations: "Product localizations" #?
Expand Down
2 changes: 2 additions & 0 deletions config/locales/fra/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ fra:
junctions: "Jonctions" #?
key: "Clé"
label: "Libellé"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "Numéro de la parcelle PAC"
land_parcels: "Parcelles"
language: "Langue"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/ita/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,8 @@ ita:
journal_entry_items: "articoli voce di diario"
key: "Chiave"
label: "Etichetta"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "il numero delle parcelle agricole"
land_parcels: "appezzamenti"
language: "Lingua"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/jpn/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ jpn:
journal_entry_items: "仕訳項目"
key: "キー"
label: "ラベル"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "土地区画番号"
land_parcels: "土地区画"
language: "言語"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/por/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,8 @@ por:
journal_entry_items: "Itens de entrada de diário"
key: "Chave"
label: "Rótulo"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "Número de parcelas de terreno"
land_parcels: "Parcelas de terra"
language: "Língua"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/spa/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,8 @@ spa:
journal_entry_items: "Artículos entrada de diario"
key: "Llave"
label: "Etiqueta"
# labellings: "Labellings"
# labels: "Labels"
land_parcel_number: "Número de parcelas"
land_parcels: "Parcelas"
language: "Idioma"
Expand Down
24 changes: 24 additions & 0 deletions db/migrate/20160910200730_create_labels.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
class CreateLabels < ActiveRecord::Migration
def change
create_table :labels do |t|
t.string :name, null: false
t.string :color, null: false
t.stamps
t.index :name, unique: true
end

create_table :intervention_labellings do |t|
t.references :intervention, null: false, index: true
t.references :label, null: false, index: true
t.stamps
t.index [:intervention_id, :label_id], unique: true
end

create_table :product_labellings do |t|
t.references :product, null: false, index: true
t.references :label, null: false, index: true
t.stamps
t.index [:product_id, :label_id], unique: true
end
end
end
3 changes: 3 additions & 0 deletions db/models.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
- intervention_doer
- intervention_group_parameter
- intervention_input
- intervention_labelling
- intervention_output
- intervention_parameter
- intervention_parameter_reading
Expand All @@ -89,6 +90,7 @@
- journal
- journal_entry
- journal_entry_item
- label
- land_parcel
- listing
- listing_node
Expand Down Expand Up @@ -117,6 +119,7 @@
- product
- product_enjoyment
- product_group
- product_labelling
- product_link
- product_linkage
- product_localization
Expand Down
54 changes: 53 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20160906112630) do
ActiveRecord::Schema.define(version: 20160910200730) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -1575,6 +1575,24 @@
add_index "integrations", ["updated_at"], name: "index_integrations_on_updated_at", using: :btree
add_index "integrations", ["updater_id"], name: "index_integrations_on_updater_id", using: :btree

create_table "intervention_labellings", force: :cascade do |t|
t.integer "intervention_id", null: false
t.integer "label_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "creator_id"
t.integer "updater_id"
t.integer "lock_version", default: 0, null: false
end

add_index "intervention_labellings", ["created_at"], name: "index_intervention_labellings_on_created_at", using: :btree
add_index "intervention_labellings", ["creator_id"], name: "index_intervention_labellings_on_creator_id", using: :btree
add_index "intervention_labellings", ["intervention_id", "label_id"], name: "index_intervention_labellings_on_intervention_id_and_label_id", unique: true, using: :btree
add_index "intervention_labellings", ["intervention_id"], name: "index_intervention_labellings_on_intervention_id", using: :btree
add_index "intervention_labellings", ["label_id"], name: "index_intervention_labellings_on_label_id", using: :btree
add_index "intervention_labellings", ["updated_at"], name: "index_intervention_labellings_on_updated_at", using: :btree
add_index "intervention_labellings", ["updater_id"], name: "index_intervention_labellings_on_updater_id", using: :btree

create_table "intervention_parameter_readings", force: :cascade do |t|
t.string "indicator_name", null: false
t.string "indicator_datatype", null: false
Expand Down Expand Up @@ -1889,6 +1907,22 @@
add_index "journals", ["updated_at"], name: "index_journals_on_updated_at", using: :btree
add_index "journals", ["updater_id"], name: "index_journals_on_updater_id", using: :btree

create_table "labels", force: :cascade do |t|
t.string "name", null: false
t.string "color", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "creator_id"
t.integer "updater_id"
t.integer "lock_version", default: 0, null: false
end

add_index "labels", ["created_at"], name: "index_labels_on_created_at", using: :btree
add_index "labels", ["creator_id"], name: "index_labels_on_creator_id", using: :btree
add_index "labels", ["name"], name: "index_labels_on_name", unique: true, using: :btree
add_index "labels", ["updated_at"], name: "index_labels_on_updated_at", using: :btree
add_index "labels", ["updater_id"], name: "index_labels_on_updater_id", using: :btree

create_table "listing_node_items", force: :cascade do |t|
t.integer "node_id", null: false
t.string "nature", null: false
Expand Down Expand Up @@ -2480,6 +2514,24 @@
add_index "product_enjoyments", ["updated_at"], name: "index_product_enjoyments_on_updated_at", using: :btree
add_index "product_enjoyments", ["updater_id"], name: "index_product_enjoyments_on_updater_id", using: :btree

create_table "product_labellings", force: :cascade do |t|
t.integer "product_id", null: false
t.integer "label_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "creator_id"
t.integer "updater_id"
t.integer "lock_version", default: 0, null: false
end

add_index "product_labellings", ["created_at"], name: "index_product_labellings_on_created_at", using: :btree
add_index "product_labellings", ["creator_id"], name: "index_product_labellings_on_creator_id", using: :btree
add_index "product_labellings", ["label_id"], name: "index_product_labellings_on_label_id", using: :btree
add_index "product_labellings", ["product_id", "label_id"], name: "index_product_labellings_on_product_id_and_label_id", unique: true, using: :btree
add_index "product_labellings", ["product_id"], name: "index_product_labellings_on_product_id", using: :btree
add_index "product_labellings", ["updated_at"], name: "index_product_labellings_on_updated_at", using: :btree
add_index "product_labellings", ["updater_id"], name: "index_product_labellings_on_updater_id", using: :btree

create_table "product_linkages", force: :cascade do |t|
t.integer "originator_id"
t.string "originator_type"
Expand Down
Loading

0 comments on commit 70cb67a

Please sign in to comment.