mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-26 16:53:12 +08:00
Implement stock management activities [SCI-6452] (#3810)
* Implement stock management activities [SCI-6452] * PR code fixes [SCI-6452]
This commit is contained in:
parent
6593da8988
commit
cdbf1f5fa0
10 changed files with 92 additions and 37 deletions
|
@ -18,7 +18,7 @@ var RepositoryStockValues = (function() {
|
|||
closeOnSelect: true,
|
||||
selectAppearance: 'simple',
|
||||
onChange: function() {
|
||||
$('.stock-final-container .units').text(dropdownSelector.getValues(UNIT_SELECTOR));
|
||||
$('.stock-final-container .units').text(dropdownSelector.getLabels(UNIT_SELECTOR));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -35,6 +35,8 @@ var RepositoryStockValues = (function() {
|
|||
$stockInput.data('operator', $(this).data('operator'));
|
||||
|
||||
dropdownSelector.selectValues(UNIT_SELECTOR, $('#initial_units').val());
|
||||
$('#operator').val($(this).data('operator'));
|
||||
|
||||
switch ($(this).data('operator')) {
|
||||
case 'set':
|
||||
$stockInput.val($stockInput.data('currentAmount'));
|
||||
|
@ -74,6 +76,8 @@ var RepositoryStockValues = (function() {
|
|||
newAmount = currentAmount;
|
||||
break;
|
||||
}
|
||||
$('#change_amount').val(inputAmount);
|
||||
|
||||
$('#repository_stock_value_amount').val(newAmount);
|
||||
$('.stock-final-container .value').text(newAmount);
|
||||
});
|
||||
|
|
|
@ -896,6 +896,17 @@ var dropdownSelector = (function() {
|
|||
|
||||
return values;
|
||||
},
|
||||
// Get selected labels
|
||||
getLabels: function(selector) {
|
||||
var labels;
|
||||
if ($(selector).length === 0) return false;
|
||||
labels = $.map(getCurrentData($(selector).next()), (v) => {
|
||||
return v.label;
|
||||
});
|
||||
if ($(selector).data('config').singleSelect) return labels[0];
|
||||
|
||||
return labels;
|
||||
},
|
||||
// Get all data
|
||||
getData: function(selector) {
|
||||
if ($(selector).length === 0) return false;
|
||||
|
|
|
@ -33,40 +33,51 @@ class RepositoryStockValuesController < ApplicationController
|
|||
end
|
||||
|
||||
def create_or_update
|
||||
if @repository_stock_value # update
|
||||
ActiveRecord::Base.transaction do
|
||||
@repository_stock_value.update_stock_with_ledger!(
|
||||
repository_stock_value_params[:amount],
|
||||
@repository,
|
||||
repository_stock_value_params[:comment].presence
|
||||
)
|
||||
@repository_stock_value.repository_stock_unit_item =
|
||||
@repository_column.repository_stock_unit_items.find(repository_stock_value_params[:unit_item_id])
|
||||
@repository_stock_value.update_data!(repository_stock_value_params[:amount], current_user)
|
||||
end
|
||||
else
|
||||
ActiveRecord::Base.transaction do # create
|
||||
repository_cell = @repository_row.repository_cells.create(repository_column: @repository_column)
|
||||
@repository_stock_value = RepositoryStockValue.new_with_payload(
|
||||
repository_stock_value_params[:amount],
|
||||
repository_cell: repository_cell,
|
||||
created_by: current_user,
|
||||
last_modified_by: current_user,
|
||||
repository_stock_unit_item: @repository_column.repository_stock_unit_items
|
||||
.find(repository_stock_value_params[:unit_item_id])
|
||||
)
|
||||
@repository_stock_value.save!
|
||||
@repository_stock_value.update_stock_with_ledger!(
|
||||
repository_stock_value_params[:amount],
|
||||
@repository,
|
||||
repository_stock_value_params[:comment].presence
|
||||
)
|
||||
end
|
||||
ActiveRecord::Base.transaction do
|
||||
@repository_stock_value ? update! : create!
|
||||
|
||||
log_activity(
|
||||
params[:operator],
|
||||
params[:change_amount],
|
||||
@repository_stock_value.repository_stock_unit_item.data,
|
||||
@repository_stock_value.amount
|
||||
)
|
||||
end
|
||||
|
||||
render json: @repository_stock_vlaue
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update!
|
||||
@repository_stock_value.update_stock_with_ledger!(
|
||||
repository_stock_value_params[:amount],
|
||||
@repository,
|
||||
repository_stock_value_params[:comment].presence
|
||||
)
|
||||
@repository_stock_value.repository_stock_unit_item =
|
||||
@repository_column.repository_stock_unit_items.find(repository_stock_value_params[:unit_item_id])
|
||||
@repository_stock_value.update_data!(repository_stock_value_params[:amount], current_user)
|
||||
end
|
||||
|
||||
def create!
|
||||
repository_cell = @repository_row.repository_cells.create(repository_column: @repository_column)
|
||||
@repository_stock_value = RepositoryStockValue.new_with_payload(
|
||||
repository_stock_value_params[:amount],
|
||||
repository_cell: repository_cell,
|
||||
created_by: current_user,
|
||||
last_modified_by: current_user,
|
||||
repository_stock_unit_item: @repository_column.repository_stock_unit_items
|
||||
.find(repository_stock_value_params[:unit_item_id])
|
||||
)
|
||||
@repository_stock_value.save!
|
||||
@repository_stock_value.update_stock_with_ledger!(
|
||||
repository_stock_value_params[:amount],
|
||||
@repository,
|
||||
repository_stock_value_params[:comment].presence
|
||||
)
|
||||
end
|
||||
|
||||
def load_vars
|
||||
@repository = Repository.find(params[:repository_id])
|
||||
@repository_row = @repository.repository_rows.find(params[:id])
|
||||
|
@ -81,4 +92,19 @@ class RepositoryStockValuesController < ApplicationController
|
|||
def repository_stock_value_params
|
||||
params.require(:repository_stock_value).permit(:unit_item_id, :amount, :comment)
|
||||
end
|
||||
|
||||
def log_activity(operator, change_amount, unit, new_amount)
|
||||
Activities::CreateActivityService
|
||||
.call(activity_type: "inventory_item_stock_#{operator}",
|
||||
owner: current_user,
|
||||
subject: @repository_row,
|
||||
team: @repository.team,
|
||||
message_items: {
|
||||
repository: @repository.id,
|
||||
repository_row: @repository_row.id,
|
||||
change_amount: change_amount,
|
||||
unit: unit,
|
||||
new_amount: new_amount
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -21,7 +21,7 @@ module RepositoryDatatableHelper
|
|||
'recordInfoUrl': Rails.application.routes.url_helpers.repository_repository_row_path(repository, record)
|
||||
}.merge(default_cells)
|
||||
|
||||
if options[:include_stock_consumption]
|
||||
if record.repository.has_stock_management?
|
||||
row['manageStockUrl'] = if record.has_stock?
|
||||
Rails.application.routes.url_helpers
|
||||
.edit_repository_stock_repository_repository_row_url(
|
||||
|
|
|
@ -150,6 +150,8 @@ class Activity < ApplicationRecord
|
|||
when Repository
|
||||
breadcrumbs[:repository] = subject.name
|
||||
generate_breadcrumb(subject.team)
|
||||
when RepositoryRow
|
||||
generate_breadcrumb(subject.repository)
|
||||
when Result
|
||||
breadcrumbs[:result] = subject.name
|
||||
generate_breadcrumb(subject.my_module)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
<%= render partial: "global_activities/references/repository_base.html.erb",
|
||||
locals: { team: team, subject: subject.repository, breadcrumbs: breadcrumbs, values: values, type_of: type_of } %>
|
|
@ -9,7 +9,9 @@
|
|||
</div>
|
||||
<div class="modal-body">
|
||||
<%= hidden_field_tag 'repository_stock_value[amount]', repository_stock_value.amount %>
|
||||
<%= hidden_field_tag 'initial_units', repository_stock_value.units %>
|
||||
<%= hidden_field_tag 'initial_units', repository_stock_value.repository_stock_unit_item_id %>
|
||||
<%= hidden_field_tag 'change_amount' %>
|
||||
<%= hidden_field_tag 'operator', 'set' %>
|
||||
<p><%= t('repository_stock_values.manage_modal.enter_amount') %></p>
|
||||
<div class="row">
|
||||
<div class="col-sm-5">
|
||||
|
@ -83,7 +85,7 @@
|
|||
<div class="stock-initial-container">
|
||||
<span class="subtitle"><%= t('repository_stock_values.manage_modal.current_stock') %></span>
|
||||
<span class="value"><%= repository_stock_value.amount %></span>
|
||||
<span class="units"><%= repository_stock_value.units %></span>
|
||||
<span class="units"><%= repository_stock_value.repository_stock_unit_item&.data %></span>
|
||||
</div>
|
||||
<div class="stock-arrow">
|
||||
<i class="fas fa-arrow-right"></i>
|
||||
|
@ -91,7 +93,7 @@
|
|||
<div class="stock-final-container">
|
||||
<span class="subtitle"><%= t('repository_stock_values.manage_modal.new_stock') %></span>
|
||||
<span class="value"><%= repository_stock_value.amount %></span>
|
||||
<span class="units"><%= repository_stock_value.units %></span>
|
||||
<span class="units"><%= repository_stock_value.repository_stock_unit_item&.data %></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -138,7 +138,8 @@ class Extends
|
|||
]
|
||||
|
||||
ACTIVITY_SUBJECT_TYPES = %w(
|
||||
Team RepositoryBase Project Experiment MyModule Result Protocol Report RepositoryRow ProjectFolder Asset Step
|
||||
Team RepositoryBase Project Experiment MyModule Result Protocol Report RepositoryRow
|
||||
ProjectFolder Asset Step
|
||||
).freeze
|
||||
|
||||
SEARCHABLE_ACTIVITY_SUBJECT_TYPES = %w(
|
||||
|
@ -324,7 +325,10 @@ class Extends
|
|||
create_molecule_on_step_in_repository: 173,
|
||||
register_molecule_on_step: 177,
|
||||
register_molecule_on_result: 178,
|
||||
register_molecule_on_step_in_repository: 179
|
||||
register_molecule_on_step_in_repository: 179,
|
||||
inventory_item_stock_set: 180,
|
||||
inventory_item_stock_add: 181,
|
||||
inventory_item_stock_remove: 182
|
||||
}
|
||||
|
||||
ACTIVITY_GROUPS = {
|
||||
|
@ -337,7 +341,8 @@ class Extends
|
|||
task_inventory: [55, 56, 146, 147],
|
||||
experiment: [*27..31, 57, 141, 165],
|
||||
reports: [48, 50, 49, 163, 164],
|
||||
inventories: [70, 71, 105, 144, 145, 72, 73, 74, 102, 142, 143, 75, 76, 77, 78, 96, 107, 113, 114, *133..136],
|
||||
inventories: [70, 71, 105, 144, 145, 72, 73, 74, 102, 142, 143, 75, 76, 77,
|
||||
78, 96, 107, 113, 114, *133..136, 180, 181, 182],
|
||||
protocol_repository: [80, 103, 89, 87, 79, 90, 91, 88, 85, 86, 84, 81, 82,
|
||||
83, 101, 112, 123, 125, 117, 119, 129, 131, 170, 173, 179],
|
||||
team: [92, 94, 93, 97, 104]
|
||||
|
|
|
@ -205,6 +205,9 @@ en:
|
|||
register_molecule_on_step_html: "%{user} registered molecule %{asset_name} on protocol's step %{step_position} %{step} on task %{my_module}."
|
||||
register_molecule_on_result_html: "%{user} registered molecule %{asset_name} on result %{result}."
|
||||
register_molecule_on_step_in_repository_html: "%{user} registered molecule %{asset_name} on protocol %{protocol}'s step %{step_position} %{step}."
|
||||
inventory_item_stock_set_html: "%{user} set total stock for %{repository_row} to %{new_amount} %{unit} in %{repository}"
|
||||
inventory_item_stock_add_html: "%{user} added %{change_amount} %{unit} of stock to a total of %{new_amount} %{unit} for %{repository_row} in %{repository}"
|
||||
inventory_item_stock_remove_html: "%{user} removed %{change_amount} %{unit} of stock to a total of %{new_amount} %{unit} for %{repository_row} in %{repository}"
|
||||
|
||||
activity_name:
|
||||
create_project: "Project created"
|
||||
|
|
Loading…
Reference in a new issue