Adopt model to reference GroupOrder in generated FinancialTransaction

This commit is contained in:
Patrick Gansterer 2019-11-04 04:33:43 +01:00
parent b6542fb711
commit 17059a8104
7 changed files with 17 additions and 5 deletions

View file

@ -5,6 +5,7 @@ class FinancialTransaction < ApplicationRecord
belongs_to :user
belongs_to :financial_link
belongs_to :financial_transaction_type
belongs_to :group_order
belongs_to :reverts, class_name: 'FinancialTransaction', foreign_key: 'reverts_id'
has_one :reverted_by, class_name: 'FinancialTransaction', foreign_key: 'reverts_id'

View file

@ -8,6 +8,7 @@ class GroupOrder < ApplicationRecord
belongs_to :ordergroup
has_many :group_order_articles, :dependent => :destroy
has_many :order_articles, :through => :group_order_articles
has_one :financial_transaction
belongs_to :updated_by, :class_name => "User", :foreign_key => "updated_by_user_id"
validates_presence_of :order_id

View file

@ -244,7 +244,7 @@ class Order < ApplicationRecord
for group_order in gos
if group_order.ordergroup
price = group_order.price * -1 # decrease! account balance
group_order.ordergroup.add_financial_transaction!(price, transaction_note, user, transaction_type)
group_order.ordergroup.add_financial_transaction!(price, transaction_note, user, transaction_type, nil, group_order)
end
end

View file

@ -80,9 +80,9 @@ class Ordergroup < Group
# Creates a new FinancialTransaction for this Ordergroup and updates the account_balance accordingly.
# Throws an exception if it fails.
def add_financial_transaction!(amount, note, user, transaction_type, link = nil)
def add_financial_transaction!(amount, note, user, transaction_type, link = nil, group_order = nil)
transaction do
t = FinancialTransaction.new(ordergroup: self, amount: amount, note: note, user: user, financial_transaction_type: transaction_type, financial_link: link)
t = FinancialTransaction.new(ordergroup: self, amount: amount, note: note, user: user, financial_transaction_type: transaction_type, financial_link: link, group_order: group_order)
t.save!
update_balance!
# Notify only when order group had a positive balance before the last transaction:

View file

@ -38,7 +38,11 @@
%td= h show_user(t.user)
- if FinancialTransactionType.has_multiple_types
%td= h t.financial_transaction_type.name
%td= h t.note
%td
- if t.group_order
= link_to t.note, t.group_order
- else
= t.note
- FinancialTransactionClass.sorted.each do |c|
%td.numeric{style: 'width:5em'}
- if t.financial_transaction_type.financial_transaction_class == c