From a5c1251e7f7e5a0af718cd4744712611f01408c0 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Fri, 6 Dec 2024 00:29:31 +0100 Subject: [PATCH 01/15] Update _form.html.haml: display deposit and tolerance only if necessary --- app/views/group_orders/_form.html.haml | 51 ++++++++++++++++---------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 9061bdf85..4e81da5b0 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -77,11 +77,15 @@ %th{style: 'width:120px'}= heading_helper StockArticle, :supplier %th{style: "width:13px;"} %th{style: "width:4.5em;"}= t '.price' + - if @order.has_deposit? + %th{style: "width:4.5em;"}= t '.contains_deposit' %th{style: "width:4.5em;"}= heading_helper Article, :unit - unless @order.stockit? - %th{style: "width:70px;"}= heading_helper OrderArticle, :missing_units, short: true + - if @order.has_tolerance? + %th{style: "width:70px;"}= heading_helper OrderArticle, :missing_units, short: true %th#col_required= heading_helper GroupOrderArticle, :quantity - %th#col_tolerance= heading_helper GroupOrderArticle, :tolerance + - if @order.has_tolerance? + %th#col_tolerance= heading_helper GroupOrderArticle, :tolerance - else %th(style="width:20px")= heading_helper StockArticle, :available %th#col_required= heading_helper GroupOrderArticle, :quantity @@ -100,35 +104,44 @@ %td= truncate order_article.article.supplier.name, length: 15 %td= h order_article.article.origin %td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price]) + - if @order.has_deposit? + %td= number_to_currency(order_article.article.deposit * (1+order_article.article.tax/100 )) if order_article.article.deposit>0 %td= order_article.article.unit - %td - - if @order.stockit? - = @ordering_data[:order_articles][order_article.id][:quantity_available] - - else - %span{id: "missing_units_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:missing_units] + - if @order.has_tolerance? || @order.stockit? + %td + - if @order.stockit? + = @ordering_data[:order_articles][order_article.id][:quantity_available] + - else + %span{id: "missing_units_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:missing_units] %td.quantity %input{id: "q_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][quantity]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:quantity], 'data-min' => (@ordering_data[:order_articles][order_article.id][:quantity] if @order.boxfill?), 'data-max' => (@ordering_data[:order_articles][order_article.id][:quantity]+@ordering_data[:order_articles][order_article.id][:missing_units] if @order.boxfill?)}/ %span.used{id: "q_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_quantity] - + - %span.unused{id: "q_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity] + - if order_article.article.unit_quantity > 1 + + + %span.unused{id: "q_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity] + - else + %span{ style: "color: transparent;" } + 0 .btn-group %a.btn.btn-ordering{'data-increase_quantity' => order_article.id} %i.icon-plus %a.btn.btn-ordering{'data-decrease_quantity' => order_article.id} %i.icon-minus - %td.tolerance{style: ('display:none' if @order.stockit?)} - %input{id: "t_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:tolerance], 'data-min' => (@ordering_data[:order_articles][order_article.id][:tolerance] if @order.boxfill?)}/ - - if (@ordering_data[:order_articles][order_article.id][:unit] > 1) - %span.used{id: "t_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_tolerance] - + - %span.unused{id: "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance] + - if @order.has_tolerance? + %td.tolerance{style: ('display:none' if @order.stockit?)} + %input{id: "t_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:tolerance], 'data-min' => (@ordering_data[:order_articles][order_article.id][:tolerance] if @order.boxfill?)}/ + - if (@ordering_data[:order_articles][order_article.id][:unit] > 1) + %span.used{id: "t_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_tolerance] + + + %span.unused{id: "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance] + - else + %span{ style: "color: transparent;" } + 0 .btn-group - %a.btn.btn-ordering{'data-increase_tolerance' => order_article.id} - %i.icon-plus - %a.btn.btn-ordering{'data-decrease_tolerance' => order_article.id} - %i.icon-minus + %a.btn.btn-ordering{'data-increase_tolerance' => order_article.id} + %i.icon-plus + %a.btn.btn-ordering{'data-decrease_tolerance' => order_article.id} + %i.icon-minus %td{id: "td_price_#{order_article.id}", style: "text-align:right; padding-right:10px; width:4em"} %span{id: "price_#{order_article.id}_display"}= number_to_currency(@ordering_data[:order_articles][order_article.id][:total_price]) From 96092fb0d6d7a9e14d0bae2dfdfad2a1ac3b89b6 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Fri, 6 Dec 2024 00:41:42 +0100 Subject: [PATCH 02/15] Update _form.html.haml: identation corrected, wrong else for tolarance removed --- app/views/group_orders/_form.html.haml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 4e81da5b0..9bebeab08 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -133,11 +133,9 @@ %input{id: "t_#{order_article.id}", name: "group_order[group_order_articles_attributes][#{order_article.id}][tolerance]", type: "hidden", value: @ordering_data[:order_articles][order_article.id][:tolerance], 'data-min' => (@ordering_data[:order_articles][order_article.id][:tolerance] if @order.boxfill?)}/ - if (@ordering_data[:order_articles][order_article.id][:unit] > 1) %span.used{id: "t_used_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:used_tolerance] - + - %span.unused{id: "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance] - - else - %span{ style: "color: transparent;" } + 0 - .btn-group + + + %span.unused{id: "t_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:tolerance] - @ordering_data[:order_articles][order_article.id][:used_tolerance] + .btn-group %a.btn.btn-ordering{'data-increase_tolerance' => order_article.id} %i.icon-plus %a.btn.btn-ordering{'data-decrease_tolerance' => order_article.id} From 6621aac7a1fec1672c0a5ddbae762ae515a164ae Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Fri, 6 Dec 2024 00:46:59 +0100 Subject: [PATCH 03/15] Update order.rb: added methods has_deposit? and has_tolerance? --- app/models/order.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/models/order.rb b/app/models/order.rb index 23c19baab..95585618a 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -189,6 +189,14 @@ def articles_sort_by_category end end + def has_deposit? + order_articles.any? { |oa| oa.article.deposit != 0 } + end + + def has_tolerance? + order_articles.any? { |oa| oa.article.unit_quantity > 1 } + end + # Returns the defecit/benefit for the foodcoop # Requires a valid invoice, belonging to this order # FIXME: Consider order.foodcoop_result From e853e19d320053bb89df17d88a8ac7ec751fd7ca Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Fri, 6 Dec 2024 01:03:25 +0100 Subject: [PATCH 04/15] Update _form.html.haml: use %span.unused for hidden unused text --- app/views/group_orders/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 9bebeab08..5d8733dd7 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -121,7 +121,7 @@ + %span.unused{id: "q_unused_#{order_article.id}"}= @ordering_data[:order_articles][order_article.id][:quantity] - @ordering_data[:order_articles][order_article.id][:used_quantity] - else - %span{ style: "color: transparent;" } + 0 + %span.unused{style: "color: transparent;"} + 0 .btn-group %a.btn.btn-ordering{'data-increase_quantity' => order_article.id} %i.icon-plus From 5bfeff865b0ec9bb759a607c336969c81c984044 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:47:36 +0100 Subject: [PATCH 05/15] Update price_calculation.rb: add gross_deposit and fc_deposit --- app/models/concerns/price_calculation.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index 8d56d6715..4c6f82ae7 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -12,6 +12,15 @@ def fc_price add_percent(gross_price, FoodsoftConfig[:price_markup].to_i) end + # deposit + def gross_deposit + add_percent(deposit, tax) + end + + def fc_deposit + add_percent(gross_deposit, FoodsoftConfig[:price_markup]) + end + private def add_percent(value, percent) From c6dad407c6e2260e89fa311140be5def04a85ae6 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Mon, 16 Dec 2024 23:59:32 +0100 Subject: [PATCH 06/15] Update _form.html.haml: display fc_deposit --- app/views/group_orders/_form.html.haml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 5d8733dd7..1f93071e7 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -105,7 +105,8 @@ %td= h order_article.article.origin %td= number_to_currency(@ordering_data[:order_articles][order_article.id][:price]) - if @order.has_deposit? - %td= number_to_currency(order_article.article.deposit * (1+order_article.article.tax/100 )) if order_article.article.deposit>0 + - deposit = order_article.article.fc_deposit + %td= number_to_currency(deposit) if deposit>0 %td= order_article.article.unit - if @order.has_tolerance? || @order.stockit? %td From 17bdf060f90178b5b28e77476283b3a37e347259 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 00:02:33 +0100 Subject: [PATCH 07/15] Update order.rb: has_deposit true only for positive deposit --- app/models/order.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/order.rb b/app/models/order.rb index 95585618a..db2289f93 100644 --- a/app/models/order.rb +++ b/app/models/order.rb @@ -190,7 +190,7 @@ def articles_sort_by_category end def has_deposit? - order_articles.any? { |oa| oa.article.deposit != 0 } + order_articles.any? { |oa| oa.article.deposit > 0 } end def has_tolerance? From ee949bb0affe0f9a96b10574c3163a32dbc31f4d Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:38:30 +0100 Subject: [PATCH 08/15] Update price_calculation.rb: no markup on deposit (optionally?) --- app/models/concerns/price_calculation.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index 4c6f82ae7..94ebfc503 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -3,22 +3,30 @@ module PriceCalculation # Gross price = net price + deposit + tax. # @return [Number] Gross price. - def gross_price - add_percent(price + deposit, tax) + def gross_price(include_deposit=TRUE) + if include_depost + add_percent(price + deposit, tax) + else + add_percent(price, tax) + end end # @return [Number] Price for the foodcoop-member. def fc_price - add_percent(gross_price, FoodsoftConfig[:price_markup].to_i) + add_percent(gross_price(include_deposit=FALSE), FoodsoftConfig[:price_markup]) + fc_deposit end - # deposit def gross_deposit add_percent(deposit, tax) end def fc_deposit - add_percent(gross_deposit, FoodsoftConfig[:price_markup]) + deposit_with_markup = FALSE # FoodsoftConfig[:deposit_with_markup] + if deposit_with_markup + add_percent(gross_deposit, FoodsoftConfig[:price_markup]) + else + gross_deposit + end end private From 268b5cb03067aadbb1972c79d53e15d66f32f671 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:39:57 +0100 Subject: [PATCH 09/15] Update price_calculation.rb: ident corr. --- app/models/concerns/price_calculation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index 94ebfc503..ee36b2633 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -13,7 +13,7 @@ def gross_price(include_deposit=TRUE) # @return [Number] Price for the foodcoop-member. def fc_price - add_percent(gross_price(include_deposit=FALSE), FoodsoftConfig[:price_markup]) + fc_deposit + add_percent(gross_price(include_deposit=FALSE), FoodsoftConfig[:price_markup]) + fc_deposit end def gross_deposit From c7d479acfb9ebcbc7eb4e73efaa0d46879136cff Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:40:55 +0100 Subject: [PATCH 10/15] Update price_calculation.rb: ident 2 --- app/models/concerns/price_calculation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index ee36b2633..e021b7ba7 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -13,7 +13,7 @@ def gross_price(include_deposit=TRUE) # @return [Number] Price for the foodcoop-member. def fc_price - add_percent(gross_price(include_deposit=FALSE), FoodsoftConfig[:price_markup]) + fc_deposit + add_percent(gross_price(include_deposit=FALSE), FoodsoftConfig[:price_markup]) + fc_deposit end def gross_deposit From f2868fe4e741eeca9fa297110362535f9912a645 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:56:35 +0100 Subject: [PATCH 11/15] Update price_calculation.rb: typo --- app/models/concerns/price_calculation.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index e021b7ba7..d2bb6bf60 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -3,8 +3,8 @@ module PriceCalculation # Gross price = net price + deposit + tax. # @return [Number] Gross price. - def gross_price(include_deposit=TRUE) - if include_depost + def gross_price(include_deposit = TRUE) + if include_deposit add_percent(price + deposit, tax) else add_percent(price, tax) @@ -13,7 +13,7 @@ def gross_price(include_deposit=TRUE) # @return [Number] Price for the foodcoop-member. def fc_price - add_percent(gross_price(include_deposit=FALSE), FoodsoftConfig[:price_markup]) + fc_deposit + add_percent(gross_price(include_deposit = FALSE), FoodsoftConfig[:price_markup]) + fc_deposit end def gross_deposit From 9f11da4c53dda39e95e33aaf3c5dfae63afb41be Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:57:22 +0100 Subject: [PATCH 12/15] Update price_calculation.rb: lc true/false --- app/models/concerns/price_calculation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index d2bb6bf60..be2069a85 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -3,7 +3,7 @@ module PriceCalculation # Gross price = net price + deposit + tax. # @return [Number] Gross price. - def gross_price(include_deposit = TRUE) + def gross_price(include_deposit = true) if include_deposit add_percent(price + deposit, tax) else @@ -13,7 +13,7 @@ def gross_price(include_deposit = TRUE) # @return [Number] Price for the foodcoop-member. def fc_price - add_percent(gross_price(include_deposit = FALSE), FoodsoftConfig[:price_markup]) + fc_deposit + add_percent(gross_price(include_deposit = false), FoodsoftConfig[:price_markup]) + fc_deposit end def gross_deposit From 2ec322e77f4d9e52832732b0509f92562151dc8b Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:58:10 +0100 Subject: [PATCH 13/15] Update price_calculation.rb: lc false --- app/models/concerns/price_calculation.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index be2069a85..e8d806bb2 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -21,7 +21,7 @@ def gross_deposit end def fc_deposit - deposit_with_markup = FALSE # FoodsoftConfig[:deposit_with_markup] + deposit_with_markup = false # FoodsoftConfig[:deposit_with_markup] if deposit_with_markup add_percent(gross_deposit, FoodsoftConfig[:price_markup]) else From b5967b49d6b4cd4fed07773689610c9fa2378184 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:31:21 +0100 Subject: [PATCH 14/15] Update price_calculation.rb: use FoodsoftConfig[:deposit_with_markup] --- app/models/concerns/price_calculation.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index e8d806bb2..e55f72728 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -21,8 +21,7 @@ def gross_deposit end def fc_deposit - deposit_with_markup = false # FoodsoftConfig[:deposit_with_markup] - if deposit_with_markup + if FoodsoftConfig[:deposit_with_markup] || false add_percent(gross_deposit, FoodsoftConfig[:price_markup]) else gross_deposit From 567217f140ea54fe5309b3f616bf98655ce9e644 Mon Sep 17 00:00:00 2001 From: mjavurek <57668028+mjavurek@users.noreply.github.com> Date: Tue, 17 Dec 2024 13:34:03 +0100 Subject: [PATCH 15/15] Update price_calculation.rb: use : instead of = for bool args --- app/models/concerns/price_calculation.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index e55f72728..fe03569ed 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -3,7 +3,7 @@ module PriceCalculation # Gross price = net price + deposit + tax. # @return [Number] Gross price. - def gross_price(include_deposit = true) + def gross_price(include_deposit: true) if include_deposit add_percent(price + deposit, tax) else @@ -13,7 +13,7 @@ def gross_price(include_deposit = true) # @return [Number] Price for the foodcoop-member. def fc_price - add_percent(gross_price(include_deposit = false), FoodsoftConfig[:price_markup]) + fc_deposit + add_percent(gross_price(include_deposit: false), FoodsoftConfig[:price_markup]) + fc_deposit end def gross_deposit