mirror of
https://github.com/LaCasemate/fab-manager.git
synced 2025-01-29 18:52:22 +01:00
fix running test create_as_admin_test
- do not create an empty payment gateway object if not needed
This commit is contained in:
parent
a2d870f680
commit
53e9a1c4f2
@ -22,7 +22,6 @@ class Invoice < PaymentDocument
|
||||
has_one :avoir, class_name: 'Invoice', foreign_key: :invoice_id, dependent: :destroy
|
||||
has_one :payment_schedule_item
|
||||
has_one :payment_gateway_object, as: :item
|
||||
accepts_nested_attributes_for :payment_gateway_object
|
||||
belongs_to :operator_profile, foreign_key: :operator_profile_id, class_name: 'InvoicingProfile'
|
||||
|
||||
before_create :add_environment
|
||||
|
@ -75,18 +75,19 @@ class InvoicesService
|
||||
method = if payment_method
|
||||
payment_method
|
||||
else
|
||||
operator&.admin? || (operator&.manager? && operator != user) ? nil : Setting.get('payment_gateway')
|
||||
operator&.admin? || (operator&.manager? && operator != user) ? nil : 'card'
|
||||
end
|
||||
|
||||
pgo = payment_id.nil? ? {} : { gateway_object_id: payment_id, gateway_object_type: payment_type }
|
||||
invoice = Invoice.new(
|
||||
invoiced: subscription || reservation,
|
||||
invoicing_profile: user.invoicing_profile,
|
||||
statistic_profile: user.statistic_profile,
|
||||
operator_profile_id: operator_profile_id,
|
||||
payment_gateway_object_attributes: pgo,
|
||||
payment_method: method
|
||||
)
|
||||
unless payment_id.nil?
|
||||
invoice.payment_gateway_object = PaymentGatewayObject.new(gateway_object_id: payment_id, gateway_object_type: payment_type)
|
||||
end
|
||||
|
||||
InvoicesService.generate_invoice_items(invoice, payment_details, reservation: reservation, subscription: subscription)
|
||||
InvoicesService.set_total_and_coupon(invoice, user, payment_details[:coupon])
|
||||
|
@ -91,12 +91,11 @@ class PaymentScheduleService
|
||||
invoicing_profile: payment_schedule_item.payment_schedule.invoicing_profile,
|
||||
statistic_profile: payment_schedule_item.payment_schedule.statistic_profile,
|
||||
operator_profile_id: payment_schedule_item.payment_schedule.operator_profile_id,
|
||||
payment_gateway_object_attributes: {
|
||||
gateway_object_id: payment_id,
|
||||
gateway_object_type: payment_type
|
||||
},
|
||||
payment_method: payment_method
|
||||
)
|
||||
unless payment_id.nil?
|
||||
invoice.payment_gateway_object = PaymentGatewayObject.new(gateway_object_id: payment_id, gateway_object_type: payment_type)
|
||||
end
|
||||
# complete the invoice with some InvoiceItem
|
||||
if payment_schedule_item.first?
|
||||
complete_first_invoice(payment_schedule_item, invoice)
|
||||
|
Loading…
x
Reference in New Issue
Block a user