4 Commits
Author SHA1 Message Date
rickyandClaude Opus 5.5 ffaf37e55b 2026.11.2
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 16:55:16 -05:00
rickyandClaude Opus 5.5 67a0bc62aa Top menu opens this week; weeks run are for Run tech bonuses
The Tech bonuses top menu now goes to /tech_bonuses/current, which
redirects to the week containing today. The index (week picker and
weeks run) is limited to Run tech bonuses: View tech bonuses only
covers a week's page, whose title links to the index only for those
who can run the bonus.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 16:55:16 -05:00
rickyandClaude Opus 5.5 d35d408ac6 2026.11.1
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:45:57 -05:00
rickyandClaude Opus 5.5 07e79a3c00 View tech bonuses permission, for the Foreman
A global "View tech bonuses" permission shows the weeks run and each
week's hours, tiers and bonuses, read-only: no attendance boxes, run
button or Email again, and no customer accounts, emailed-to addresses,
or QuickBooks/PDF links. "Run tech bonuses" is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 12:45:57 -05:00
8 changed files with 82 additions and 16 deletions

No files matched your search

+4 -2
View File
@@ -25,7 +25,7 @@ The tier line is only there when a tier was reached. Both lines use the product/
## Running a week
**Tech bonuses** (top menu) lists the weeks run so far. Pick a week to see:
**Tech bonuses** (top menu) opens this week, so far. For those who run the bonus, its title links to the weeks run so far and a week picker. A week shows:
* the shop's hours, the goal, the tiers reached and the hours to the next tier;
* each technician's hours and bonus, with an **Attended** box. Uncheck a technician who missed part of a scheduled shift;
@@ -55,7 +55,9 @@ Restart Redmine, then:
* Check the target and amounts.
* Pick the product/service.
3. **Administration » Bonus technicians**: add each technician and the Foreman. Give each one their role, the QuickBooks customer account their bonus is credited to, and the last day of their probation if they're in it.
4. **Administration » Roles and permissions**: give **Run tech bonuses** to the roles that run the bonus. It's a global permission, so it applies to any role the user has in any project.
4. **Administration » Roles and permissions**: give **Run tech bonuses** to the roles that run the bonus, and **View tech bonuses** to those who only see a week's hours and bonuses (e.g. the Foreman), without the weeks run. They're global permissions, so they apply to any role the user has in any project.
**View tech bonuses** shows the weeks and each week's hours, tiers and bonuses, read-only. It doesn't show the technicians' customer accounts, the attendance boxes, or the credit memos' QuickBooks and PDF links, and it can't run a week or email a credit memo.
## Tests
@@ -30,10 +30,16 @@ class TechBonusesController < ApplicationController
@week = RedmineQboBonus::Week.last_completed
end
# The top menu opens this week, so far
def current
redirect_to tech_bonus_week_path(RedmineQboBonus::Week.containing(Date.current).to_param)
end
def show
@report = RedmineQboBonus::WeekReport.new(@week)
@bonus_week = TechBonusWeek.for(@week)
@credits = @bonus_week ? @bonus_week.credits.index_by(&:user_id) : {}
@can_run = RedmineQboBonus.allowed?
end
def create
+13 -8
View File
@@ -11,7 +11,7 @@
| <%= link_to sprite_icon('time', l(:label_tech_bonus_time_report)), report_time_entries_path(report.redmine_report_params), class: 'icon icon-time' %>
</div>
<h2><%= link_to l(:label_tech_bonus_plural), tech_bonuses_path %> » <%= bonus_week_title(@week) %></h2>
<h2><%= @can_run ? link_to(l(:label_tech_bonus_plural), tech_bonuses_path) : l(:label_tech_bonus_plural) %> » <%= bonus_week_title(@week) %></h2>
<div class="tech-bonus-summary">
<div class="box">
@@ -69,13 +69,16 @@
<% credit = @credits[tech.user_id] %>
<% credited = credit&.credited? %>
<tr class="<%= 'ineligible' unless line.eligible? %>">
<td class="name"><%= link_to_user tech.user %><br><small><%= tech.customer&.name || l(:text_tech_bonus_no_customer) %></small></td>
<td class="name">
<%= link_to_user tech.user %>
<% if @can_run %><br><small><%= tech.customer&.name || l(:text_tech_bonus_no_customer) %></small><% end %>
</td>
<td><%= tech.role_name %></td>
<td><%= bonus_hours(line.hours) %></td>
<td>
<% if credited %>
<%= sprite_icon('checked', l(:general_text_Yes)) %>
<% elsif line.eligible? %>
<% elsif @can_run && line.eligible? %>
<%= check_box_tag 'attended[]', tech.user_id, credit.nil? || credit.message != l(:text_tech_bonus_missed_shift),
id: "attended_#{tech.user_id}", disabled: !report.goal_met? %>
<% end %>
@@ -89,15 +92,15 @@
<td><%= bonus_money(line.tier_amount) %></td>
<td><%= bonus_money(line.amount) %></td>
<% end %>
<td><%= credit_memo_link(credit) %></td>
<td><%= @can_run ? credit_memo_link(credit) : (credit&.doc_number.presence && "##{credit.doc_number}") %></td>
<td class="message">
<%= bonus_status_tag(credit) %>
<% message = credit&.message.presence || line.ineligible_reason %>
<% if credit&.emailed_to.present? %><br><small><%= credit.emailed_to %></small><% end %>
<% if @can_run && credit&.emailed_to.present? %><br><small><%= credit.emailed_to %></small><% end %>
<% if message %><br><small><%= message %></small><% end %>
</td>
<td>
<% if credited %>
<% if credited && @can_run %>
<%= link_to sprite_icon('email', l(:button_tech_bonus_resend)), resend_tech_bonus_credit_path(credit),
method: :post, class: 'icon icon-email',
data: { confirm: l(:text_tech_bonus_resend_confirm) } %>
@@ -108,9 +111,11 @@
</tbody>
</table>
</div>
<p><em class="info"><%= l(:text_tech_bonus_attendance) %></em></p>
<% if @can_run %>
<p><em class="info"><%= l(:text_tech_bonus_attendance) %></em></p>
<% end %>
<% if @week.completed? %>
<% if @can_run && @week.completed? %>
<p>
<% label = report.goal_met? ? l(:button_tech_bonus_run) : l(:button_tech_bonus_record) %>
<%= submit_tag label, data: { confirm: report.goal_met? ? l(:text_tech_bonus_run_confirm) : nil } %>
+1
View File
@@ -1,5 +1,6 @@
en:
permission_run_tech_bonuses: "Run tech bonuses"
permission_view_tech_bonuses: "View tech bonuses"
label_tech_bonus_plural: "Tech bonuses"
label_bonus_technician_plural: "Bonus technicians"
+1
View File
@@ -12,6 +12,7 @@ RedmineApp::Application.routes.draw do
# Weekly bonus: the weeks run, a week's hours and bonuses (by its Sunday, e.g. /tech_bonuses/2026-11-15)
get 'tech_bonuses', to: 'tech_bonuses#index', as: :tech_bonuses
get 'tech_bonuses/current', to: 'tech_bonuses#current', as: :current_tech_bonus_week
get 'tech_bonuses/:week', to: 'tech_bonuses#show', as: :tech_bonus_week, constraints: { week: /\d{4}-\d{2}-\d{2}/ }
post 'tech_bonuses/:week', to: 'tech_bonuses#create', constraints: { week: /\d{4}-\d{2}-\d{2}/ }
get 'tech_bonuses/credits/:id/pdf', to: 'tech_bonuses#pdf', as: :tech_bonus_credit_pdf
+7 -5
View File
@@ -15,7 +15,7 @@ Redmine::Plugin.register :redmine_qbo_bonus do
author 'Rick Barrette'
description 'Weekly billable hours bonus for technicians (SOP-OPS-012): totals the shop\'s billable hours for a week, ' \
'and credits each qualifying technician\'s QuickBooks customer account with an emailed credit memo'
version '2026.11.0'
version '2026.11.2'
url 'https://gitea.rickbarrette.org/ricky/redmine_qbo_bonus'
author_url 'https://barrettefabrication.com'
requires_redmine version_or_higher: '7.0.0'
@@ -29,12 +29,14 @@ Redmine::Plugin.register :redmine_qbo_bonus do
settings default: RedmineQboBonus::Settings::DEFAULTS.dup, partial: 'settings/qbo_bonus'
# Previewing a week's bonus, creating and emailing its credit memos
permission :run_tech_bonuses, { tech_bonuses: [:index, :show, :create, :resend, :pdf] }, global: true
# Seeing a week's hours and bonuses (e.g. the Foreman), without the weeks run, running them or opening the credit memos
permission :view_tech_bonuses, { tech_bonuses: [:current, :show] }, global: true
# The weeks run, previewing a week's bonus, creating and emailing its credit memos
permission :run_tech_bonuses, { tech_bonuses: [:index, :current, :show, :create, :resend, :pdf] }, global: true
menu :top_menu, :tech_bonuses, { controller: 'tech_bonuses', action: 'index' },
menu :top_menu, :tech_bonuses, { controller: 'tech_bonuses', action: 'current' },
caption: :label_tech_bonus_plural, after: :my_page,
if: proc { User.current.allowed_to?(:run_tech_bonuses, nil, global: true) }
if: proc { RedmineQboBonus.visible? }
# The technicians who earn the bonus and their QuickBooks customer accounts
menu :admin_menu, :bonus_technicians, { controller: 'bonus_technicians', action: 'index' },
+6
View File
@@ -12,10 +12,16 @@ module RedmineQboBonus
def self.setup; end
# May run the bonus (create and email credit memos)
def self.allowed?(user = User.current)
user.allowed_to?(:run_tech_bonuses, nil, global: true)
end
# May see the bonus pages (run them, or only view them)
def self.visible?(user = User.current)
allowed?(user) || user.allowed_to?(:view_tech_bonuses, nil, global: true)
end
# 95.5 => "95.5", 110.0 => "110", 87.583 => "87.58"
def self.format_hours(hours)
rounded = hours.to_d.round(2)
+44 -1
View File
@@ -31,7 +31,50 @@ class TechBonusesTest < Redmine::IntegrationTest
Role.find(1).add_permission!(:run_tech_bonuses)
get '/tech_bonuses'
assert_response :success
assert_select '#top-menu a.tech-bonuses'
assert_select '#top-menu a.tech-bonuses[href=?]', '/tech_bonuses/current'
end
def test_menu_opens_this_week
log_user('admin', 'admin')
travel_to Date.new(2026, 11, 18) do
get '/tech_bonuses/current'
assert_redirected_to '/tech_bonuses/2026-11-15'
end
end
def test_view_only
log_user('admin', 'admin')
post '/tech_bonuses/2026-11-08', params: { attended: ['2'] }
credit = TechBonusCredit.find_by(user_id: 2)
Role.find(1).add_permission!(:view_tech_bonuses)
reset!
log_user('jsmith', 'jsmith')
get '/tech_bonuses'
assert_response :forbidden
get '/tech_bonuses/current'
assert_response :redirect
get '/tech_bonuses/2026-11-08'
assert_response :success
assert_select '#top-menu a.tech-bonuses[href=?]', '/tech_bonuses/current'
assert_select 'h2 a[href=?]', '/tech_bonuses', count: 0
assert_select 'td', text: '$100.00'
assert_select 'td', text: '#1042'
assert_select 'input[name=?]', 'attended[]', count: 0
assert_select '#tech-bonus-run input[type=submit]', count: 0
assert_select 'a[href*="creditmemo"]', count: 0
assert_select 'a[href*="/pdf"]', count: 0
assert_select 'a[href*="/resend"]', count: 0
assert_not_includes response.body, 'tech@example.com'
assert_no_difference 'TechBonusCredit.count' do
post '/tech_bonuses/2026-11-15', params: { attended: ['2'] }
end
assert_response :forbidden
post "/tech_bonuses/credits/#{credit.id}/resend"
assert_response :forbidden
get "/tech_bonuses/credits/#{credit.id}/pdf"
assert_response :forbidden
end
def test_week_preview