TVA rates fix

This commit is contained in:
Barnabé 2021-08-30 19:49:28 +02:00
parent c870d58122
commit 7baa9a4435
5 changed files with 26 additions and 12 deletions

View File

@ -174,12 +174,14 @@ class Admin::PCustomerSheetsController < ApplicationController
@p_customer_sheet.admin = current_admin
@p_customer = @p_customer_sheet.p_customer
if @p_customer_sheet.save
@p_customer_sheets = PCustomerSheet.order(:id).all
redirect_to admin_p_customer_sheet_path(@p_customer_sheet)
else
@p_customer = @p_customer_sheet.price_line_block.p_customer
render action: "new"
end
@ -189,13 +191,14 @@ class Admin::PCustomerSheetsController < ApplicationController
def update
@p_customer_sheet = PCustomerSheet.find(params[:id])
@p_customer = @p_customer_sheet.p_customer
if @p_customer_sheet.update_attributes(params.require(:p_customer_sheet).permit!)
@p_customer_sheets = PCustomerSheet.order(:id).all
@p_customer = @p_customer_sheet.price_line_block.p_customer
redirect_to admin_p_customer_sheet_path(@p_customer_sheet)
else
render action: "edit"

View File

@ -138,27 +138,29 @@ class Admin::PProductRefsController < ApplicationController
def get_infos
@p_product_ref = PProductRef.find(params[:id])
if params[:type] == "price"
price = @p_product_ref.get_price(:p_customer_id => params[:p_customer_id], :qte => params[:qte])
puts params[:p_fournisseur_id]
if params[:p_customer_id].to_s != ""
p_customer = PCustomer.find(params[:p_customer_id])
accounting_zone_id = p_customer.accounting_zone_id
if p_customer.tva_rate
tva_account_id = p_customer.tva_rate.id
tva_account_value = p_customer.tva_rate.rate
else
tva_account_id = @p_product_ref.p_product.tva_rate(accounting_zone_id).id if @p_product_ref.p_product.tva_rate(accounting_zone_id)
tva_account_value = @p_product_ref.p_product.tva_rate(accounting_zone_id).rate if @p_product_ref.p_product.tva_rate(accounting_zone_id)
end
elsif params[:p_fournisseur_id].to_s != ""
p_fournisseur = PFournisseur.find(params[:p_fournisseur_id])
accounting_zone_id = p_fournisseur.accounting_zone_id

View File

@ -192,6 +192,15 @@ class PCustomer < ApplicationRecord
end
def tva_rate
if tva = TvaRate.where(:accounting_zone_id => self.accounting_zone_id).first
return tva
else
return nil
end
end
def update_caches

View File

@ -118,7 +118,7 @@
-else
%label Taux de TVA :
%br
=select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id", :disabled => true
=select_tag :tva_account_id, options_from_collection_for_select(TvaRate.where(:accounting_zone_id => (@p_customer ? @p_customer.accounting_zone_id : nil)).all, "id", "member_label", form.object.tva_account_id), :class => "input_price_line_tva_account_id" #, :disabled => true