fix rubocop errors
This commit is contained in:
parent
09679812af
commit
bafa163ce5
8 changed files with 107 additions and 115 deletions
|
@ -9,9 +9,11 @@ class GroupOrderInvoicesController < ApplicationController
|
||||||
send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig[:contact][:tax_number]
|
send_group_order_invoice_pdf @group_order_invoice if FoodsoftConfig[:contact][:tax_number]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else raise RecordInvalid
|
else
|
||||||
redirect_back fallback_location: root_path, notice: 'Something went wrong', :alert => I18n.t('errors.general_msg', :msg => "#{error} " + I18n.t('errors.check_tax_number'))
|
raise RecordInvalid
|
||||||
end
|
end
|
||||||
|
rescue => error
|
||||||
|
redirect_back fallback_location: root_path, notice: 'Something went wrong', alert: I18n.t('errors.general_msg', msg: "#{error} " + I18n.t('errors.check_tax_number'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
@ -27,7 +29,7 @@ class GroupOrderInvoicesController < ApplicationController
|
||||||
def create
|
def create
|
||||||
go = GroupOrder.find(params[:group_order])
|
go = GroupOrder.find(params[:group_order])
|
||||||
@order = go.order
|
@order = go.order
|
||||||
goi = GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
|
GroupOrderInvoice.find_or_create_by!(group_order_id: go.id)
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.js
|
format.js
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,8 +12,8 @@ class GroupOrderInvoicePdf < RenderPDF
|
||||||
ordergroup = @options[:ordergroup]
|
ordergroup = @options[:ordergroup]
|
||||||
|
|
||||||
# From paragraph
|
# From paragraph
|
||||||
bounding_box [margin_box.right - 200, margin_box.top-20], width: 200 do
|
bounding_box [margin_box.right - 200, margin_box.top - 20], width: 200 do
|
||||||
text I18n.t('documents.group_order_invoice_pdf.invoicer')
|
text I18n.t('documents.group_order_invoice_pdf.invoicer')
|
||||||
move_down 7
|
move_down 7
|
||||||
text FoodsoftConfig[:name], size: fontsize(9), align: :left
|
text FoodsoftConfig[:name], size: fontsize(9), align: :left
|
||||||
move_down 5
|
move_down 5
|
||||||
|
@ -32,24 +32,23 @@ class GroupOrderInvoicePdf < RenderPDF
|
||||||
text I18n.t('documents.group_order_invoice_pdf.tax_number', :number => @options[:tax_number]), size: fontsize(9), align: :left
|
text I18n.t('documents.group_order_invoice_pdf.tax_number', :number => @options[:tax_number]), size: fontsize(9), align: :left
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Receiving Ordergroup
|
# Receiving Ordergroup
|
||||||
bounding_box [margin_box.left, margin_box.top - 20], width: 200 do
|
bounding_box [margin_box.left, margin_box.top - 20], width: 200 do
|
||||||
text I18n.t('documents.group_order_invoice_pdf.invoicee')
|
text I18n.t('documents.group_order_invoice_pdf.invoicee')
|
||||||
move_down 7
|
move_down 7
|
||||||
text I18n.t('documents.group_order_invoice_pdf.ordergroup.name', ordergroup: ordergroup.name.to_s ), size: fontsize(9)
|
text I18n.t('documents.group_order_invoice_pdf.ordergroup.name', ordergroup: ordergroup.name.to_s), size: fontsize(9)
|
||||||
move_down 5
|
move_down 5
|
||||||
if ordergroup.contact_address
|
if ordergroup.contact_address
|
||||||
text I18n.t('documents.group_order_invoice_pdf.ordergroup.contact_address', contact_address: ordergroup.contact_address.to_s ), size: fontsize(9)
|
text I18n.t('documents.group_order_invoice_pdf.ordergroup.contact_address', contact_address: ordergroup.contact_address.to_s), size: fontsize(9)
|
||||||
move_down 5
|
move_down 5
|
||||||
end
|
end
|
||||||
if ordergroup.contact_phone
|
if ordergroup.contact_phone
|
||||||
text I18n.t('documents.group_order_invoice_pdf.ordergroup.contact_phone', contact_phone: ordergroup.contact_phone.to_s ), size: fontsize(9)
|
text I18n.t('documents.group_order_invoice_pdf.ordergroup.contact_phone', contact_phone: ordergroup.contact_phone.to_s), size: fontsize(9)
|
||||||
move_down 5
|
move_down 5
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#invoice Date and nnvoice number
|
# invoice Date and nnvoice number
|
||||||
bounding_box [margin_box.right - 200, margin_box.top - 150], width: 200 do
|
bounding_box [margin_box.right - 200, margin_box.top - 150], width: 200 do
|
||||||
text I18n.t('documents.group_order_invoice_pdf.invoice_date', invoice_date: @options[:invoice_date].strftime(I18n.t('date.formats.default'))), align: :left
|
text I18n.t('documents.group_order_invoice_pdf.invoice_date', invoice_date: @options[:invoice_date].strftime(I18n.t('date.formats.default'))), align: :left
|
||||||
move_down 5
|
move_down 5
|
||||||
|
@ -69,36 +68,37 @@ class GroupOrderInvoicePdf < RenderPDF
|
||||||
total_net = 0
|
total_net = 0
|
||||||
# Articles
|
# Articles
|
||||||
|
|
||||||
tax_hash_net = Hash.new(0) #for summing up article net prices grouped into vat percentage
|
tax_hash_net = Hash.new(0) # for summing up article net prices grouped into vat percentage
|
||||||
tax_hash_gross = Hash.new(0) #same here with gross prices
|
tax_hash_gross = Hash.new(0) # same here with gross prices
|
||||||
|
|
||||||
group_order = GroupOrder.find(@options[:group_order].id)
|
group_order = GroupOrder.find(@options[:group_order].id)
|
||||||
marge = FoodsoftConfig[:price_markup]
|
marge = FoodsoftConfig[:price_markup]
|
||||||
|
|
||||||
# data table looks different when price_markup > 0
|
# data table looks different when price_markup > 0
|
||||||
if marge == 0
|
data = if marge == 0
|
||||||
data = [I18n.t('documents.group_order_invoice_pdf.no_price_markup_rows')]
|
[I18n.t('documents.group_order_invoice_pdf.no_price_markup_rows')]
|
||||||
else
|
else
|
||||||
data = [I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)]
|
[I18n.t('documents.group_order_invoice_pdf.price_markup_rows', marge: marge)]
|
||||||
end
|
end
|
||||||
goa_tax_hash = GroupOrderArticle.where(group_order_id: group_order.id).find_each.group_by {|oat| oat.order_article.price.tax}
|
goa_tax_hash = GroupOrderArticle.where(group_order_id: group_order.id).find_each.group_by { |oat| oat.order_article.price.tax }
|
||||||
goa_tax_hash.each do |tax, group_order_articles|
|
goa_tax_hash.each do |tax, group_order_articles|
|
||||||
group_order_articles.each do |goa|
|
group_order_articles.each do |goa|
|
||||||
# if no unit is received, nothing is to be charged
|
# if no unit is received, nothing is to be charged
|
||||||
next if goa.result.to_i == 0
|
next if goa.result.to_i == 0
|
||||||
|
|
||||||
order_article = goa.order_article
|
order_article = goa.order_article
|
||||||
goa_total_net = goa.result * order_article.price.price
|
goa_total_net = goa.result * order_article.price.price
|
||||||
goa_total_gross = goa.result * order_article.price.gross_price
|
goa_total_gross = goa.result * order_article.price.gross_price
|
||||||
data << [order_article.article.name,
|
data << [order_article.article.name,
|
||||||
goa.result.to_i,
|
goa.result.to_i,
|
||||||
number_to_currency(order_article.price.price),
|
number_to_currency(order_article.price.price),
|
||||||
number_to_currency(goa_total_net),
|
number_to_currency(goa_total_net),
|
||||||
tax.to_s + '%',
|
tax.to_s + '%',
|
||||||
number_to_currency(goa.total_price)]
|
number_to_currency(goa.total_price)]
|
||||||
tax_hash_net[tax.to_i] += goa_total_net
|
tax_hash_net[tax.to_i] += goa_total_net
|
||||||
tax_hash_gross[tax.to_i] += goa_total_gross
|
tax_hash_gross[tax.to_i] += goa_total_gross
|
||||||
total_net += goa_total_net
|
total_net += goa_total_net
|
||||||
total_gross += goa_total_gross
|
total_gross += goa_total_gross
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ class GroupOrderInvoicePdf < RenderPDF
|
||||||
# article information + data
|
# article information + data
|
||||||
table data, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table|
|
table data, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table|
|
||||||
table.header = true
|
table.header = true
|
||||||
table.position= :center
|
table.position = :center
|
||||||
table.cells.border_width = 1
|
table.cells.border_width = 1
|
||||||
table.cells.border_color = '666666'
|
table.cells.border_color = '666666'
|
||||||
|
|
||||||
|
@ -118,23 +118,22 @@ class GroupOrderInvoicePdf < RenderPDF
|
||||||
|
|
||||||
sum = []
|
sum = []
|
||||||
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_net'), number_to_currency(total_net)]
|
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_net'), number_to_currency(total_net)]
|
||||||
tax_hash_net.keys.each do |tax|
|
tax_hash_net.each_key.each do |tax|
|
||||||
sum << [nil,nil,nil,nil, I18n.t('documents.group_order_invoice_pdf.tax_included', tax: tax), number_to_currency(tax_hash_gross[tax] - tax_hash_net[tax])]
|
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.tax_included', tax: tax), number_to_currency(tax_hash_gross[tax] - tax_hash_net[tax])]
|
||||||
end
|
end
|
||||||
unless marge == 0
|
unless marge == 0
|
||||||
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.markup_included', marge: marge), number_to_currency(total_gross * marge/100.0)]
|
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.markup_included', marge: marge), number_to_currency(total_gross * marge / 100.0)]
|
||||||
end
|
end
|
||||||
end_sum = total_gross * (1 + marge/100.0)
|
end_sum = total_gross * (1 + marge / 100.0)
|
||||||
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_gross'), number_to_currency(end_sum)]
|
sum << [nil, nil, nil, nil, I18n.t('documents.group_order_invoice_pdf.sum_to_pay_gross'), number_to_currency(end_sum)]
|
||||||
# table for sum
|
# table for sum
|
||||||
table sum, position: :right, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table|
|
table sum, position: :right, cell_style: { size: fontsize(8), overflow: :shrink_to_fit } do |table|
|
||||||
sum.length.times do |count|
|
sum.length.times do |count|
|
||||||
table.row(count).columns(0..5).borders = []
|
table.row(count).columns(0..5).borders = []
|
||||||
end
|
end
|
||||||
table.row(sum.length-1).columns(0..4).borders = []
|
table.row(sum.length - 1).columns(0..4).borders = []
|
||||||
table.row(sum.length-1).border_bottom_width = 2
|
table.row(sum.length - 1).border_bottom_width = 2
|
||||||
table.row(sum.length-1).columns(5).borders = [:bottom]
|
table.row(sum.length - 1).columns(5).borders = [:bottom]
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
move_down 15
|
move_down 15
|
||||||
|
|
|
@ -63,7 +63,6 @@ class Mailer < ActionMailer::Base
|
||||||
subject: I18n.t('mailer.group_order_invoice.subject', group: @group.name, supplier: @supplier)
|
subject: I18n.t('mailer.group_order_invoice.subject', group: @group.name, supplier: @supplier)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# Sends order result for specific Ordergroup
|
# Sends order result for specific Ordergroup
|
||||||
def order_result(user, group_order)
|
def order_result(user, group_order)
|
||||||
@order = group_order.order
|
@order = group_order.order
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
class GroupOrderInvoice < ApplicationRecord
|
class GroupOrderInvoice < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :group_order
|
belongs_to :group_order
|
||||||
validates_presence_of :group_order
|
validates_presence_of :group_order
|
||||||
validates_uniqueness_of :invoice_number
|
validates_uniqueness_of :invoice_number
|
||||||
|
@ -8,10 +7,10 @@ class GroupOrderInvoice < ApplicationRecord
|
||||||
|
|
||||||
def generate_invoice_number(count)
|
def generate_invoice_number(count)
|
||||||
trailing_number = count.to_s.rjust(4, '0')
|
trailing_number = count.to_s.rjust(4, '0')
|
||||||
unless GroupOrderInvoice.find_by(invoice_number: Time.now.strftime("%Y%m%d") + trailing_number)
|
if GroupOrderInvoice.find_by(invoice_number: Time.now.strftime("%Y%m%d") + trailing_number)
|
||||||
Time.now.strftime("%Y%m%d") + trailing_number
|
|
||||||
else
|
|
||||||
generate_invoice_number(count.to_i + 1)
|
generate_invoice_number(count.to_i + 1)
|
||||||
|
else
|
||||||
|
Time.now.strftime("%Y%m%d") + trailing_number
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,7 +43,7 @@ class GroupOrderInvoice < ApplicationRecord
|
||||||
invoice_data[:order_articles] = {}
|
invoice_data[:order_articles] = {}
|
||||||
group_order.order_articles.each do |order_article|
|
group_order.order_articles.each do |order_article|
|
||||||
# Get the result of last time ordering, if possible
|
# Get the result of last time ordering, if possible
|
||||||
goa = group_order.group_order_articles.detect { |goa| goa.order_article_id == order_article.id }
|
goa = group_order.group_order_articles.detect { |tmp_goa| tmp_goa.order_article_id == order_article.id }
|
||||||
|
|
||||||
# Build hash with relevant data
|
# Build hash with relevant data
|
||||||
invoice_data[:order_articles][order_article.id] = {
|
invoice_data[:order_articles][order_article.id] = {
|
||||||
|
@ -55,6 +54,5 @@ class GroupOrderInvoice < ApplicationRecord
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
invoice_data
|
invoice_data
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -172,7 +172,6 @@ Rails.application.routes.draw do
|
||||||
get :unpaid, on: :collection
|
get :unpaid, on: :collection
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
resources :links, controller: 'financial_links', only: [:create, :show] do
|
resources :links, controller: 'financial_links', only: [:create, :show] do
|
||||||
collection do
|
collection do
|
||||||
get :incomplete
|
get :incomplete
|
||||||
|
|
|
@ -2,6 +2,6 @@ require 'factory_bot'
|
||||||
|
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :group_order_invoice do
|
factory :group_order_invoice do
|
||||||
group_order{ create :group_order}
|
group_order { create :group_order }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,59 +3,55 @@ require_relative '../spec_helper'
|
||||||
feature GroupOrderInvoice, js: true do
|
feature GroupOrderInvoice, js: true do
|
||||||
let(:admin) { create :user, groups: [create(:workgroup, role_finance: true)] }
|
let(:admin) { create :user, groups: [create(:workgroup, role_finance: true)] }
|
||||||
let(:article) { create :article, unit_quantity: 1 }
|
let(:article) { create :article, unit_quantity: 1 }
|
||||||
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id], ends: Time.now } # need to ref article
|
let(:order) { create :order, supplier: article.supplier, article_ids: [article.id], ends: Time.now } # need to ref article
|
||||||
let(:go) { create :group_order, order: order }
|
let(:go) { create :group_order, order: order }
|
||||||
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
let(:oa) { order.order_articles.find_by_article_id(article.id) }
|
||||||
let(:ftt) { create :financial_transaction_type }
|
let(:ftt) { create :financial_transaction_type }
|
||||||
let(:goa) { create :group_order_article, group_order: go, order_article: oa }
|
let(:goa) { create :group_order_article, group_order: go, order_article: oa }
|
||||||
|
|
||||||
|
include ActiveJob::TestHelper
|
||||||
|
|
||||||
|
before { login admin }
|
||||||
|
|
||||||
describe 'trigger process' do
|
after { clear_enqueued_jobs }
|
||||||
|
|
||||||
include ActiveJob::TestHelper
|
it 'does not enqueue MailerJob when order is settled if tax_number or options not set' do
|
||||||
|
goa.update_quantities 2, 0
|
||||||
|
oa.update_results!
|
||||||
|
visit confirm_finance_order_path(id: order.id)
|
||||||
|
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
||||||
|
expect(NotifyGroupOrderInvoiceJob).not_to have_been_enqueued
|
||||||
|
end
|
||||||
|
|
||||||
before { login admin }
|
it 'enqueues MailerJob when order is settled if tax_number or options are set' do
|
||||||
after { clear_enqueued_jobs }
|
goa.update_quantities 2, 0
|
||||||
|
oa.update_results!
|
||||||
|
order.reload
|
||||||
|
FoodsoftConfig[:group_order_invoices] = { use: true }
|
||||||
|
FoodsoftConfig[:contact][:tax_number] = 12_345_678
|
||||||
|
visit confirm_finance_order_path(id: order.id, type: ftt)
|
||||||
|
expect(page).to have_selector(:link_or_button, I18n.t('finance.balancing.confirm.clear'))
|
||||||
|
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
||||||
|
expect(NotifyGroupOrderInvoiceJob).to have_been_enqueued
|
||||||
|
end
|
||||||
|
|
||||||
it 'does not enqueue MailerJob when order is settled if tax_number or options not set' do
|
it 'does not generate Group Order Invoice when order is closed if tax_number not set' do
|
||||||
goa.update_quantities 2, 0
|
goa.update_quantities 2, 0
|
||||||
oa.update_results!
|
oa.update_results!
|
||||||
visit confirm_finance_order_path(id: order.id)
|
order.update!(state: 'closed')
|
||||||
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
order.reload
|
||||||
expect(NotifyGroupOrderInvoiceJob).not_to have_been_enqueued
|
visit finance_order_index_path
|
||||||
end
|
expect(page).to have_content(I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set'))
|
||||||
|
end
|
||||||
|
|
||||||
it 'enqueues MailerJob when order is settled if tax_number or options are set' do
|
it 'generates Group Order Invoice when order is closed if tax_number is set' do
|
||||||
goa.update_quantities 2, 0
|
goa.update_quantities 2, 0
|
||||||
oa.update_results!
|
oa.update_results!
|
||||||
order.reload
|
FoodsoftConfig[:contact][:tax_number] = 12_345_678
|
||||||
FoodsoftConfig[:group_order_invoices] = { use: true }
|
order.update!(state: 'closed')
|
||||||
FoodsoftConfig[:contact][:tax_number] = 12345678
|
order.reload
|
||||||
visit confirm_finance_order_path(id: order.id, type: ftt)
|
visit finance_order_index_path
|
||||||
expect(page).to have_selector(:link_or_button, I18n.t('finance.balancing.confirm.clear'))
|
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate')
|
||||||
click_link_or_button I18n.t('finance.balancing.confirm.clear')
|
expect(GroupOrderInvoice.all.count).to eq(1)
|
||||||
expect(NotifyGroupOrderInvoiceJob).to have_been_enqueued
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'does not generate Group Order Invoice when order is closed if tax_number not set' do
|
|
||||||
goa.update_quantities 2, 0
|
|
||||||
oa.update_results!
|
|
||||||
order.update!(state: 'closed')
|
|
||||||
order.reload
|
|
||||||
visit finance_order_index_path
|
|
||||||
expect(page).to have_content(I18n.t('activerecord.attributes.group_order_invoice.tax_number_not_set'))
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'generates Group Order Invoice when order is closed if tax_number is set' do
|
|
||||||
goa.update_quantities 2, 0
|
|
||||||
oa.update_results!
|
|
||||||
FoodsoftConfig[:contact][:tax_number] = 12345678
|
|
||||||
order.update!(state: 'closed')
|
|
||||||
order.reload
|
|
||||||
visit finance_order_index_path
|
|
||||||
click_link_or_button I18n.t('activerecord.attributes.group_order_invoice.links.generate')
|
|
||||||
expect(GroupOrderInvoice.all.count).to eq(1)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -4,58 +4,57 @@ describe GroupOrderInvoice do
|
||||||
let(:user) { create :user, groups: [create(:ordergroup)] }
|
let(:user) { create :user, groups: [create(:ordergroup)] }
|
||||||
let(:supplier) { create :supplier }
|
let(:supplier) { create :supplier }
|
||||||
let(:article) { create :article, supplier: supplier }
|
let(:article) { create :article, supplier: supplier }
|
||||||
let(:order){ create :order }
|
let(:order) { create :order }
|
||||||
let(:group_order) {create :group_order, order: order, ordergroup: user.ordergroup }
|
let(:group_order) { create :group_order, order: order, ordergroup: user.ordergroup }
|
||||||
|
|
||||||
describe 'erroneous group order invoice' do
|
describe 'erroneous group order invoice' do
|
||||||
let(:goi) { create :group_order_invoice, group_order_id: group_order.id }
|
let(:goi) { create :group_order_invoice, group_order_id: group_order.id }
|
||||||
|
|
||||||
it 'does not create group order invoice if tax_number not set' do
|
it 'does not create group order invoice if tax_number not set' do
|
||||||
expect{goi}.to raise_error(ActiveRecord::RecordInvalid)
|
expect { goi }.to raise_error(ActiveRecord::RecordInvalid)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'valid group order invoice' do
|
describe 'valid group order invoice' do
|
||||||
before do
|
before do
|
||||||
FoodsoftConfig[:contact][:tax_number] = 12345678
|
FoodsoftConfig[:contact][:tax_number] = 123_457_8
|
||||||
end
|
end
|
||||||
|
|
||||||
invoice_number1 = Time.now.strftime("%Y%m%d") + '0001'
|
invoice_number1 = Time.now.strftime("%Y%m%d") + '0001'
|
||||||
invoice_number2 = Time.now.strftime("%Y%m%d") + '0002'
|
invoice_number2 = Time.now.strftime("%Y%m%d") + '0002'
|
||||||
|
|
||||||
let(:user_2) { create :user, groups: [create(:ordergroup)] }
|
let(:user2) { create :user, groups: [create(:ordergroup)] }
|
||||||
|
|
||||||
let(:goi_1) { create :group_order_invoice, group_order_id: group_order.id }
|
let(:goi1) { create :group_order_invoice, group_order_id: group_order.id }
|
||||||
let(:goi_2) { create :group_order_invoice, group_order_id: group_order.id }
|
let(:goi2) { create :group_order_invoice, group_order_id: group_order.id }
|
||||||
|
|
||||||
let(:group_order_2) {create :group_order, order: order, ordergroup: user_2.ordergroup }
|
let(:group_order2) { create :group_order, order: order, ordergroup: user2.ordergroup }
|
||||||
|
|
||||||
let(:goi_3) { create :group_order_invoice, group_order_id: group_order_2.id }
|
let(:goi3) { create :group_order_invoice, group_order_id: group_order2.id }
|
||||||
let(:goi_4) { create :group_order_invoice, group_order_id: group_order_2.id, invoice_number: invoice_number1 }
|
let(:goi4) { create :group_order_invoice, group_order_id: group_order2.id, invoice_number: invoice_number1 }
|
||||||
|
|
||||||
it 'creates group order invoice if tax_number is set' do
|
it 'creates group order invoice if tax_number is set' do
|
||||||
expect(goi_1).to be_valid
|
expect(goi1).to be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets invoice_number according to date' do
|
it 'sets invoice_number according to date' do
|
||||||
number = Time.now.strftime("%Y%m%d") + '0001'
|
number = Time.now.strftime("%Y%m%d") + '0001'
|
||||||
expect(goi_1.invoice_number).to eq(number.to_i)
|
expect(goi1.invoice_number).to eq(number.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails to create if group_order_id is used multiple times for creation' do
|
it 'fails to create if group_order_id is used multiple times for creation' do
|
||||||
expect(goi_1.group_order.id).to eq(group_order.id)
|
expect(goi1.group_order.id).to eq(group_order.id)
|
||||||
expect{goi_2}.to raise_error(ActiveRecord::RecordNotUnique)
|
expect { goi2 }.to raise_error(ActiveRecord::RecordNotUnique)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'creates two different group order invoice with different invoice_numbers' do
|
it 'creates two different group order invoice with different invoice_numbers' do
|
||||||
expect(goi_1.invoice_number).to eq(invoice_number1.to_i)
|
expect(goi1.invoice_number).to eq(invoice_number1.to_i)
|
||||||
expect(goi_3.invoice_number).to eq(invoice_number2.to_i)
|
expect(goi3.invoice_number).to eq(invoice_number2.to_i)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'fails to create two different group order invoice with same invoice_numbers' do
|
it 'fails to create two different group order invoice with same invoice_numbers' do
|
||||||
goi_1
|
goi1
|
||||||
expect{goi_4}.to raise_error(ActiveRecord::RecordInvalid)
|
expect { goi4 }.to raise_error(ActiveRecord::RecordInvalid)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
Loading…
Reference in a new issue