Redmine でWEBショップの商品管理をしてみる
3月 21st, 2011 by mattari
プロジェクト管理のための Redmine ですが、どうせなら別のことにも使ってみようということで、ヤフオクやWEBショップなどの商品管理で使えるようにカスタマイズしてみました。応用すれば、社内の在庫管理や物品管理などにも使えるかもしれません。
作業時間を売上高に置き換えることでレポート機能が使えます。
写真を添付できるので、なかなかいい感じです。
以下は、Redmineで商品管理化の手順です。
文言の修正
$REDMINE_HOME/config/locales/ja.ymの文言をそれっぽく修正します。
- プロジェクト→ショップ
- チケット→商品
- 作業時間、時間→売上
- トラッカー→商品種別
- バージョン、ロードマップ→納品計画
- ワークフロー→商品の流れ
- 開始日→納品日
- 期日→回収日
- 題名→商品名
- 予定工数→売上目標
- 時間を記録→売上(税込)
- 報告したチケット→登録した商品
作業時間を金額に修正
1. 作業時間を金額として利用する場合に、そのままだと1000までしか入力できないので、桁数のチッェクを外します。
$REDMINE_HOME/app/models/time_entry.rb
def validate
- errors.add :hours, :invalid if hours && (hours < 0 || hours >= 1000)
+ errors.add :hours, :invalid if hours && (hours < 0)
errors.add :project_id, :invalid if project.nil?
errors.add :issue_id, :invalid if (issue_id && !issue) || (issue && project!=issue.project)
end
2. 時間表示部分を金額表示に変更します。
(1) $REDMINE_HOME/app/helpers/application_helper.rb
def html_hours(text)
- text.gsub(%r{(\d+)\.(\d+)}, ‘<span class="hours hours-int">\1</span><span class="hours hours-dec">.\2</span>’)
+ "<span class=\"hours hours-int\">#{number_to_currency(text)}</span>"
end
def authoring(created, author, options={})
(2) $REDMINE_HOME/app/views/issues/show.rhtml
<th class="category"><%=l(:field_category)%>:</th><td class="category"><%=h @issue.category ? @issue.category.name : "-" %></td>
<% if User.current.allowed_to?(:view_time_entries, @project) %>
<th class="spent-time"><%=l(:label_spent_time)%>:</th>
- <td class="spent-time"><%= @issue.spent_hours > 0 ? (link_to l_hours(@issue.spent_hours), {:controller => ‘timelog’, :action => ‘index’, :project_id => @project, :issue_id => @issue}) : "-" %></td>
+ <td class="spent-time"><%= @issue.spent_hours > 0 ? (link_to number_to_currency(@issue.spent_hours), {:controller => ‘timelog’, :action => ‘index’, :project_id => @project, :issue_id => @issue}) : "-" %></td>
<% end %>
</tr>
<tr>
<th class="fixed-version"><%=l(:field_fixed_version)%>:</th><td class="fixed-version"><%= @issue.fixed_version ? link_to_version(@issue.fixed_version) : "-" %></td>
<% if @issue.estimated_hours %>
- <th class="estimated-hours"><%=l(:field_estimated_hours)%>:</th><td class="estimated-hours"><%= l_hours(@issue.estimated_hours) %></td>
+ <th class="estimated-hours"><%=l(:field_estimated_hours)%>:</th><td class="estimated-hours"><%= number_to_currency(@issue.estimated_hours) %></td>
<% end %>
</tr>
<%= render_custom_fields_rows(@issue) %>
前回のエントリ「Redmine のチケット一覧に作業時間を表示してみる。」で表示していた作業時間も、金額表示に変更します。
(3) $REDMINE_HOME/app/views/issues/_list.rhtml
<td class="checkbox hide-when-print"><%= check_box_tag("ids[]", issue.id, false, :id => nil) %></td>
<td class="id"><%= link_to issue.id, :controller => ‘issues’, :action => ‘show’, :id => issue %></td>
<% query.columns.each do |column| %><%= content_tag ‘td’, column_content(column, issue), :class => column.name %><% end %>- <td class="spent-time"><%= issue.spent_hours > 0 ? (link_to l_hours(issue.spent_hours), {:controller => ‘timelog’, :action => ‘index’, :project_id => @project, :issue_id => issue}) : "-" %></td>
+ <td class="spent-time"><%= issue.spent_hours > 0 ? (link_to number_to_currency(issue.spent_hours), {:controller => ‘timelog’, :action => ‘index’, :project_id => @project, :issue_id => issue}) : "-" %></td>
</tr>
<% end -%>
</tbody>
(4) $REDMINE_HOME/app/views/projects/show.rhtml
<% content_for :sidebar do %>
<% if @total_hours && User.current.allowed_to?(:view_time_entries, @project) %>
<h3><%= l(:label_spent_time) %></h3>
- <p><span class="icon icon-time"><%= l_hours(@total_hours) %></span></p>
+ <p><span class="icon icon-time"><%= number_to_currency(@total_hours) %></span></p>
<p><%= link_to(l(:label_details), {:controller => ‘timelog’, :action => ‘index’, :project_id => @project}) %> |
<%= link_to(l(:label_report), {:controller => ‘time_entry_reports’, :action => ‘report’, :project_id => @project}) %></p>
<% end %>
3. 以前の記事「Redmine の CSV出力に作業時間の記録を追加してみた。」をやっておくと、売り上げをCSV出力できるようなります。
4. 最後に作業時間のアイコンをお金のアイコンで上書きします。
- $REDMINE_HOME/public/images/time.png
- $REDMINE_HOME/public/images/time_add.png
お好みに応じて、Redmineのテーマを入れ替えます。
ここまでで、Redmine を再起動します。
Redmine の設定
ステータスとワークフローを商品管理っぽく設定します。
使いそうなカスタムフィールドを追加します。
扱う商品種別(トラッカー)を設定します。
ショップ(プロジェクト)の設定
商品のカテゴリ(チケットのカテゴリ)を設定します。
以上で、Redmineで商品管理化の完成です。