Skip to content

Commit

Permalink
procurement: 2 editable fields more for inspectors
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaai committed Nov 9, 2016
1 parent d1f1171 commit cb255b4
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -25,7 +25,7 @@ db/structure.sql
doc/diagrams/generated/captures.dot
.idea/
chrome*
public/attachments/*
public/**/attachments/*
Gemfile.local*
.vagrant/*
.vagrant*
Expand Down
6 changes: 5 additions & 1 deletion engines/procurement/app/models/procurement/request.rb
Expand Up @@ -23,7 +23,11 @@ class Request < ActiveRecord::Base
:supplier_name, :supplier_id, :motivation, :receiver,
:location_name, :location_id, :template_id,
attachments_attributes: [:file]]
INSPECTOR_KEYS = [:approved_quantity, :order_quantity, :inspection_comment]
INSPECTOR_KEYS = [:requested_quantity,
:approved_quantity,
:order_quantity,
:inspection_comment,
:replacement]

#################################################################

Expand Down
Expand Up @@ -76,7 +76,7 @@
%label.col-xs-4.control-label
= format('%s / %s', _('Replacement'), _('New'))
.col-xs-8
- if request.editable?(current_user) and request.user_id == current_user.id
- if request.editable?(current_user) and (request.user_id == current_user.id or request.category.inspectable_by?(current_user))
%label
%input{type: :radio, name: "requests[#{request.id}][replacement]", value: 1, checked: request.replacement}
.label.label-default= _('Replacement')
Expand All @@ -103,7 +103,7 @@
%label.col-xs-4.control-label
= _('Requested quantity')
.col-xs-4
- if request.editable?(current_user) and request.user_id == current_user.id
- if request.editable?(current_user) and (request.user_id == current_user.id or request.category.inspectable_by?(current_user))
%input.form-control{name: "requests[#{request.id}][requested_quantity]", type: :number, min: 1, value: request.requested_quantity, placeholder: _('Requested quantity'), autocomplete: :off, required: true}
- else
.label.label-primary.requested_quantity
Expand Down
31 changes: 30 additions & 1 deletion engines/procurement/spec/features/inspection.feature
Expand Up @@ -55,8 +55,37 @@ Feature: Inspection (state-behaviour described in seperate feature-file)
Then the following fields are not editable
| Motivation |
| Priority |
| Requested quantity |

@inspection
Scenario: Editing a request
Given I am Barbara
And a request with following data exist
| key | value |
| user | Roger |
| article or project | MyProject |
| article nr. or producer nr.| 1234 |
| supplier | Dell |
| name of receiver | Markus |
| point of delivery | ZHdK |
| replacement | Replacement|
| price | 100 |
| requested amount | 1 |
When I navigate to the requests form of Roger
And I fill in the following fields
| key | value |
| Article or Project | MyProject2 |
| Article nr. or Producer nr.| 12345 |
| Supplier | Digitec |
| Name of receiver | Stefan |
| Point of Delivery | Toni |
| Replacement / New | New |
| Price | 1000 |
| Requested quantity | 2 |
When I upload a file
And I click on save
Then I see a success message
And the request with all given information was updated successfully in the database

@inspection
Scenario: Using the filters as inspector
Given I am Barbara
Expand Down
1 change: 0 additions & 1 deletion engines/procurement/spec/features/roles.feature
Expand Up @@ -35,7 +35,6 @@ Feature: Description of roles
And I can not modify the field of other person's request
| motivation |
| priority |
| requested quantity |
And I can export the data
And I can move requests of my own category to other budget periods
And I can move requests of my own category to other categories
Expand Down
66 changes: 42 additions & 24 deletions engines/procurement/spec/steps/shared/common_steps.rb
Expand Up @@ -13,28 +13,42 @@ module CommonSteps
hash['value'] = nil if hash['value'] == 'random'
case hash['key']
when 'budget period'
@changes[:budget_period] = if hash['value'] == 'current'
Procurement::BudgetPeriod.current
else
Procurement::BudgetPeriod.all.sample
end
@changes[:budget_period] = if hash['value'] == 'current'
Procurement::BudgetPeriod.current
else
Procurement::BudgetPeriod.all.sample
end
when 'user'
@changes[:user] = case hash['value']
when 'myself'
@current_user
else
find_or_create_user(hash['value'], true)
end
@changes[:user] = case hash['value']
when 'myself'
@current_user
else
@user = find_or_create_user(hash['value'], true)
end
when 'requested amount'
@changes[:requested_quantity] = \
(hash['value'] || Faker::Number.number(2)).to_i
@changes[:requested_quantity] = \
(hash['value'] || Faker::Number.number(2)).to_i
when 'approved amount'
@changes[:approved_quantity] = \
(hash['value'] || Faker::Number.number(2)).to_i
@changes[:approved_quantity] = \
(hash['value'] || Faker::Number.number(2)).to_i
when 'inspection comment'
@changes[:inspection_comment] = hash['value'] || Faker::Lorem.sentence
@changes[:inspection_comment] = hash['value'] || Faker::Lorem.sentence
when 'article or project'
@changes[:article_name] = hash['value']
when 'article nr. or producer nr.'
@changes[:article_number] = hash['value']
when 'supplier'
@changes[:supplier_name] = hash['value']
when 'name of receiver'
@changes[:receiver] = hash['value']
when 'point of delivery'
@changes[:location_name] = hash['value']
when 'replacement'
@changes[:replacement] = (hash['value'] == 'Replacement' ? 1 : 0)
when 'price'
@changes[:price] = hash['value']
else
raise
raise
end
end
@request = FactoryGirl.create :procurement_request, @changes
Expand Down Expand Up @@ -283,7 +297,7 @@ module CommonSteps
v = (hash['value'] || Faker::Number.number(2)).to_i
fill_in _(hash['key']), with: v
when 'Replacement / New'
v = hash['value'] || [0, 1].sample
v = (hash['value'] == 'Replacement' ? 1 : 0) || [0, 1].sample
find("input[name*='[replacement]'][value='#{v}']").click
else
v = hash['value'] || Faker::Lorem.sentence
Expand Down Expand Up @@ -624,7 +638,7 @@ module CommonSteps
end

step 'the request with all given information ' \
'was created successfully in the database' do
'was :updated_or_created successfully in the database' do |_|
user = @user || @current_user
if price = @changes.delete(:price)
@changes[:price_cents] = price * 100
Expand Down Expand Up @@ -702,15 +716,19 @@ def currency(amount)
def mapped_key(from)
case from
when 'Article or Project'
:article_name
:article_name
when 'Article nr. or Producer nr.'
:article_number
:article_number
when 'Replacement / New'
:replacement
:replacement
when 'Supplier'
:supplier_name
:supplier_name
when 'Name of receiver'
:receiver
when 'Point of Delivery'
:location_name
else
from.parameterize.underscore.to_sym
from.parameterize.underscore.to_sym
end
end

Expand Down

0 comments on commit cb255b4

Please sign in to comment.