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
|
|
@ -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