chore: rubocop
chore: fix api test conventions chore: rubocop -A spec/ chore: more rubocop -A fix failing test rubocop fixes removes helper methods that are in my opinion dead code more rubocop fixes rubocop -a --auto-gen-config
This commit is contained in:
parent
f6fb804bbe
commit
fb2b4d8a8a
331 changed files with 4263 additions and 4507 deletions
|
|
@ -3,13 +3,13 @@ class Invoice < ApplicationRecord
|
|||
include LocalizeInput
|
||||
|
||||
belongs_to :supplier
|
||||
belongs_to :created_by, :class_name => 'User', :foreign_key => 'created_by_user_id'
|
||||
belongs_to :created_by, class_name: 'User', foreign_key: 'created_by_user_id'
|
||||
belongs_to :financial_link, optional: true
|
||||
has_many :deliveries, dependent: :nullify
|
||||
has_many :orders, dependent: :nullify
|
||||
|
||||
validates_presence_of :supplier_id
|
||||
validates_numericality_of :amount, :deposit, :deposit_credit
|
||||
validates :supplier_id, presence: true
|
||||
validates :amount, :deposit, :deposit_credit, numericality: true
|
||||
validate :valid_attachment
|
||||
|
||||
scope :unpaid, -> { where(paid_on: nil) }
|
||||
|
|
@ -23,18 +23,18 @@ class Invoice < ApplicationRecord
|
|||
def attachment=(incoming_file)
|
||||
self.attachment_data = incoming_file.read
|
||||
# allow to soft-fail when FileMagic isn't present and removed from Gemfile (e.g. Heroku)
|
||||
self.attachment_mime = defined?(FileMagic) ? FileMagic.new(FileMagic::MAGIC_MIME).buffer(self.attachment_data) : 'application/octet-stream'
|
||||
self.attachment_mime = defined?(FileMagic) ? FileMagic.new(FileMagic::MAGIC_MIME).buffer(attachment_data) : 'application/octet-stream'
|
||||
end
|
||||
|
||||
def delete_attachment=(value)
|
||||
if value == '1'
|
||||
self.attachment_data = nil
|
||||
self.attachment_mime = nil
|
||||
end
|
||||
return unless value == '1'
|
||||
|
||||
self.attachment_data = nil
|
||||
self.attachment_mime = nil
|
||||
end
|
||||
|
||||
def user_can_edit?(user)
|
||||
user.role_finance? || (user.role_invoices? && !self.paid_on && self.created_by.try(:id) == user.id)
|
||||
user.role_finance? || (user.role_invoices? && !paid_on && created_by.try(:id) == user.id)
|
||||
end
|
||||
|
||||
# Amount without deposit
|
||||
|
|
@ -45,9 +45,9 @@ class Invoice < ApplicationRecord
|
|||
def orders_sum
|
||||
orders
|
||||
.joins(order_articles: [:article_price])
|
||||
.sum("COALESCE(order_articles.units_received, order_articles.units_billed, order_articles.units_to_order)" \
|
||||
+ "* article_prices.unit_quantity" \
|
||||
+ "* ROUND((article_prices.price + article_prices.deposit) * (100 + article_prices.tax) / 100, 2)")
|
||||
.sum('COALESCE(order_articles.units_received, order_articles.units_billed, order_articles.units_to_order)' \
|
||||
+ '* article_prices.unit_quantity' \
|
||||
+ '* ROUND((article_prices.price + article_prices.deposit) * (100 + article_prices.tax) / 100, 2)')
|
||||
end
|
||||
|
||||
def orders_transport_sum
|
||||
|
|
@ -63,11 +63,11 @@ class Invoice < ApplicationRecord
|
|||
protected
|
||||
|
||||
def valid_attachment
|
||||
if attachment_data
|
||||
mime = MIME::Type.simplified(attachment_mime)
|
||||
unless ['application/pdf', 'image/jpeg'].include? mime
|
||||
errors.add :attachment, I18n.t('model.invoice.invalid_mime', :mime => mime)
|
||||
end
|
||||
end
|
||||
return unless attachment_data
|
||||
|
||||
mime = MIME::Type.simplified(attachment_mime)
|
||||
return if ['application/pdf', 'image/jpeg'].include? mime
|
||||
|
||||
errors.add :attachment, I18n.t('model.invoice.invalid_mime', mime: mime)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue