mirror of
https://github.com/rickbarrette/redmine_qbo_lineitems.git
synced 2026-11-17 19:20:36 -05:00
Polish: permissions, billed-line locking, sync and billing fixes
Permissions - Item catalog and accounts pages, and their syncs, are admin-only (they push to / pull from QuickBooks); shown in the Administration layout - Item autocomplete is allowed with Add or Edit line items - Permissions now map to real actions (they pointed at a non-existent line_items controller); line_items_attributes is only accepted from users with a line item permission - Line item changes are checked on the server: adding, editing and deleting each need their permission, and billed lines (already on a QBO estimate) can't be changed or removed Bugs - Billing on close now runs from an Issue after_commit, so closing via bulk edit or the context menu bills too (replaces the save hook); the job takes an issue id - Full sync runs Accounts before Items, and item sync no longer fails when an item has no income account or its account hasn't synced - New QBO items default to Non-inventory in the default income account (the account ref was being assigned to the item type) - Choosing a blank account on an item no longer raises; set_default handles no selection - Item autocomplete escapes item names, SKUs and descriptions (they were inserted into the page as HTML) - Items list showed "translation missing" for Yes/No Polish - Fractional quantities allowed (0.5 hrs, 2.5 qts) - Billed lines show a Billed badge and are read-only; remove button only where allowed; add button only with Add line items - Removed dead code (Item belongs_to :issue, Item#ref, no-op in new, swallowed errors); validation failures return 422 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
20 files changed
+182
-138
No files matched your search
@@ -27,16 +27,16 @@
|
||||
<td class="unit_price"><%= number_to_currency(item.unit_price) %></td>
|
||||
<td class="taxable center">
|
||||
<% if item.taxable %>
|
||||
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||
<span class="icon icon-ok" style="color: green;"><%= l(:general_text_Yes) %></span>
|
||||
<% else %>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%= l(:general_text_No) %></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="active center">
|
||||
<% if item.active %>
|
||||
<span class="icon icon-ok" style="color: green;"><%=t(:yes)%></span>
|
||||
<span class="icon icon-ok" style="color: green;"><%= l(:general_text_Yes) %></span>
|
||||
<% else %>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%=t(:no)%></span>
|
||||
<span class="icon icon-not-ok" style="color: #999;"><%= l(:general_text_No) %></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<td class="buttons">
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
<% readonly = @issue.status.is_closed? %>
|
||||
<%
|
||||
readonly = @issue.status.is_closed?
|
||||
can_add = User.current.allowed_to?(:add_line_items, nil, global: true)
|
||||
can_edit = User.current.allowed_to?(:edit_line_items, nil, global: true)
|
||||
can_delete = User.current.allowed_to?(:delete_line_items, nil, global: true)
|
||||
permissions = { can_edit: can_edit, can_delete: can_delete }
|
||||
%>
|
||||
|
||||
<% @issue.line_items.build if @issue.line_items.empty? && !readonly %>
|
||||
<% @issue.line_items.build if @issue.line_items.empty? && !readonly && can_add %>
|
||||
|
||||
<div class="box tabular"
|
||||
data-nested-form
|
||||
@@ -25,7 +31,8 @@
|
||||
<%= f.fields_for :line_items do |item_form| %>
|
||||
<%= render "line_items/line_item_fields",
|
||||
f: item_form,
|
||||
readonly: readonly %>
|
||||
readonly: readonly,
|
||||
**permissions %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
@@ -35,24 +42,22 @@
|
||||
<span id="line-items-grand-total">0.00</span>
|
||||
</p>
|
||||
|
||||
<% unless readonly %>
|
||||
<% if !readonly && can_add %>
|
||||
<template data-nested-form-template>
|
||||
<%= f.fields_for :line_items, LineItem.new, child_index: "NEW_RECORD" do |item_form| %>
|
||||
<%= render "line_items/line_item_fields",
|
||||
f: item_form,
|
||||
readonly: false %>
|
||||
readonly: false,
|
||||
**permissions %>
|
||||
<% end %>
|
||||
</template>
|
||||
|
||||
<p>
|
||||
|
||||
<% if User.current.allowed_to?(:add_line_items, nil, global: true) %>
|
||||
<button type="button"
|
||||
class="icon icon-add"
|
||||
data-nested-form-add>
|
||||
<%= l(:button_add) %>
|
||||
</button>
|
||||
<% end %>
|
||||
<button type="button"
|
||||
class="icon icon-add"
|
||||
data-nested-form-add>
|
||||
<%= l(:button_add) %>
|
||||
</button>
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
<% if @issue.line_items.any? || @issue.descendant_line_items_total > 0%>
|
||||
<% if issue.line_items.any? || issue.descendant_line_items_total > 0%>
|
||||
<hr/>
|
||||
<div>
|
||||
<p><strong><%= t :label_line_items %></strong></p>
|
||||
|
||||
<% total = 0 %>
|
||||
|
||||
<% if @issue.line_items.any?%>
|
||||
<% if issue.line_items.any?%>
|
||||
|
||||
<table class="list line-items-table">
|
||||
<thead>
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<tbody>
|
||||
|
||||
<% @issue.line_items.each do |item| %>
|
||||
<% issue.line_items.each do |item| %>
|
||||
<% line_total = item.quantity.to_f * item.unit_price.to_f %>
|
||||
<% total += line_total %>
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<% end %>
|
||||
|
||||
<tfoot>
|
||||
<% if @issue.line_items.any?%>
|
||||
<% if issue.line_items.any?%>
|
||||
<tr>
|
||||
<td colspan="3" style="text-align:right;"><strong><%= t :label_total %></strong></td>
|
||||
<td>
|
||||
@@ -44,11 +44,11 @@
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
<% if @issue.descendant_line_items_total > 0 %>
|
||||
<% if issue.descendant_line_items_total > 0 %>
|
||||
<tr>
|
||||
<td colspan="3" style="text-align:right;"><strong><%= t :label_running_total %></strong></td>
|
||||
<td>
|
||||
<strong>(<%= number_to_currency(@issue.descendant_line_items_total + total) %>)</strong>
|
||||
<strong>(<%= number_to_currency(issue.descendant_line_items_total + total) %>)</strong>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
@@ -1,4 +1,12 @@
|
||||
<tr class="line-item">
|
||||
<%
|
||||
item = f.object
|
||||
billed = item.persisted? && item.billed?
|
||||
# Billed lines are on a QuickBooks estimate already; existing lines need "Edit line items" to change
|
||||
locked = readonly || billed || (item.persisted? && !can_edit)
|
||||
# Unsaved rows can always be removed; saved ones need "Delete line items"
|
||||
removable = !readonly && !billed && (item.new_record? || can_delete)
|
||||
%>
|
||||
<tr class="line-item<%= ' billed' if billed %>">
|
||||
<%= f.hidden_field :id %>
|
||||
<%= f.hidden_field :_destroy %>
|
||||
<%= f.hidden_field :item_id, class: "item-id-field" %>
|
||||
@@ -9,17 +17,21 @@
|
||||
class: "line-item-description",
|
||||
autocomplete: "off",
|
||||
no_label: true,
|
||||
disabled: readonly %>
|
||||
disabled: locked %>
|
||||
<% if billed %>
|
||||
<span class="line-item-billed-badge" title="<%= l(:text_line_item_billed) %>"><%= l(:label_billed) %></span>
|
||||
<% end %>
|
||||
</td>
|
||||
|
||||
<td data-label="<%= t :label_qty %>">
|
||||
<%# Fractional quantities are allowed (e.g. 0.5 hours, 2.5 quarts) %>
|
||||
<%= f.number_field :quantity,
|
||||
step: 1,
|
||||
min: 1,
|
||||
value: (f.object.quantity.to_i > 0) ? f.object.quantity : 1,
|
||||
step: "any",
|
||||
min: 0,
|
||||
value: (item.quantity.to_f > 0) ? number_with_precision(item.quantity, precision: 4, strip_insignificant_zeros: true) : 1,
|
||||
class: "qty-field",
|
||||
no_label: true,
|
||||
disabled: readonly %>
|
||||
disabled: locked %>
|
||||
</td>
|
||||
|
||||
<td data-label="<%= t :label_price %>">
|
||||
@@ -28,22 +40,22 @@
|
||||
inputmode: "decimal",
|
||||
autocomplete: "off",
|
||||
no_label: true,
|
||||
disabled: readonly %>
|
||||
disabled: locked %>
|
||||
</td>
|
||||
|
||||
<td class="line-total" data-label="<%= t :label_total %>">
|
||||
0.00
|
||||
</td>
|
||||
|
||||
<% if User.current.allowed_to?(:delete_line_items, nil, global: true) %>
|
||||
<% unless readonly %>
|
||||
<td class="actions">
|
||||
<% unless readonly %>
|
||||
<td class="actions">
|
||||
<% if removable %>
|
||||
<button type="button"
|
||||
class="icon-only icon-del"
|
||||
title="<%= l(:label_remove) %>"
|
||||
data-nested-form-remove>
|
||||
</button>
|
||||
</td>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
@@ -15,7 +15,7 @@
|
||||
</p>
|
||||
<p>
|
||||
<label><strong><%= t(:label_last_sync) %> (QBO)</strong></label>
|
||||
<%= Qbo.exists? ? Qbo.last_sync : 'Never synced' %>
|
||||
<%= Qbo.exists? ? Qbo.last_sync : l(:label_never_synced) %>
|
||||
</p>
|
||||
<p>
|
||||
<label><strong><%= t(:label_default_account) %></strong></label>
|
||||
@@ -24,7 +24,7 @@
|
||||
</div>
|
||||
|
||||
<fieldset class="box">
|
||||
<legend>Management & Synchronization</legend>
|
||||
<legend><%= l(:label_management_and_sync) %></legend>
|
||||
|
||||
<div style="margin-bottom: 15px;">
|
||||
<%= link_to t(:label_sync_now_items), sync_items_path, class: 'button icon icon-reload' %>
|
||||
|
||||
Reference in new issue
Block a user