Refactor and improve invoices

- `runner 'Invoice.cancel_overdue_invoices'` in `schedule.rb` is
changed to `rake 'invoices:cancel_overdue'`.
- `invoices.payment_term` database column is removed and its value is
hardcoded in UI.
- `invoices.paid_at` is removed as unused
- `invoices.due_date` column's type is now `date`.
- `Invoice#invoice_items` renamed to `Invoice#items` and `Invoice`
interface to get a list of items is unified.
- Default date format in UI.
- Default translations are used.
- Tests improved.
- Specs converted to tests and removed along with factories.
- Database structure improved.
This commit is contained in:
Artur Beljajev 2018-10-17 12:21:04 +03:00
parent d86ec026e3
commit a97728c0f3
65 changed files with 758 additions and 341 deletions

View file

@ -33,13 +33,8 @@ module Admin
end
def cancel
if @invoice.cancel
flash[:notice] = t(:record_updated)
redirect_to([:admin, @invoice])
else
flash.now[:alert] = t(:failed_to_update_record)
render :show
end
@invoice.cancel
redirect_to [:admin, @invoice], notice: t('.cancelled')
end
def forward

View file

@ -6,8 +6,7 @@ class Registrar
def index
params[:q] ||= {}
invoices = current_registrar_user.registrar.invoices
.includes(:invoice_items, :account_activity)
invoices = current_registrar_user.registrar.invoices.includes(:items, :account_activity)
normalize_search_parameters do
@q = invoices.search(params[:q])
@ -35,13 +34,8 @@ class Registrar
end
def cancel
if @invoice.cancel
flash[:notice] = t(:record_updated)
redirect_to([:registrar, @invoice])
else
flash.now[:alert] = t(:failed_to_update_record)
render :show
end
@invoice.cancel
redirect_to [:registrar, @invoice], notice: t('.cancelled')
end
def download_pdf
@ -58,18 +52,7 @@ class Registrar
def normalize_search_parameters
params[:q][:total_gteq].gsub!(',', '.') if params[:q][:total_gteq]
params[:q][:total_lteq].gsub!(',', '.') if params[:q][:total_lteq]
ca_cache = params[:q][:due_date_lteq]
begin
end_time = params[:q][:due_date_lteq].try(:to_date)
params[:q][:due_date_lteq] = end_time.try(:end_of_day)
rescue
logger.warn('Invalid date')
end
yield
params[:q][:due_date_lteq] = ca_cache
end
end
end

View file

@ -29,7 +29,7 @@ class Registrar
if @payment.valid_response_from_intermediary? && @payment.settled_payment?
@payment.complete_transaction
if invoice.binded?
if invoice.paid?
flash[:notice] = t(:pending_applied)
else
flash[:alert] = t(:something_wrong)