enable actions for multi (group) orders and ordergroup invoices
This commit is contained in:
parent
f676497e43
commit
e902aa0d5a
44 changed files with 550 additions and 324 deletions
|
|
@ -11,7 +11,7 @@ class GroupOrder < ApplicationRecord
|
|||
has_one :financial_transaction
|
||||
has_one :group_order_invoice
|
||||
belongs_to :ordergroup_invoice, optional: true
|
||||
belongs_to :multi_group_order, optional: true
|
||||
belongs_to :multi_group_order, optional: true, dependent: :destroy
|
||||
belongs_to :multi_order, optional: true
|
||||
belongs_to :updated_by, optional: true, class_name: 'User', foreign_key: 'updated_by_user_id'
|
||||
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
class MultiGroupOrder < ApplicationRecord
|
||||
belongs_to :multi_order
|
||||
has_many :group_orders, dependent: :nullify
|
||||
|
||||
after_destroy :delete_ordergroup_invoices
|
||||
|
||||
def ordergroup_invoice
|
||||
#TODO: delete if deleted
|
||||
group_orders.joins(:ordergroup_invoice).first&.ordergroup_invoice
|
||||
end
|
||||
has_many :group_orders
|
||||
has_one :ordergroup_invoice, dependent: :destroy
|
||||
|
||||
def ordergroup
|
||||
ordergroup_invoice&.ordergroup
|
||||
group_orders.first&.ordergroup
|
||||
end
|
||||
|
||||
private
|
||||
def price
|
||||
group_orders.map(&:price).sum
|
||||
end
|
||||
|
||||
def delete_ordergroup_invoices
|
||||
ordergroup_invoice&.destroy
|
||||
def group_order_invoice
|
||||
ordergroup_invoice
|
||||
end
|
||||
|
||||
def order
|
||||
multi_order
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,10 @@ class MultiOrder < ApplicationRecord
|
|||
has_many :orders, dependent: :nullify
|
||||
has_many :order_articles, through: :orders
|
||||
has_many :multi_group_orders, dependent: :destroy
|
||||
|
||||
#TODO: diese association lösen
|
||||
has_many :group_orders, through: :multi_group_orders
|
||||
has_many :ordergroups, through: :group_orders
|
||||
#TODO: wenn groupOrderInvoice existiert, dann fehler schmeißen..
|
||||
# has_many :ordergroups, through: :group_orders
|
||||
has_many :ordergroup_invoices, through: :group_orders
|
||||
|
||||
#make sure order has no multi_order_id
|
||||
|
|
@ -33,6 +34,11 @@ class MultiOrder < ApplicationRecord
|
|||
orders.map(&:foodcoop_result).compact_blank.sum
|
||||
end
|
||||
|
||||
def supplier
|
||||
#todo: who is this?
|
||||
orders.map(&:supplier).compact.first
|
||||
end
|
||||
|
||||
private
|
||||
def check_orders
|
||||
orders.each do |order|
|
||||
|
|
|
|||
|
|
@ -3,16 +3,27 @@ class OrdergroupInvoice < ApplicationRecord
|
|||
|
||||
belongs_to :multi_group_order, optional: true
|
||||
|
||||
has_many :group_orders, dependent: :nullify
|
||||
# has_many :group_orders, through: :multi_group_order, dependent: :nullify
|
||||
|
||||
validates_presence_of :invoice_number
|
||||
validates_uniqueness_of :invoice_number
|
||||
validate :tax_number_set
|
||||
after_initialize :init, unless: :persisted?
|
||||
|
||||
# accepts_nested_attributes_for :group_orders, :multi_group_order
|
||||
|
||||
|
||||
enum sequence_type: {
|
||||
FRST: "Erst-Lastschrift",
|
||||
RCUR: "Folge-Lastschrift",
|
||||
OOFF: "Einmalige Lastschrift",
|
||||
FNAL: "Letztmalige Lastschrift"
|
||||
}
|
||||
|
||||
def init
|
||||
self.invoice_date = Time.now unless invoice_date
|
||||
self.invoice_number = generate_invoice_number(self, 1) unless self.invoice_number
|
||||
self.payment_method = group_orders.first&.financial_transaction&.financial_transaction_type&.name || FoodsoftConfig[:group_order_invoices]&.[](:payment_method) || I18n.t('activerecord.attributes.group_order_invoice.payment_method') unless self.payment_method
|
||||
self.payment_method = multi_group_order.group_orders.first&.financial_transaction&.financial_transaction_type&.name || FoodsoftConfig[:ordergroup_invoices]&.[](:payment_method) || I18n.t('activerecord.attributes.ordergroup_invoice.payment_method') unless self.payment_method
|
||||
end
|
||||
|
||||
def ordergroup
|
||||
|
|
@ -27,13 +38,26 @@ class OrdergroupInvoice < ApplicationRecord
|
|||
errors.add(:cumulative_invoice, "Keine Steuernummer in FoodsoftConfig :contact gesetzt")
|
||||
end
|
||||
|
||||
def mark_sepa_downloaded
|
||||
self.sepa_downloaded = true
|
||||
self.save
|
||||
end
|
||||
|
||||
def unmark_sepa_downloaded
|
||||
self.sepa_downloaded = false
|
||||
self.save
|
||||
end
|
||||
|
||||
def name
|
||||
I18n.t('activerecord.attributes.group_order_invoice.name') + "_#{invoice_number}"
|
||||
I18n.t('activerecord.attributes.ordergroup_invoice.name') + "_#{invoice_number}"
|
||||
end
|
||||
|
||||
def load_data_for_invoice
|
||||
invoice_data = {}
|
||||
group_orders = multi_group_order.group_orders
|
||||
order = group_orders.map(&:order).first
|
||||
#how to define one order?
|
||||
|
||||
invoice_data[:pickup] = order.pickup
|
||||
invoice_data[:supplier] = order.supplier&.name
|
||||
invoice_data[:ordergroup] = group_orders.first.ordergroup
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue