Skip to content

Commit

Permalink
article data UI for new unit handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Ostler, Leonard committed Feb 20, 2022
1 parent 16eb988 commit 979eebc
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 10 deletions.
15 changes: 15 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,21 @@ class Article < ApplicationRecord
before_save :update_price_history
before_destroy :check_article_in_use

attr_accessor :unit_offered_by_supplier
attr_accessor :unit_description

attr_accessor :unit_quantifier
attr_accessor :base_unit
attr_accessor :price_unit
attr_accessor :goa_granularity
attr_accessor :goa_unit
attr_accessor :billing_unit
attr_accessor :min_order_quantity

def test_attribute
"hhhhh"
end

def self.ransackable_attributes(auth_object = nil)
%w(id name supplier_id article_category_id unit note manufacturer origin unit_quantity order_number)
end
Expand Down
5 changes: 2 additions & 3 deletions app/views/articles/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@

= render partial: 'shared/article_fields_units', locals: {f: f}

= render partial: 'shared/article_fields_price', locals: {f: f}

= f.input :note
= f.association :article_category
/ TODO labels
= render partial: 'shared/article_fields_price', locals: {f: f}

= f.input :origin
= f.input :manufacturer
= f.input :order_number
Expand Down
14 changes: 12 additions & 2 deletions app/views/shared/_article_fields_price.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,30 @@
.input-prepend
%span.add-on= t 'number.currency.format.unit'
= f.input_field :price, class: 'input-mini'
= f.input :price_unit, label: 'per' do
= f.input_field :price_unit, class: 'input-small', title: "unit dropdown"
.fold-line
= f.input :tax do
.input-append
= f.input_field :tax, class: 'input-mini'
%span.add-on %
.fold-line
= f.input :deposit do
.input-prepend
%span.add-on= t 'number.currency.format.unit'
= f.input_field :deposit, class: 'input-mini'
.fold-line
.control-group
%label.control-label{for: 'article_fc_price'}
= Article.human_attribute_name(:fc_price)
.controls.control-text#article_fc_price
.controls.control-text#article_fc_price{:style => 'width:8em'}
= number_to_currency(f.object.fc_price) rescue nil
.control-group
%label.control-label{for: 'fc_base_price'}
= "Base price"
.controls.control-text#fc_base_price
/ TODO: calculate and display base price per base unit
= number_to_currency(f.object.fc_price) rescue nil
= "/ kg"

-# do this inline, since it's being used in ajax forms only
- field = f.object.class.model_name.to_s.underscore
Expand Down
45 changes: 40 additions & 5 deletions app/views/shared/_article_fields_units.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,41 @@
-# use the local 'f', or supply 'f_uq' and 'f_unit' for more control (like in balancing)
- content_for :javascript do
:javascript
var parcel = $($.parseHTML("#{escape_javascript(render('shared/parcel'))}"));
var parcels = #{raw @parcels.to_json};

$(function() {
$(document).on('touchclick', 'a[data-add-parcel]', function() {
parcel.clone().appendTo('#parcels');
return false;
});

$(document).on('touchclick', 'a[data-remove-parcel]', function() {
$(this).parents('tr').remove();
return false;
});
});

.fold-line
= (f_uq rescue f).input :unit_quantity, label: Article.human_attribute_name(:unit),
input_html: {class: 'input-mini', title: Article.human_attribute_name(:unit_quantity)}
= (f_unit rescue f).input :unit, label: '&times;'.html_safe,
input_html: {class: 'input-mini', title: Article.human_attribute_name(:unit)}
= f.input :unit_offered_by_supplier, label: "Unit offered by supplier", input_html: {class: 'input-mini', title: "unit in which article can be ordered from supplier"}
= f.input :unit_description, label: "descr.", input_html: {class: 'input-mini', title: "free text unit"}
= link_to t('.add_content'), '#', 'data-add-parcel' => true, class: 'btn', title: "add content"
.fold-line
= "."
.fold-line
.control-group
%label.control-label{for: 'parcels'}
= "Parcels"
%table#fc_base_price{:class => "controls"}
%tbody
= render :partial => 'shared/parcel', :collection => [1]
.fold-line
= f.input :min_order_quantity, label: "Mininum order quantity" do
.input-append
= f.input_field :min_order_quantity, class: 'input-mini', title: "total minimum order quantity for this article"
/ TODO: replace 'pck' with unit offered by supplier
%span.add-on pck
.fold-line
= f.input :billing_unit, label: "Billing unit", input_html: {class: 'input-small', title: "unit dropdown"}
.fold-line
= f.input :goa_granularity, label: "Allow orders per", input_html: {class: 'input-mini', title: "steps in which ordergroups can order this article"}
= f.input :goa_unit, label: '&times;'.html_safe, input_html: {class: 'input-small', title: "unit dropdown"}
8 changes: 8 additions & 0 deletions app/views/shared/_parcel.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
%tr
%td= text_field_tag 'articles[parcels][unit_quantifier]', nil, class: 'input-mini', title: "unit quantifier"
%td= '&times;'.html_safe
%td= text_field_tag 'articles[parcels][unit]', nil, class: 'input-mini', title: "unit dropdown"
%td.actions{style: 'width:1em'}
= link_to t('.remove'), method: :delete, 'data-remove-parcel' => true, title: 'remove', class: 'btn btn-danger btn-mini' do
= glyph :remove
%td= link_to t('.add_content'), '#', 'data-add-parcel' => true, class: 'btn btn-small'

0 comments on commit 979eebc

Please sign in to comment.