From 7baa9a4435b4a951cad0efce96c25bc118bbe8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Mon, 30 Aug 2021 19:49:28 +0200 Subject: [PATCH] TVA rates fix --- .../(__TEMPLATE__)c | Bin 0 -> 5961 bytes .../admin/p_customer_sheets_controller.rb | 13 ++++++++----- .../admin/p_product_refs_controller.rb | 14 ++++++++------ app/models/p_customer.rb | 9 +++++++++ app/views/admin/price_lines/_form.html.haml | 2 +- 5 files changed, 26 insertions(+), 12 deletions(-) create mode 100644 .sass-cache/2008dff8cddf4c9967017d710d180856df6a3c9d/(__TEMPLATE__)c diff --git a/.sass-cache/2008dff8cddf4c9967017d710d180856df6a3c9d/(__TEMPLATE__)c b/.sass-cache/2008dff8cddf4c9967017d710d180856df6a3c9d/(__TEMPLATE__)c new file mode 100644 index 0000000000000000000000000000000000000000..e13aa0321643ab633d299c9ffc3efbd90872cbe3 GIT binary patch literal 5961 zcmbVQ+j85;5fxP_ULZ>py}Fr_WrlXNwpJEtNnY7ARmsF&yNan@muscXiylw|a6};s zVi*9lS8@3*`Gw>&@>9t#B#%k=;4&N%(n|Y84AIkbx~KbeHxBoY_m8aOqoZT)9yrd+ zbAIsLIS}2WL-!?r)^}e#=i-HXEWUPxbJ(?hRh8u436CN|PD3FG`CiKSo$QM{WQn;K zp5G5ea8{cZ8v6o;>cnCpJfD?&?e&L_>|feZ%wsQ#y+4mdR3_y&r{pdh@h}p78zm!2 z+R1Sz!WV8VLqcB5;gFvQ*b%s*N*38r3>^_hXJtw5PYY*q6?zBXKb(2*4M)Dnq!tpX z^=YYIzY5R;J`}z7+AMBbJB8Q27YMHmemM7hfwEn|7LA=h0dDmu$DxZBRZm1*h7A`y zy7)Zz7A%g`D?8-DKuEHY9NOZZK{`a)7yZf5n>mhg7q?tMcBoS^ltK#Jd#Zor9QU}d~~Bm?@6t%Ot&Uh z8}xp!{l#P3K7I4u`)_}L`o^}Ol)*uCTas3Sx|bdbLG%`IM3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b{> literal 0 HcmV?d00001 diff --git a/app/controllers/admin/p_customer_sheets_controller.rb b/app/controllers/admin/p_customer_sheets_controller.rb index f99ea9f..5729f1c 100644 --- a/app/controllers/admin/p_customer_sheets_controller.rb +++ b/app/controllers/admin/p_customer_sheets_controller.rb @@ -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" diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index c72e779..5648846 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -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 diff --git a/app/models/p_customer.rb b/app/models/p_customer.rb index 3fd7005..e1ee85d 100644 --- a/app/models/p_customer.rb +++ b/app/models/p_customer.rb @@ -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 diff --git a/app/views/admin/price_lines/_form.html.haml b/app/views/admin/price_lines/_form.html.haml index 9920ecb..67bd84d 100644 --- a/app/views/admin/price_lines/_form.html.haml +++ b/app/views/admin/price_lines/_form.html.haml @@ -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