mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-01-28 10:37:52 +08:00
Add consume column to assigned item export [SCI-6841] (#4115)
* Add consume column to assigned item export [SCI-6841] * Fix hound [SCI-6841]
This commit is contained in:
parent
9d4c97f191
commit
13798374ed
3 changed files with 29 additions and 16 deletions
|
@ -3,7 +3,6 @@
|
||||||
class MyModule < ApplicationRecord
|
class MyModule < ApplicationRecord
|
||||||
SEARCHABLE_ATTRIBUTES = ['my_modules.name', 'my_modules.description']
|
SEARCHABLE_ATTRIBUTES = ['my_modules.name', 'my_modules.description']
|
||||||
|
|
||||||
include ActionView::Helpers::NumberHelper
|
|
||||||
include ArchivableModel
|
include ArchivableModel
|
||||||
include SearchableModel
|
include SearchableModel
|
||||||
include SearchableByNameModel
|
include SearchableByNameModel
|
||||||
|
@ -325,18 +324,7 @@ class MyModule < ApplicationRecord
|
||||||
consumed_stock = row.repository_stock_consumption_cell&.value&.formatted
|
consumed_stock = row.repository_stock_consumption_cell&.value&.formatted
|
||||||
row_json << (consumed_stock || 0)
|
row_json << (consumed_stock || 0)
|
||||||
else
|
else
|
||||||
consumed_stock_formatted =
|
row_json << row.row_consumption(row.stock_consumption)
|
||||||
if row.repository_stock_cell.present?
|
|
||||||
consumed_stock = number_with_precision(
|
|
||||||
row.stock_consumption || 0,
|
|
||||||
precision: (row.repository.repository_stock_column.metadata['decimals'].to_i || 0),
|
|
||||||
strip_insignificant_zeros: true
|
|
||||||
)
|
|
||||||
"#{consumed_stock} #{row.repository_stock_value&.repository_stock_unit_item&.data}"
|
|
||||||
else
|
|
||||||
'-'
|
|
||||||
end
|
|
||||||
row_json << consumed_stock_formatted
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
data << row_json
|
data << row_json
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class RepositoryRow < ApplicationRecord
|
class RepositoryRow < ApplicationRecord
|
||||||
|
include ActionView::Helpers::NumberHelper
|
||||||
include SearchableModel
|
include SearchableModel
|
||||||
include SearchableByNameModel
|
include SearchableByNameModel
|
||||||
include ArchivableModel
|
include ArchivableModel
|
||||||
|
@ -149,4 +150,17 @@ class RepositoryRow < ApplicationRecord
|
||||||
repository_cells.each { |cell| cell.snapshot!(row_snapshot) }
|
repository_cells.each { |cell| cell.snapshot!(row_snapshot) }
|
||||||
row_snapshot
|
row_snapshot
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def row_consumption(stock_consumption)
|
||||||
|
if repository_stock_cell.present?
|
||||||
|
consumed_stock = number_with_precision(
|
||||||
|
stock_consumption || 0,
|
||||||
|
precision: (repository.repository_stock_column.metadata['decimals'].to_i || 0),
|
||||||
|
strip_insignificant_zeros: true
|
||||||
|
)
|
||||||
|
"#{consumed_stock} #{repository_stock_value&.repository_stock_unit_item&.data}"
|
||||||
|
else
|
||||||
|
'-'
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -13,6 +13,13 @@ module RepositoryZipExport
|
||||||
.joins(:my_module_repository_rows)
|
.joins(:my_module_repository_rows)
|
||||||
.where(my_module_repository_rows: { my_module_id: params[:my_module_id] })
|
.where(my_module_repository_rows: { my_module_id: params[:my_module_id] })
|
||||||
end
|
end
|
||||||
|
if repository.has_stock_management?
|
||||||
|
rows = rows.left_joins(my_module_repository_rows: :repository_stock_unit_item)
|
||||||
|
.select(
|
||||||
|
'repository_rows.*',
|
||||||
|
'my_module_repository_rows.stock_consumption'
|
||||||
|
)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
ordered_row_ids = params[:row_ids]
|
ordered_row_ids = params[:row_ids]
|
||||||
id_row_map = RepositoryRow.where(id: ordered_row_ids,
|
id_row_map = RepositoryRow.where(id: ordered_row_ids,
|
||||||
|
@ -24,14 +31,15 @@ module RepositoryZipExport
|
||||||
zip = ZipExport.create(user: current_user)
|
zip = ZipExport.create(user: current_user)
|
||||||
zip.generate_exportable_zip(
|
zip.generate_exportable_zip(
|
||||||
current_user,
|
current_user,
|
||||||
to_csv(rows, params[:header_ids], current_user, repository.team),
|
to_csv(rows, params[:header_ids], current_user, repository),
|
||||||
:repositories
|
:repositories
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.to_csv(rows, column_ids, user, team, handle_file_name_func = nil)
|
def self.to_csv(rows, column_ids, user, repository, handle_file_name_func = nil)
|
||||||
# Parse column names
|
# Parse column names
|
||||||
csv_header = []
|
csv_header = []
|
||||||
|
add_consumption = !repository.is_a?(RepositorySnapshot) && repository.has_stock_management?
|
||||||
column_ids.each do |c_id|
|
column_ids.each do |c_id|
|
||||||
csv_header << case c_id.to_i
|
csv_header << case c_id.to_i
|
||||||
when -1, -2
|
when -1, -2
|
||||||
|
@ -53,6 +61,7 @@ module RepositoryZipExport
|
||||||
column ? column.name : nil
|
column ? column.name : nil
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
csv_header << I18n.t('repositories.table.row_consumption') if add_consumption
|
||||||
|
|
||||||
CSV.generate do |csv|
|
CSV.generate do |csv|
|
||||||
csv << csv_header
|
csv << csv_header
|
||||||
|
@ -84,12 +93,14 @@ module RepositoryZipExport
|
||||||
handle_file_name_func.call(cell.value.asset)
|
handle_file_name_func.call(cell.value.asset)
|
||||||
else
|
else
|
||||||
SmartAnnotations::TagToText.new(
|
SmartAnnotations::TagToText.new(
|
||||||
user, team, cell.value.export_formatted
|
user, repository.team, cell.value.export_formatted
|
||||||
).text
|
).text
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
csv_row << row.row_consumption(row.stock_consumption) if add_consumption
|
||||||
csv << csv_row
|
csv << csv_row
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue