Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jresinas committed Feb 2, 2017
1 parent 635384c commit 39ed686
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/facturaplus/custom_fields_controller_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ def self.included(base) # :nodoc:
base.send(:include, InstanceMethods)

base.class_eval do
skip_filter :require_admin, :only => :sync_client_field
before_filter :authorize_global, :only => :sync_client_field
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/facturaplus/fp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def self.get_clients(field)
FacturaplusClient.transaction do
FacturaplusClient.destroy_all
save_success = FacturaplusClient.create(res[:body]['results'].map{|c| {client_name: c['nameComercial'], biller_id: c['codeEmisor'].to_i, client_id: c['code'].to_i}})
res[:options] = res[:body]['results'].map{|c| c['nameComercial']}.uniq
res[:options] = res[:body]['results'].map{|c| c['nameComercial']}.uniq.sort
raise ActiveRecord::Rollback if !save_success
end
end
Expand Down
14 changes: 14 additions & 0 deletions lib/facturaplus/issue_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ def self.included(base) # :nodoc:
has_one :facturaplus_relation, :dependent => :destroy
after_save :facturaplus_bill_save, :if => Proc.new{Facturaplus::Fp.requirements?}
after_destroy :facturaplus_bill_destroy, :if => Proc.new{Facturaplus::Fp.requirements?}
# Patch to fix error when try to submit a NEW issue form after Rollback in facturaplus_bill_save method
before_create :patch_new_bill, :if => Proc.new{Facturaplus::Fp.requirements?}
end
end

Expand All @@ -31,6 +33,10 @@ def facturaplus_bill_destroy
end
end

def patch_new_bill
@new_bill = true
end

def facturaplus_bill_save
results = []
biller_field = self.custom_values.find_by(custom_field: Setting.plugin_redmine_facturaplus['biller_field'])
Expand All @@ -46,6 +52,10 @@ def facturaplus_bill_save
if client_id.blank?
# El cliente (o emisor) elegidos no son validos (el cliente no está registrado en el emisor en FacturaPlus) -> ERROR
errors[:base] << I18n.t('facturaplus.text_biller_client_not_valid')

# Patch to fix error when try to submit a NEW issue form after Rollback in facturaplus_bill_save method
self.destroy if @new_bill.present?

raise ActiveRecord::Rollback
end

Expand All @@ -72,6 +82,10 @@ def facturaplus_bill_save
FacturaplusMailer.facturaplus_sync_error(self)
message = res[:body]['result'].present? ? res[:body]['result'] : I18n.t('facturaplus.text_sync_fail')
errors[:base] << message

# Patch to fix error when try to submit a NEW issue form after Rollback in facturaplus_bill_save method
self.destroy if @new_bill.present?

raise ActiveRecord::Rollback
end
end
Expand Down

0 comments on commit 39ed686

Please sign in to comment.