Skip to content

Commit

Permalink
Fixes #69
Browse files Browse the repository at this point in the history
  • Loading branch information
lentschi committed May 24, 2024
1 parent 9d3df4e commit bec3039
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ Metrics/BlockNesting:
# Offense count: 22
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 335
Max: 350

# Offense count: 63
# Configuration parameters: AllowedMethods, AllowedPatterns.
Expand Down
7 changes: 5 additions & 2 deletions app/controllers/articles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class ArticlesController < ApplicationController

before_action :load_article, only: %i[edit update]
before_action :load_article_units, only: %i[edit update new create]
before_action :load_article_categories, only: %i[edit_all migrate_units update_all]
before_action :load_article_categories, only: %i[edit_all copy migrate_units update_all]
before_action :new_empty_article_ratio,
only: %i[edit edit_all migrate_units update new create parse_upload sync update_synchronized]

Expand Down Expand Up @@ -50,7 +50,9 @@ def new
end

def copy
@article = @supplier.articles.find(params[:article_id]).dup
article = @supplier.articles.find(params[:article_id])
@article = article.duplicate_including_latest_version_and_ratios
load_article_units(@article.current_article_units)
render layout: false
end

Expand All @@ -71,6 +73,7 @@ def create
if valid
render layout: false
else
load_article_units(@article.current_article_units)
render action: 'new', layout: false
end
end
Expand Down
6 changes: 6 additions & 0 deletions app/models/article.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,12 @@ def current_article_units
.compact
end

def duplicate_including_latest_version_and_ratios
article = dup
article.latest_article_version = latest_article_version.duplicate_including_article_unit_ratios
article
end

protected

# Checks if the article is in use before it will deleted
Expand Down

0 comments on commit bec3039

Please sign in to comment.