From 0e093fac3df1af1f6672152aa51fe88332ad2f94 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Thu, 18 Nov 2021 11:13:01 +0100
Subject: [PATCH 1/3] adding validates on name firstname, adding
available_articles method in p_article model, adding fixing bugs
---
app/controllers/admin/line_stocks_controller.rb | 4 +++-
app/models/p_article.rb | 13 ++++++++++++-
app/models/particular.rb | 2 ++
app/models/price_line_block.rb | 2 +-
app/views/admin/price_documents/index.html.haml | 2 +-
app/views/admin/price_documents/show.html.haml | 5 ++---
.../admin/price_line_p_articles/_form.html.haml | 2 +-
.../admin/price_lines/_add_p_article_form.html.haml | 1 +
config/database.yml | 2 +-
9 files changed, 24 insertions(+), 9 deletions(-)
diff --git a/app/controllers/admin/line_stocks_controller.rb b/app/controllers/admin/line_stocks_controller.rb
index caab464..ea968b2 100644
--- a/app/controllers/admin/line_stocks_controller.rb
+++ b/app/controllers/admin/line_stocks_controller.rb
@@ -54,7 +54,9 @@ class Admin::LineStocksController < ApplicationController
end
- @line_stocks = sort_by_sorting(@line_stocks, "date DESC")
+ #@line_stocks = sort_by_sorting(@line_stocks, "date DESC")
+ @line_stocks = @line_stocks.order(date: :desc, id: :desc)
+
@all_line_stocks = @line_stocks
diff --git a/app/models/p_article.rb b/app/models/p_article.rb
index 9cadeb6..9348933 100644
--- a/app/models/p_article.rb
+++ b/app/models/p_article.rb
@@ -59,6 +59,17 @@ class PArticle < ApplicationRecord
end
def serialized_name
- "#{self.p_product_ref.cc_name} #{self.p_article_serial_nums.map{|x| x.value}.join(' / ')}"
+ "#{self.p_product_ref.cc_name} #{self.p_article_serial_nums.map{|x| "#{x.p_serial_num_type.name}: #{x.value}"}.join(' / ')}"
end
+
+ def self.available_articles
+ p_articles = PArticle.joins(:line_stocks).where("qte_available > ?", 0)
+ p_articles.each do |p_article|
+ if LineStockUsage.where(p_article_id: p_article.id).empty?
+ p_articles.drop(p_article.id)
+ end
+ end
+ return p_articles
+ end
+
end
diff --git a/app/models/particular.rb b/app/models/particular.rb
index ca23dfe..c5ab907 100644
--- a/app/models/particular.rb
+++ b/app/models/particular.rb
@@ -18,6 +18,8 @@ class Particular < ApplicationRecord
validates :country, :presence => true, :if => :force_validation
#validates :tel, :presence => true, :if => :force_validation
validates :organisation, :presence => true, :if => :force_validation
+ validates :name, :presence => true, :if => :force_validation
+ validates :firstname, :presence => true, :if => :force_validation
attr_accessor :validate_email, :skip_email
belongs_to :particular_ref, :class_name => "Particular"
diff --git a/app/models/price_line_block.rb b/app/models/price_line_block.rb
index 03bab55..f17b509 100644
--- a/app/models/price_line_block.rb
+++ b/app/models/price_line_block.rb
@@ -171,7 +171,7 @@ class PriceLineBlock < ApplicationRecord
line_stock: decr_line_stock
)
ls_p_art.save
-
+ #p_article.line_stocks << decr_line_stock fonctionne aussi selon la doc : https://guides.rubyonrails.org/association_basics.html#:~:text=The%20collection%20of%20join%20models%20can%20be%20managed
end
else
diff --git a/app/views/admin/price_documents/index.html.haml b/app/views/admin/price_documents/index.html.haml
index 65869ab..34107c9 100644
--- a/app/views/admin/price_documents/index.html.haml
+++ b/app/views/admin/price_documents/index.html.haml
@@ -1,6 +1,6 @@
.qi_header
.right
- -if params[:price_document_type_id].to_i == 6 # Facture Achat
+ -if params[:price_document_type_id].to_i == 6 or params[:price_document_type_id].nil? # Facture Achat
= link_to 'Ajouter une facture achat', new_admin_price_document_path(:document_type => "Facture achat"), :class => "btn btn-primary bgbd-documents", :remote => false
-elsif params[:price_document_type_id].to_i == 4 # Commande Achat
= link_to 'Ajouter une commande achat', new_admin_price_document_path(:document_type => "Commande achat"), :class => "btn btn-primary bgbd-documents", :remote => false
diff --git a/app/views/admin/price_documents/show.html.haml b/app/views/admin/price_documents/show.html.haml
index 7bd05c1..11619e8 100644
--- a/app/views/admin/price_documents/show.html.haml
+++ b/app/views/admin/price_documents/show.html.haml
@@ -232,7 +232,7 @@
= link_to i(:"trash-o"), admin_price_line_path(price_line), method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
= link_to i(:pencil), edit_admin_price_line_path(price_line), :remote => true
= link_to i(:eye), admin_price_line_path(price_line), :remote => true
- = link_to i(:"mobile-alt"), add_p_article_admin_price_lines_path(p_product_ref_id: price_line.p_product_ref.id, price_line_id: price_line.id), :remote => true if price_line.p_product_ref.p_product.stockable and price_line.p_product_ref.p_product.with_serial_number
+ = link_to i(:"mobile-alt"), add_p_article_admin_price_lines_path(p_product_ref_id: price_line.p_product_ref.id, price_line_id: price_line.id), :remote => true if @price_document.price_document_type_id != 6 and price_line.p_product_ref.p_product.stockable and price_line.p_product_ref.p_product.with_serial_number
-price_line.p_articles.each do |p_article|
%tr{class: "p_articles_lines p_articles_#{price_line.id}"}
%td
@@ -248,8 +248,7 @@
-if @price_document.price_document_type_id == 6
-# =link_to "Générer les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
-# =link_to "Générer les stocks", generate_stocks_admin_price_document_path(@price_document), :class => "btn btn-primary disabled" if !@price_document.stock_ok and !@price_document.stock_generable
- =link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok and @price_document.stock_generable
- =link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary disabled" if !@price_document.stock_ok and !@price_document.stock_generable
+ =link_to "Générer un bon de réception", bon_de_reception_admin_price_document_path(@price_document), :class => "btn btn-primary" if !@price_document.stock_ok
-elsif @price_document.price_document_type_id == 4 or @price_document.price_document_type_id == 5
-# %p
diff --git a/app/views/admin/price_line_p_articles/_form.html.haml b/app/views/admin/price_line_p_articles/_form.html.haml
index 2dcf600..5726753 100644
--- a/app/views/admin/price_line_p_articles/_form.html.haml
+++ b/app/views/admin/price_line_p_articles/_form.html.haml
@@ -1 +1 @@
-= form.input :p_article_id, as: :select, collection: PArticle.joins(:p_product_ref).where(p_product_ref: @price_line.p_product_ref).map{|p_article| [p_article.serialized_name, p_article.id]}, label: "Article(s) associé(s)", input_html: {class:"p_article_select"}
+= form.input :p_article_id, as: :select, collection: PArticle.available_articles.joins(:p_product_ref).where(p_product_ref: @price_line.p_product_ref).map{|p_article| [p_article.serialized_name, p_article.id]}, label: "Article(s) associé(s)", input_html: {class:"p_article_select"}
diff --git a/app/views/admin/price_lines/_add_p_article_form.html.haml b/app/views/admin/price_lines/_add_p_article_form.html.haml
index aed4cdb..3b4efde 100644
--- a/app/views/admin/price_lines/_add_p_article_form.html.haml
+++ b/app/views/admin/price_lines/_add_p_article_form.html.haml
@@ -6,4 +6,5 @@
= f.semantic_fields_for :p_articles do |form|
=render :partial => "admin/p_articles/form", :locals => {:form => form, @price_line => f.object}
%p= link_to_add_fields "Ajouter un article", f, :p_articles, {:class => "btn btn-primary"} if f.object.p_articles.count < f.object.qte
+ -# %span.destroy{style: "font-size: 2rem;"}=link_to_remove_fields ic(:"trash-o"), f
=render :partial => "qi/actions", :locals => {:f => f}
diff --git a/config/database.yml b/config/database.yml
index 8c6dba5..b85374a 100644
--- a/config/database.yml
+++ b/config/database.yml
@@ -27,7 +27,7 @@ test:
production:
<<: *default
- database: arcom_app
+ database: phone_app
username: postgres
password: 852321pg
host: localhost
From 43e26cabf232b4c62ce4e91bf13a58d143021a14 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Thu, 18 Nov 2021 11:54:07 +0100
Subject: [PATCH 2/3] fixing available_p_articles method
---
app/models/p_article.rb | 21 ++++++++++++++++++---
1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/app/models/p_article.rb b/app/models/p_article.rb
index 9348933..f2da272 100644
--- a/app/models/p_article.rb
+++ b/app/models/p_article.rb
@@ -62,14 +62,29 @@ class PArticle < ApplicationRecord
"#{self.p_product_ref.cc_name} #{self.p_article_serial_nums.map{|x| "#{x.p_serial_num_type.name}: #{x.value}"}.join(' / ')}"
end
+ # def self.available_articles
+ # p_articles = PArticle.joins(:line_stocks).where("qte_available > ?", 0)
+ # p_articles.each do |p_article|
+ # if LineStockUsage.where(p_article_id: p_article.id).empty?
+ # p_articles.drop(p_article.id)
+ # end
+ # end
+ # return p_articles
+ # end
+
def self.available_articles
p_articles = PArticle.joins(:line_stocks).where("qte_available > ?", 0)
+ used_p_articles_ids = LineStockUsage.where.not(p_article_id: nil).pluck(:p_article_id)#.map{|ls| ls.p_article_id}
+ available_p_articles_ids =[]
p_articles.each do |p_article|
- if LineStockUsage.where(p_article_id: p_article.id).empty?
- p_articles.drop(p_article.id)
+ #puts used_p_articles_ids.include?(p_article.id)
+ if !used_p_articles_ids.include?(p_article.id)
+ available_p_articles_ids << p_article.id
end
+
end
- return p_articles
+
+ return PArticle.where(id: available_p_articles_ids)
end
end
From 94fd558c30b383c8fd8f109de14a126ec3888ae4 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Thu, 18 Nov 2021 13:55:34 +0100
Subject: [PATCH 3/3] adding adresse qi_s, adding link_to_remove_fields
---
app/models/price_line.rb | 2 +-
app/views/admin/p_articles/_form.html.haml | 34 +++++++++---------
.../admin/particulars/_particular.html.haml | 36 +++++++------------
.../price_lines/_add_p_article_form.html.haml | 2 +-
4 files changed, 33 insertions(+), 41 deletions(-)
diff --git a/app/models/price_line.rb b/app/models/price_line.rb
index 534aaf5..bf653ba 100644
--- a/app/models/price_line.rb
+++ b/app/models/price_line.rb
@@ -12,7 +12,7 @@ class PriceLine < ApplicationRecord
#has_many :price_line_demands, through: :price_line_resp_selects
has_many :price_line_p_articles
has_many :p_articles, through: :price_line_p_articles
- accepts_nested_attributes_for :p_articles
+ accepts_nested_attributes_for :p_articles, allow_destroy: true
accepts_nested_attributes_for :price_line_p_articles
default_scope { order('position ASC') }
diff --git a/app/views/admin/p_articles/_form.html.haml b/app/views/admin/p_articles/_form.html.haml
index 6ed23d2..7b42465 100644
--- a/app/views/admin/p_articles/_form.html.haml
+++ b/app/views/admin/p_articles/_form.html.haml
@@ -16,21 +16,23 @@
=render :partial => "qi/actions", :locals => {:f => f}
/.actions=f.submit "sauvegarder", :class => "btn btn-primary"
- elsif params[:controller] == "admin/price_lines"
- = form.inputs do
+ .field
+ = form.inputs do
- =@price_line.price_line_block.price_lineable.tva_type_id
- -if params[:p_product_ref_id]
- = form.input :p_product_ref_id, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => form.object.label_for(:p_product_ref), input_html: {disabled: true}
- = form.hidden_field :p_product_ref_id, value: form.object.p_product_ref_id
- = form.hidden_field :tva_type_id, value: @price_line.price_line_block.price_lineable.tva_type_id
+ =@price_line.price_line_block.price_lineable.tva_type_id
+ -if params[:p_product_ref_id]
+ = form.input :p_product_ref_id, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => form.object.label_for(:p_product_ref), input_html: {disabled: true}
+ = form.hidden_field :p_product_ref_id, value: form.object.p_product_ref_id
+ = form.hidden_field :tva_type_id, value: @price_line.price_line_block.price_lineable.tva_type_id
- -else
- = form.input :p_product_ref_id, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => form.object.label_for(:p_product_ref), input_html: {disabled: true}
- = form.hidden_field :p_product_ref_id, value: form.object.p_product_ref_id
- -if PGrade::ACTIVATED
- = form.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade"
- %h4 Numero de série :
- .p_article_serial_nums_form
- = form.semantic_fields_for :p_article_serial_nums do |form|
- =render :partial => "admin/p_article_serial_nums/form", :locals => {:form => form}
- %p= link_to_add_fields "Ajouter un numéro de série", form, :p_article_serial_nums, {:class => "btn btn-primary"}
+ -else
+ = form.input :p_product_ref_id, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => form.object.label_for(:p_product_ref), input_html: {disabled: true}
+ = form.hidden_field :p_product_ref_id, value: form.object.p_product_ref_id
+ -if PGrade::ACTIVATED
+ = form.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade"
+ %h4 Numero de série :
+ .p_article_serial_nums_form
+ = form.semantic_fields_for :p_article_serial_nums do |form|
+ =render :partial => "admin/p_article_serial_nums/form", :locals => {:form => form}
+ %p= link_to_add_fields "Ajouter un numéro de série", form, :p_article_serial_nums, {:class => "btn btn-primary"}
+ %p.destroy{class: "btn btn-danger"}=link_to_remove_fields "Supprimer l'article", form
diff --git a/app/views/admin/particulars/_particular.html.haml b/app/views/admin/particulars/_particular.html.haml
index e5253ea..0a9aa52 100644
--- a/app/views/admin/particulars/_particular.html.haml
+++ b/app/views/admin/particulars/_particular.html.haml
@@ -1,26 +1,16 @@
-.particular_apercu
- -if particular.organisation?
- =particular.organisation
+%tr#particular_row{:id => particular.id}
+ -tr = {}
- -if particular.firstname? or particular.name?
- %strong
- =particular.firstname
+ -tr[:actions] = capture do
+ %td.actions
+ = link_to i(:"trash-o"), [:admin, particular], method: :delete, data: { confirm: 'Voulez-vous vraiment supprimer cet enregistrement ? ' } , :remote => true
+ = link_to i(:pencil), edit_admin_particular_path(particular), :remote => true
+ = link_to i(:eye), admin_particular_path(particular), :remote => true
- =particular.name
- %br
+
+
+ =render :partial => "qi/qi_ordered_table_object", :locals => {:tr => tr, :object => particular}
+
- =particular.address_2
-
- -if particular.address_3?
- %br
- =particular.address_3
- %br
- =particular.cp
-
- =particular.city
- %br
- =particular.country
- %br
- =particular.tel
- %br
- =particular.email
\ No newline at end of file
+
+
\ No newline at end of file
diff --git a/app/views/admin/price_lines/_add_p_article_form.html.haml b/app/views/admin/price_lines/_add_p_article_form.html.haml
index 3b4efde..33a2951 100644
--- a/app/views/admin/price_lines/_add_p_article_form.html.haml
+++ b/app/views/admin/price_lines/_add_p_article_form.html.haml
@@ -5,6 +5,6 @@
.p_articles_form
= f.semantic_fields_for :p_articles do |form|
=render :partial => "admin/p_articles/form", :locals => {:form => form, @price_line => f.object}
+
%p= link_to_add_fields "Ajouter un article", f, :p_articles, {:class => "btn btn-primary"} if f.object.p_articles.count < f.object.qte
- -# %span.destroy{style: "font-size: 2rem;"}=link_to_remove_fields ic(:"trash-o"), f
=render :partial => "qi/actions", :locals => {:f => f}