From 46e6bea49ed10a3138a65c50a543520b48a0c968 Mon Sep 17 00:00:00 2001 From: viehlieb Date: Fri, 29 Sep 2023 10:12:38 +0200 Subject: [PATCH] fix deposit is net value --- app/models/order.rb | 4 +++- app/views/finance/balancing/_summary.haml | 3 +++ app/views/orders/show.html.haml | 4 ++-- config/locales/de.yml | 3 ++- spec/models/article_spec.rb | 5 ++++- 5 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/models/order.rb b/app/models/order.rb index 69340a4d..e071bee0 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -207,7 +207,7 @@ class Order < ApplicationRecord # :fc, guess what... def sum(type = :gross) total = 0 - if %i[net gross net_deposit gross_without_deposit fc_deposit deposit fc].include?(type) + if %i[net gross net_deposit gross_without_deposit fc_without_deposit fc_deposit deposit fc].include?(type) for oa in order_articles.ordered.includes(:article, :article_price) quantity = oa.units * oa.price.unit_quantity case type @@ -219,6 +219,8 @@ class Order < ApplicationRecord total += quantity * oa.price.gross_price_without_deposit when :fc total += quantity * oa.price.fc_price + when :fc_without_deposit + total += quantity * oa.price.fc_price_without_deposit when :net_deposit total += quantity * oa.price.net_deposit_price when :fc_deposit diff --git a/app/views/finance/balancing/_summary.haml b/app/views/finance/balancing/_summary.haml index 9de36756..42f3e3ed 100644 --- a/app/views/finance/balancing/_summary.haml +++ b/app/views/finance/balancing/_summary.haml @@ -10,6 +10,9 @@ %tr %td= t('.gross_amount') %td.numeric= number_to_currency(order.sum(:gross_without_deposit)) + %tr + %td= t('.fc_amount') + %td.numeric= number_to_currency(order.sum(:fc_without_deposit)) %tr %td= t('.deposit') %td.numeric= number_to_currency(order.sum(:deposit)) diff --git a/app/views/orders/show.html.haml b/app/views/orders/show.html.haml index e76db249..1587f8e1 100644 --- a/app/views/orders/show.html.haml +++ b/app/views/orders/show.html.haml @@ -32,8 +32,8 @@ = raw t '.description2', ordergroups: ordergroup_count(@order), article_count: @order.order_articles.ordered.count, - net_sum: number_to_currency(@order.sum(:net)), - gross_sum: number_to_currency(@order.sum(:gross)) + net_sum: number_to_currency(@order.sum(:net) + @order.sum(:net_deposit)), + gross_sum: number_to_currency(@order.sum(:fc)) - unless @order.comments.blank? = link_to t('.comments_link'), '#comments' diff --git a/config/locales/de.yml b/config/locales/de.yml index 39340578..13a2e3dc 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -934,6 +934,7 @@ de: net_deposit: 'Pfand netto:' fc_deposit: 'Pfand FC-Betrag:' fc_profit: FC Gewinn + fc_amount: FC-Betrag (brutto) gross_amount: 'Bruttobetrag:' groups_amount: 'Gruppenbeträge:' net_amount: 'Nettobetrag:' @@ -1635,7 +1636,7 @@ de: pickup: und kann am %{pickup} abgeholt werden starts: läuft von %{starts} starts_ends: läuft von %{starts} bis %{ends} - description2: "%{ordergroups} haben %{article_count} Artikel mit einem Gesamtwert von %{net_sum} / %{gross_sum} (netto / brutto) bestellt." + description2: "%{ordergroups} haben %{article_count} Artikel mit einem Gesamtwert von %{net_sum} / %{gross_sum} (netto / brutto + fc + Pfand) bestellt." group_orders: 'Gruppenbestellungen:' search_placeholder: articles: Suche nach Artikeln ... diff --git a/spec/models/article_spec.rb b/spec/models/article_spec.rb index 3a810827..91a2f8ea 100644 --- a/spec/models/article_spec.rb +++ b/spec/models/article_spec.rb @@ -64,7 +64,10 @@ describe Article do article.tax = 12 expect(article.gross_price).to eq((article.price * 1.12).round(2)) article.deposit = 1.20 - expect(article.gross_price).to eq(((article.price + 1.20) * 1.12).round(2)) + if FoodsoftConfig[:group_order_invoices]&.[](:separate_deposits) + expect(article.gross_price_without_deposit).to eq((article.price * 1.12 + 1.20).round(2)) + expect(article.gross_price).to eq(((article.price + 1.20) * 1.12).round(2)) + end end it 'gross price >= net price' do