From 0e093fac3df1af1f6672152aa51fe88332ad2f94 Mon Sep 17 00:00:00 2001
From: Philippe
Date: Thu, 18 Nov 2021 11:13:01 +0100
Subject: [PATCH] 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