adding validates on name firstname, adding available_articles method in p_article model, adding fixing bugs

This commit is contained in:
Philippe 2021-11-18 11:13:01 +01:00
parent ea67464914
commit 0e093fac3d
9 changed files with 24 additions and 9 deletions

View File

@ -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

View File

@ -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

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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"}

View File

@ -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}

View File

@ -27,7 +27,7 @@ test:
production:
<<: *default
database: arcom_app
database: phone_app
username: postgres
password: 852321pg
host: localhost