adding nested p articles and SN

This commit is contained in:
Philippe 2021-11-02 19:36:31 +01:00
parent ee52fca31e
commit f1bad61fd2
29 changed files with 212 additions and 98 deletions

View File

@ -10,7 +10,7 @@
.actions{
position:absolute;
position: static;
bottom:0px;
left:0px;
right:0px;

View File

@ -1,5 +1,5 @@
# -*- encoding : utf-8 -*-
require "awesome_print"
class Admin::PriceLinesController < ApplicationController
layout "admin"
before_action :auth_admin, :except => [:edit, :update]
@ -44,12 +44,17 @@ class Admin::PriceLinesController < ApplicationController
def update
puts "PAAMSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
puts params
puts "PAAMSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
@price_line = PriceLine.find(params[:id])
if @price_line.update_attributes(params.require(:price_line).permit!)
else
puts "ERRORSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
puts @price_line.errors.messages
puts "ERRORSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS"
render action: "edit"
end
@ -62,4 +67,10 @@ class Admin::PriceLinesController < ApplicationController
@price_line.destroy
end
def add_p_article
@price_line = PriceLine.find(params[:price_line_id])
# @p_article = PArticle.new#@price_line.p_articles.build
# @p_article_serial_nums = @p_article.p_article_serial_nums.build
end
end

View File

@ -78,7 +78,6 @@ module ApplicationHelper
icon = sort_direction == "asc" ? "chevron-up" : "chevron-down"
icon = column == sort_column ? icon : ""
link_to raw("#{title} "+ic(icon).html_safe), request.query_parameters.merge({column: column, direction: direction})
end
end
end

View File

@ -20,6 +20,18 @@ module DocumentLineHelper
end
if association == :p_articles
new_object.p_product_ref_id = f.object.p_product_ref_id
end
if options[:partial]
fields = f.fields_for(association, new_object, :child_index => "new_#{association}") do |builder|
render(options[:partial], :form => builder)

View File

@ -6,6 +6,8 @@
belongs_to :price_line_block
belongs_to :stock_movement_line
belongs_to :partition_lines
acts_as_sorting :fields => {
:id => {:name => "ID", :reorder => false},
:date => {:name => "Date", :reorder => true, :as => :date},

View File

@ -7,8 +7,12 @@ class PArticle < ApplicationRecord
has_many :p_article_serial_nums, dependent: :destroy
# has_many :p_serial_num_values, through: :p_article_serial_nums
has_many :price_line_p_articles
has_many :price_lines, through: :price_line_p_articles
accepts_nested_attributes_for :p_article_serial_nums
validates_presence_of :p_product_ref
# has_many :p_product_ref_specs, through: :p_product_ref
# accepts_nested_attributes_for :p_product_ref_specs

View File

@ -73,8 +73,13 @@ class PCustomer < ApplicationRecord
def generate_code
if !self.code
last_used_code = self.class.all.order(code: :desc).limit(1)[0].code
last_number = last_used_code.match(/\d+/).to_s.to_i + 1
if self.class.all.order(code: :desc).limit(1)[0]
last_used_code = self.class.all.order(code: :desc).limit(1)[0].code
last_number = last_used_code.match(/\d+/).to_s.to_i + 1
else
last_used_code = 1
last_number = 1
end
code = "CLI%04d" % [last_number]

View File

@ -12,8 +12,9 @@ class PCustomerSheet < ApplicationRecord
belongs_to :p_customer
belongs_to :particular_bill, :class_name => "Particular"#, :dependent => :destroy
accepts_nested_attributes_for :particular_bill
belongs_to :particular_send, :class_name => "Particular"#, :dependent => :destroy
accepts_nested_attributes_for :particular_send
has_one :price_line_block, :as => :price_lineable

View File

@ -284,7 +284,7 @@ class PriceDocument < ApplicationRecord
:label => {:name => "Type", :reorder => false},
:stock_ok => {:name => "Stock mis à jour ?", :reorder => true},
:tva_type_name => {:name => "ID Type de TVA", :reorder => true},
:package_number => {:name => "Nombre de colis", :reorder => true},
#:package_number => {:name => "Nombre de colis", :reorder => true},
:d_number => {:name => "Numéro", :reorder => true},
:date => {:name => "Date", :reorder => true},
:cc_payment_end_at => {:name => "Date d'échance", :reorder => true},
@ -308,9 +308,9 @@ class PriceDocument < ApplicationRecord
self.tva_type.name
end
def package_number
self.price_line_block.package_number
end
# def package_number
# self.price_line_block.package_number
# end
def self.valid_sort
r = []

View File

@ -10,6 +10,9 @@ class PriceLine < ApplicationRecord
has_one :p_fournisseur, :through => :price_line_block
#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
default_scope { order('position ASC') }

View File

@ -543,7 +543,7 @@ class PriceLineBlock < ApplicationRecord
def ca_tot_lines_tva
r = 0.0
self.price_lines.each do |pl|
r+= pl.tot_amount_tva
r+= pl.tot_amount_tva if pl
end
return r
end

View File

@ -0,0 +1,4 @@
class PriceLinePArticle < ApplicationRecord
belongs_to :price_line
belongs_to :p_article
end

View File

@ -12,7 +12,8 @@
.actions=f.submit "sauvegarder", :class => "btn btn-primary"
- else
.p_article_serial_nums_form.field
=form.inputs do
= form.input :p_serial_num_type_id, :label => "type", as: :select, collection: PSerialNumType.pluck(:name, :id)
= form.input :value
.ml-5
.p_article_serial_nums_form.field
=form.inputs do
= form.input :p_serial_num_type_id, :label => "type", as: :select, collection: PSerialNumType.pluck(:name, :id)
= form.input :value

View File

@ -1,17 +1,32 @@
=semantic_form_for [:admin, @p_article], :remote => true do |f|
- if params[:controller] == "admin/p_articles"
=semantic_form_for [:admin, @p_article], :remote => true do |f|
.content
=f.inputs do
-if params[:p_product_ref_id]
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :selected => f.object.p_product_ref , :label => f.object.label_for(:p_product_ref)
-else
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => f.object.label_for(:p_product_ref)
-if PGrade::ACTIVATED
= f.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade"
%h4 Numero de série :
.p_article_serial_nums_form
= f.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", f, :p_article_serial_nums, {:class => "btn btn-primary"}
.content
=f.inputs do
-if params[:p_product_ref_id]
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :selected => f.object.p_product_ref , :label => f.object.label_for(:p_product_ref)
-else
= f.input :p_product_ref, as: :select, collection: PProductRef.all.distinct.pluck(:cc_name, :id), :label => f.object.label_for(:p_product_ref)
-if PGrade::ACTIVATED
= f.input :p_grade, as: :select, collection: PGrade.pluck(:grade, :id), :label => "Grade"
%h4 Numero de série :
.p_article_serial_nums_form
= f.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", f, :p_article_serial_nums, {:class => "btn btn-primary"}
.actions=f.submit "sauvegarder", :class => "btn btn-primary"
.actions=f.submit "sauvegarder", :class => "btn btn-primary"
- else
= form.inputs do
-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
-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"}

View File

@ -5,21 +5,31 @@
.content
.qi_row
.qi_pannel.qi_plain.padding.row
.col-2
.col-8
=@p_customer_sheet.p_customer.particular.organisation
-if @p_customer_sheet and @p_customer_sheet.state != "commande"
=#form.input :demande_type, :collection => ["Brouillon", "Demande de bon de commande","Demande de devis"], :as => :select, :include_blank => false, :label => "Type de demande :"
=form.input :state, :collection => ["AV BPA", "PAS BPA","BPA", "Traitée"], :as => :select, :include_blank => false, :label => "Statut :"
=form.input :past_id, :label => "N° système actuel"
=yield :discount
.col-2
=#form.input :state, :collection => ["AV BPA", "PAS BPA","BPA", "Traitée"], :as => :select, :include_blank => false, :label => "Statut :"
=#form.input :past_id, :label => "N° système actuel"
=yield :shipping_date
.col-8
=yield :particular
.qi_row
.qi_pannel.qi_plain.padding.row
nested form for particular send et bill qui crée à chaque fois un particular
ajouter accept nested attributed for particular dans pcustomer sheet
=yield :price_lines
.qi_row
.qi_pannel.qi_plain.padding.row
=yield :price_lines
.qi_row
.qi_pannel.qi_plain.padding.row
=yield :discount
.large_actions
.actions
=link_to "Annuler", admin_p_customer_sheets_path(), :class => "btn"

View File

@ -4,26 +4,24 @@
.qi_pannel.qi_plain.padding
=f.inputs do
.row.qi_cancel_margins
.col-sm-2
= f.input :p_product_cat_id, :label => "Catégorie produit :", :collection => PProductCat.all, :as => :select, :include_blank => false
.col-sm-2
%br
= f.input :enabled, :label => "Produit actif ?"
.col-sm-2
%br
= f.input :stockable, :label => "Produit stockable ?", :input_html => {:onclick => "$('#with_serial').toggle('slow');"}
.col-sm-2
%br
#with_serial
= f.input :with_serial_number, :label => "Avec n° de série ?"
.col-sm-2
=f.input :s_brand_id, :label => "Marque :", :collection => SBrand.all, :as => :select, :include_blank => true
=# f.input :stocked, :label => "Suivi de stock ?"
.col-sm-2
=#f.input :sorecop_cat, label: "Catgorie Sorecop :", :collection => SorecopCat.all, :as => :select, :include_blank => true
-if false
%table{:style => "width:100%"}
%tr
@ -108,9 +106,3 @@
}

View File

@ -45,7 +45,7 @@ PRICE_DOCUMENTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
-if @price_document.price_document_type_id == 6 or @price_document.price_document_type_id == 7
.row
.col-6
= f.input :date, :label => "Date de la facture achat :", :as => :date
= f.input :date, :label => "Date de la facture achat :", :as => :date, input_html: {value: Date.today}
.col-6
= f.input :supplier_document_date, :label => "Date du document fournisseur :", :as => :date
.col-6

View File

@ -18,7 +18,7 @@
.qi_row
=debug @price_document.price_line_block.price_lines.count
%table.table.table-striped
-if @price_document.label == "Réponse fournisseur"
@ -196,7 +196,7 @@
%table.table
%thead
%tr
%th
%th ID
%th Référence
%th Marque
%th Désignation
@ -205,47 +205,46 @@
%th TVA
%th Montant HT
%th Actions
%tbody
-price_line_block.price_lines.each do |price_line|
-price_line_block.price_lines.each do |price_line|
%tbody
%tr
%td
="##{price_line.id}"
-if price_line.p_articles.count == 0
%td{style: "background-color: red;"}
="##{price_line.id}"
- elsif price_line.p_articles.count < price_line.qte
%td{style: "background-color: orange"}
="##{price_line.id}"
- else
%td{style: "background-color: green"}
="##{price_line.id}"
%td
=price_line.ref
%td
=price_line.p_product_ref.p_product.s_brand.name
%td{class: "p_product_ref_cc_name_#{@price_document.id}"}
=link_to price_line.p_product_ref.cc_name, edit_admin_p_product_path(price_line.p_product_ref.p_product) if price_line.p_product_ref and price_line.p_product_ref.p_product
%td.numeraire{class: "price_line_qte_#{@price_document.id}"}
=price_line.qte
%td.numeraire{class: "price_line_price_u_ht_#{@price_document.id}"}
=number_to_currency price_line.price_u_ht
%td.numeraire
=price_line.tva_account_value.to_s+"%"
%td.numeraire
=number_to_currency price_line.tot_amount_ht
%td.actions
= 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"), new_admin_p_article_path(p_product_ref_id: price_line.p_product_ref.id), :remote => true
/ %td=# price_line.line_stocks.sum(:price_ht)
= 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
-price_line.p_articles.each do |p_article|
%tr
%td
%td="##{p_article.id}"
%td=p_article.p_product_ref.name
%td
- p_article.p_article_serial_nums.each do |sn|
="#{sn.p_serial_num_type.name} - #{sn.value} /"
.qi_row
-if current_admin.has_permission?("show-costs")

View File

@ -80,7 +80,7 @@
=content_for :discount do
-if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande")
-if !@avoir
= f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :", :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"}
= f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :"#, :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"}
= f.input :ct_tot_fdp_ht, :label => "Frais de port personnalisés :"

View File

@ -42,14 +42,14 @@ PRICE LINE BLOCKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
=# f.input :ct_creation_date, :label => "Date de commande (si différente de la date de création) :", :as => :date
.row
.col-6
= f.input :stock_entrance_date, :label => "Date d'entrée en stock :", :as => :date
= f.input :stock_entrance_date, :label => "Date d'entrée en stock :", :as => :date, input_html: {value: Date.today}
.row
.col-6
= f.input :customer_ref, :label => "Référence commande fournisseur :"
-if current_admin.has_permission?("customer-sheets-bl")
= f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"}
=# f.input :bl_comment, :label => "Commentaire à mettre sur le BL :", :input_html => {:style => "min-height:50px;height:50px;"}
-if @p_customer_sheet and @p_customer_sheet.p_customer and @p_customer_sheet.p_customer.p_customer_sheet_note?
%div
@ -71,17 +71,18 @@ PRICE LINE BLOCKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKKK
.qi_pannel.qi_plain.padding.price_line_block_footer{:style => "margin:20px 0;"}
-if !@p_customer_sheet or (@p_customer_sheet and @p_customer_sheet.state != "commande")
= f.input :cc_tot_amount_ht, label: "Somme HT des produits", input_html: {disabled: true}
-if !@avoir
= f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :", :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"}
= f.input :ct_tot_fdp_ht, :label => "Montant des frais de port HT (€) :"
=# f.input :ct_tot_discount_percent, :label => "Réduction pied de page (%) :", :input_html => {:class => "input_price_line_block_ct_tot_discount_percent"}
=# f.input :ct_tot_fdp_ht, :label => "Montant des frais de port HT (€) :"
-if !@avoir
-if current_admin.has_permission?("customer-sheets-bl")
= f.input :ct_nbr_ship, :label => "Nombre de colis :"
= f.input :cc_tot_amount_ttc, label: "Montant TTC à payer", :input_html => {disabled: true}
= f.input :cc_tot_amount_ht, label: "Montant HT à payer", input_html: {disabled: true}
= f.input :ct_tot_amount_ht, label: "Montant HT personnalisé"
=# f.input :ct_nbr_ship, :label => "Nombre de colis :"
= f.input :ct_tot_amount_ht, label: "Montant HT à payer"
= f.input :cc_tot_amount_ttc, label: "Montant TTC à payer", :input_html => {disabled: false}
-if current_admin.has_permission?("payments")

View File

@ -0,0 +1,9 @@
.mx-2.my-2
=semantic_form_for [:admin, @price_line], :remote => true do |f|
.content
=f.inputs do
.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
.actions=f.submit "Sauvegarder", :class => "btn btn-primary"

View File

@ -1,5 +1,3 @@
=semantic_form_for [:admin, @price_line], :remote => true do |form|
.content

View File

@ -1 +1 @@
show_pane_hover("<%= escape_javascript(render(:partial => "add_p_articles_form"))%>",700,900);
show_pane_hover("<%= escape_javascript(render(:partial => "add_p_article_form"))%>",700,900);

View File

@ -697,6 +697,7 @@ Rails.application.routes.draw do
end
collection do
get :add_p_article
end
end

View File

@ -0,0 +1,6 @@
class AddStockableToPProduct < ActiveRecord::Migration[6.0]
def change
add_column :p_products, :stockable, :boolean
add_column :p_products, :with_serial_number, :boolean
end
end

View File

@ -0,0 +1,12 @@
class CreatePriceLinePArticles < ActiveRecord::Migration[6.0]
def change
create_table :price_line_p_articles do |t|
t.belongs_to :p_article
t.belongs_to :price_line
t.timestamps
end
#add_reference :price_lines, :price_line_p_article, index: true
#add_reference :p_articles, :price_line_p_article, index: true
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_29_111104) do
ActiveRecord::Schema.define(version: 2021_11_02_105934) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -1930,6 +1930,8 @@ ActiveRecord::Schema.define(version: 2021_10_29_111104) do
t.boolean "conserve_proportion", default: false
t.boolean "frontpage", default: true
t.integer "sorecop_cat_id"
t.boolean "stockable"
t.boolean "with_serial_number"
t.index ["p_product_cat_id"], name: "index_p_products_on_p_product_cat_id"
t.index ["s_brand_id"], name: "index_p_products_on_s_brand_id"
end
@ -2463,6 +2465,15 @@ ActiveRecord::Schema.define(version: 2021_10_29_111104) do
t.index ["p_customer_id"], name: "index_price_line_blocks_on_p_customer_id"
end
create_table "price_line_p_articles", force: :cascade do |t|
t.bigint "p_article_id"
t.bigint "price_line_id"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["p_article_id"], name: "index_price_line_p_articles_on_p_article_id"
t.index ["price_line_id"], name: "index_price_line_p_articles_on_price_line_id"
end
create_table "price_line_resp_selects", force: :cascade do |t|
t.integer "price_line_demand_id"
t.integer "price_line_resp_id"

11
test/fixtures/price_line_p_articles.yml vendored Normal file
View File

@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the '{}' from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value

View File

@ -0,0 +1,7 @@
require 'test_helper'
class PriceLinePArticleTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end