From 1106178e38c132192830599dc06fc7d9e14b703d Mon Sep 17 00:00:00 2001 From: viehlieb Date: Tue, 21 Feb 2023 16:50:53 +0100 Subject: [PATCH] add price_per quantity unit to group order new --- Gemfile | 2 +- Gemfile.lock | 5 ++--- app/models/article.rb | 10 +++++++++- app/models/concerns/price_calculation.rb | 8 ++++++++ app/models/group_order.rb | 2 ++ app/models/supplier.rb | 1 + app/views/articles/_form.html.haml | 1 + app/views/articles/_sync.html.haml | 4 ++-- app/views/articles/_sync_table.html.haml | 6 ++++++ app/views/group_orders/_form.html.haml | 2 ++ config/locales/de.yml | 1 + config/locales/en.yml | 1 + config/locales/es.yml | 1 + config/locales/fr.yml | 1 + config/locales/nl.yml | 1 + spec/fixtures/bnn_file_02.bnn | 2 +- 16 files changed, 40 insertions(+), 8 deletions(-) diff --git a/Gemfile b/Gemfile index 1fda1f10..512ea260 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,7 @@ gem 'ice_cube' # At time of development 01-06-2022 mmddyyyy necessary fix for config_helper.rb form builder was not in rubygems so we pull from github, see: https://github.com/gregschmit/recurring_select/pull/152 gem 'recurring_select', git: 'https://github.com/gregschmit/recurring_select' # TODO: publish gem on github -gem 'foodsoft_article_import', git: 'https://git.local-it.org/Foodsoft/foodsoft_article_import', tag: 'v0.1' +gem 'foodsoft_article_import', git: 'https://git.local-it.org/Foodsoft/foodsoft_article_import', tag: 'v1.9' gem 'roo' gem 'roo-xls' gem 'spreadsheet' diff --git a/Gemfile.lock b/Gemfile.lock index 0c9eaf3d..3387fb74 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,10 @@ GIT remote: https://git.local-it.org/Foodsoft/foodsoft_article_import - revision: c7e432c247ca6aa327ae889d22f78227efed2479 - tag: v0.1 + revision: 573851e5497758e1d27d2199f03b939e6bda9e35 + tag: v1.9 specs: foodsoft_article_import (1.0.0) roo (~> 2.9.0) - simplecov GIT remote: https://github.com/gregschmit/recurring_select diff --git a/app/models/article.rb b/app/models/article.rb index a9449e87..7e7d7fa5 100644 --- a/app/models/article.rb +++ b/app/models/article.rb @@ -142,7 +142,14 @@ class Article < ApplicationRecord new_unit_quantity = new_article.unit_quantity new_unit = new_article.unit end - + puts " + " + "______________" + " + " + "______________" + " + " + "_____oha_________" + " + " + "#{new_article.unit_symbol}" + " + " + "______________"+ " + " + "______________"+ " + " + "______________" return Article.compare_attributes( { :name => [self.name, new_article.name], @@ -153,6 +160,7 @@ class Article < ApplicationRecord :tax => [self.tax, new_article.tax], :deposit => [self.deposit.to_f.round(2), new_article.deposit.to_f.round(2)], :price_per => [self.price_per.to_f.round(2), new_article.price_per.to_f.round(2)], + :unit_symbol => [self.unit_symbol, new_article.unit_symbol], # take care of different num-objects. :unit_quantity => [self.unit_quantity.to_s.to_f, new_unit_quantity.to_s.to_f], :note => [self.note.to_s, new_article.note.to_s] diff --git a/app/models/concerns/price_calculation.rb b/app/models/concerns/price_calculation.rb index 03b9a7ad..b7a18415 100644 --- a/app/models/concerns/price_calculation.rb +++ b/app/models/concerns/price_calculation.rb @@ -12,6 +12,14 @@ module PriceCalculation add_percent(gross_price, FoodsoftConfig[:price_markup]) end + def fc_price_per + if price_per > 0 + add_percent(add_percent(price_per, tax), FoodsoftConfig[:price_markup]) + else + fc_price + end + end + private def add_percent(value, percent) diff --git a/app/models/group_order.rb b/app/models/group_order.rb index c789ef4e..73c0e5d1 100644 --- a/app/models/group_order.rb +++ b/app/models/group_order.rb @@ -45,6 +45,8 @@ class GroupOrder < ApplicationRecord # Build hash with relevant data data[:order_articles][order_article.id] = { :price => order_article.article.fc_price, + :price_per => order_article.article.fc_price_per, + :unit_symbol => order_article.article.unit_symbol, :unit => order_article.article.unit_quantity, :quantity => (goa ? goa.quantity : 0), :others_quantity => order_article.quantity - (goa ? goa.quantity : 0), diff --git a/app/models/supplier.rb b/app/models/supplier.rb index 245e2620..8ae5ef42 100644 --- a/app/models/supplier.rb +++ b/app/models/supplier.rb @@ -112,6 +112,7 @@ class Supplier < ApplicationRecord if options[:outlist_absent] outlisted_articles += articles.undeleted.where.not(order_number: all_order_numbers + [nil]) end + # TODO: change price_per to scale factor return [updated_article_pairs, outlisted_articles, new_articles] end diff --git a/app/views/articles/_form.html.haml b/app/views/articles/_form.html.haml index 7cbd64cd..fbab5d48 100644 --- a/app/views/articles/_form.html.haml +++ b/app/views/articles/_form.html.haml @@ -1,5 +1,6 @@ = simple_form_for [@supplier, @article], :validate => true, :remote => true do |f| = f.hidden_field :shared_updated_on + = f.hidden_field :unit_symbol = f.hidden_field :supplier_id .modal-header = close_button :modal diff --git a/app/views/articles/_sync.html.haml b/app/views/articles/_sync.html.haml index 05945112..37584369 100644 --- a/app/views/articles/_sync.html.haml +++ b/app/views/articles/_sync.html.haml @@ -17,14 +17,14 @@ %i = t '.update.update_msg', count: @updated_article_pairs.size = t '.update.body' - = render 'sync_table', articles: @updated_article_pairs, field: 'articles', hidden_fields: %w(shared_updated_on) + = render 'sync_table', articles: @updated_article_pairs, field: 'articles', hidden_fields: %w(shared_updated_on unit_symbol) %hr/ - if @new_articles.any? %h2= t '.upnew.title' %p %i= t '.upnew.body_count', count: @new_articles.length - = render 'sync_table', articles: @new_articles, field: 'new_articles', hidden_fields: %w(shared_updated_on order_number availability) + = render 'sync_table', articles: @new_articles, field: 'new_articles', hidden_fields: %w(shared_updated_on order_number availability unit_symbol) %hr/ - if ignored_article_count > 0 diff --git a/app/views/articles/_sync_table.html.haml b/app/views/articles/_sync_table.html.haml index ac17adfa..4704ee79 100644 --- a/app/views/articles/_sync_table.html.haml +++ b/app/views/articles/_sync_table.html.haml @@ -8,6 +8,7 @@ %th= heading_helper Article, :unit %th= heading_helper Article, :unit_quantity, short: true %th= heading_helper Article, :price + %th= heading_helper Article, :price_per %th= heading_helper Article, :tax %th= heading_helper Article, :deposit %th= heading_helper Article, :article_category @@ -23,6 +24,7 @@ %td= article.unit %td= article.unit_quantity %td= number_to_currency article.price + %td= number_to_currency article.price_per.round(2) %td= number_to_percentage article.tax %td= number_to_currency article.deposit %td= article.article_category.name if article.article_category @@ -41,6 +43,10 @@ .input-prepend %span.add-on= t 'number.currency.format.unit' = form.text_field 'price', class: 'input-mini', style: 'width: 45px' + %td{:style => highlight_new(attrs, :price_per)} + .input-prepend + %span.add-on= t 'number.currency.format.unit' + = form.text_field 'price_per', class: 'input-mini', style: 'width: 45px' %td{:style => highlight_new(attrs, :tax)} .input-append = form.text_field 'tax', class: 'input-mini', style: 'width: 45px' diff --git a/app/views/group_orders/_form.html.haml b/app/views/group_orders/_form.html.haml index 3ffd583e..72e90584 100644 --- a/app/views/group_orders/_form.html.haml +++ b/app/views/group_orders/_form.html.haml @@ -77,6 +77,7 @@ %th{style: 'width:120px'}= heading_helper StockArticle, :supplier %th{style: "width:13px;"} %th{style: "width:4.5em;"}= t '.price' + %th{style: "width:4.5em;"}= t '.price_per' %th{style: "width:4.5em;"}= heading_helper Article, :unit - unless @order.stockit? %th{style: "width:70px;"}= heading_helper OrderArticle, :missing_units, short: true @@ -100,6 +101,7 @@ %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]) + %td= "#{number_to_currency(@ordering_data[:order_articles][order_article.id][:price_per])}/#{@ordering_data[:order_articles][order_article.id][:unit_symbol]||@ordering_data[:order_articles][order_article.id][:unit]}" %td= order_article.article.unit %td - if @order.stockit? diff --git a/config/locales/de.yml b/config/locales/de.yml index 5a1a5b35..ee96c7e9 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -1052,6 +1052,7 @@ de: action_save: Bestellung speichern new_funds: Neuer Kontostand price: Preis + price_per: Preis je Mengeneinheit (ohne Pfand) reset_article_search: Suche zurücksetzen search_article: Artikel suchen... sum_amount: Gesamtbestellmenge bisher diff --git a/config/locales/en.yml b/config/locales/en.yml index 59e94385..8a87ed2c 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1054,6 +1054,7 @@ en: action_save: Save order new_funds: New account balance price: Price + price_per: Price per quantity unit (without deposit) reset_article_search: Reset search search_article: Search for articles... sum_amount: Current amount diff --git a/config/locales/es.yml b/config/locales/es.yml index 620ec3bb..31372e7d 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -929,6 +929,7 @@ es: action_save: Guardar pedido new_funds: Nuevo balance de cuenta price: Precio + price_per: Precio por unidad de cantidad (sin depósito) reset_article_search: Reinicia la búsqueda search_article: Busca artículos... sum_amount: Cantidad actual diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 4dbdb864..07d9ab5f 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -678,6 +678,7 @@ fr: action_save: Enregistrer ta commande new_funds: Nouveau solde price: Prix + price_per: Prix par unité de quantité (sans consigne) reset_article_search: Réinitialiser la recherche search_article: Rechercher des produits... sum_amount: Quantité déjà commandée diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 4c97dda4..8da6126f 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -1024,6 +1024,7 @@ nl: action_save: Bestelling opslaan new_funds: Nieuw tegoed price: Prijs + price_per: Prijs per hoeveelheidseenheid (zonder statiegeld) reset_article_search: Alles tonen search_article: Artikelen zoeken... sum_amount: Huidig totaalbedrag diff --git a/spec/fixtures/bnn_file_02.bnn b/spec/fixtures/bnn_file_02.bnn index e3dba5bb..dfcdd7a2 100644 --- a/spec/fixtures/bnn_file_02.bnn +++ b/spec/fixtures/bnn_file_02.bnn @@ -1,2 +1,2 @@ BNN;3;0;Naturkost Nord, Hamburg;T;Angebot Nr. 0922;EUR;20220905;20221001;20220825;837;1 -1;;;;4280001958081;4280001958203;Tomatoes;organic;;;med;;GR;C%;DE-?KO-001;120;1302;10;55;;1;;20;500 g;1;N;930190;99260;;1,41;;;;1;;;4,49;1,20;J;;2;3;;;;;;;;;;;;;;;;;;;A;;;;;g;28,571;; \ No newline at end of file +1;;;;4280001958081;4280001958203;Tomatoes;organic;;;med;;GR;C%;DE-?KO-001;120;1302;10;55;;1;;20;500 g;1;N;930190;99260;;1,41;;;;1;;;4,49;1,20;J;;2;3;;;;;;;;;;;;;;;;;;;A;;;;;Kg;2;; \ No newline at end of file