fix deposit is net value

This commit is contained in:
viehlieb 2023-09-29 10:12:38 +02:00
parent b425d97876
commit 46e6bea49e
5 changed files with 14 additions and 5 deletions

View file

@ -207,7 +207,7 @@ class Order < ApplicationRecord
# :fc, guess what... # :fc, guess what...
def sum(type = :gross) def sum(type = :gross)
total = 0 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) for oa in order_articles.ordered.includes(:article, :article_price)
quantity = oa.units * oa.price.unit_quantity quantity = oa.units * oa.price.unit_quantity
case type case type
@ -219,6 +219,8 @@ class Order < ApplicationRecord
total += quantity * oa.price.gross_price_without_deposit total += quantity * oa.price.gross_price_without_deposit
when :fc when :fc
total += quantity * oa.price.fc_price total += quantity * oa.price.fc_price
when :fc_without_deposit
total += quantity * oa.price.fc_price_without_deposit
when :net_deposit when :net_deposit
total += quantity * oa.price.net_deposit_price total += quantity * oa.price.net_deposit_price
when :fc_deposit when :fc_deposit

View file

@ -10,6 +10,9 @@
%tr %tr
%td= t('.gross_amount') %td= t('.gross_amount')
%td.numeric= number_to_currency(order.sum(:gross_without_deposit)) %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 %tr
%td= t('.deposit') %td= t('.deposit')
%td.numeric= number_to_currency(order.sum(:deposit)) %td.numeric= number_to_currency(order.sum(:deposit))

View file

@ -32,8 +32,8 @@
= raw t '.description2', = raw t '.description2',
ordergroups: ordergroup_count(@order), ordergroups: ordergroup_count(@order),
article_count: @order.order_articles.ordered.count, article_count: @order.order_articles.ordered.count,
net_sum: number_to_currency(@order.sum(:net)), net_sum: number_to_currency(@order.sum(:net) + @order.sum(:net_deposit)),
gross_sum: number_to_currency(@order.sum(:gross)) gross_sum: number_to_currency(@order.sum(:fc))
- unless @order.comments.blank? - unless @order.comments.blank?
= link_to t('.comments_link'), '#comments' = link_to t('.comments_link'), '#comments'

View file

@ -934,6 +934,7 @@ de:
net_deposit: 'Pfand netto:' net_deposit: 'Pfand netto:'
fc_deposit: 'Pfand FC-Betrag:' fc_deposit: 'Pfand FC-Betrag:'
fc_profit: FC Gewinn fc_profit: FC Gewinn
fc_amount: FC-Betrag (brutto)
gross_amount: 'Bruttobetrag:' gross_amount: 'Bruttobetrag:'
groups_amount: 'Gruppenbeträge:' groups_amount: 'Gruppenbeträge:'
net_amount: 'Nettobetrag:' net_amount: 'Nettobetrag:'
@ -1635,7 +1636,7 @@ de:
pickup: und kann am %{pickup} abgeholt werden pickup: und kann am %{pickup} abgeholt werden
starts: läuft von %{starts} starts: läuft von %{starts}
starts_ends: läuft von %{starts} bis %{ends} 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:' group_orders: 'Gruppenbestellungen:'
search_placeholder: search_placeholder:
articles: Suche nach Artikeln ... articles: Suche nach Artikeln ...

View file

@ -64,7 +64,10 @@ describe Article do
article.tax = 12 article.tax = 12
expect(article.gross_price).to eq((article.price * 1.12).round(2)) expect(article.gross_price).to eq((article.price * 1.12).round(2))
article.deposit = 1.20 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 end
it 'gross price >= net price' do it 'gross price >= net price' do