netsuite icon indicating copy to clipboard operation
netsuite copied to clipboard

Added AsyncAddList to Invoice

Open prburke opened this issue 10 years ago • 6 comments

Added AsyncAddList action to Invoice. Also added basic infrastructure that can be extended to support other asynchronous requests (e.g. NetSuite::Async::Status, NetSuite::Async::WriteResponseList, etc.)

Here is a simplified example of how it can be used:

job_status = NetSuite::Records::Invoice.async_add_list([invoices])
if job_status
  begin
    job_status = NetSuite::Async::Status.get(job_id: job_status.job_id)
    ...
  end until job_status.finished?
  response = NetSuite::Async::WriteResponseList.get(job_id: job_id)
  ...
end

prburke avatar Mar 04 '15 21:03 prburke

@prburke could you add the usage example to the readme? Thanks for the PR!

iloveitaly avatar Mar 20 '15 11:03 iloveitaly

@prburke would love to get this (and any other PRs you have) merged—could you update the readme with some examples of how to use this?

iloveitaly avatar Oct 15 '21 15:10 iloveitaly

Hey @iloveitaly how is it going?

I did something like this:

module Commerce
  module NetSuite
    class AsyncJobStatus < ::Commerce::BaseJob
      queue_as :low

      def perform(job_id, transaction_type_class_name)
        job_status = ::NetSuite::Async::Status.get(job_id: job_id)

        if job_status.finished?
          response = ::NetSuite::Async::WriteResponseList.get(job_id: job_id)

          if response.list&.first&.status&.is_success
            transaction_type_class_name.constantize.new.audit
          else
            ::Raven.capture_message(
              "Failed sending #{transaction_type_class_name} report",
              extra: { message: response.list&.first&.status&.details&.first&.message }
            )
          end
        else
          ::Commerce::NetSuite::AsyncJobStatus.set(wait: 10.minutes).perform_later(job_id, transaction_type_class_name)
        end
      end
    end
  end
end

and I enqueue this job after send the record:

      def async_add_record_object
        return unless first_row

        job_status = record_object.class.async_add_list([record_object])

        ::Commerce::NetSuite::AsyncJobStatus.set(wait: 10.minutes).perform_later(job_status.job_id, self.class.name)
      end

diegopolido avatar Oct 15 '21 20:10 diegopolido

@diegopolido could you collaborate on this PR and add some examples to the readme? Would be great to get a simplified version of what you posted above in the core readme.

iloveitaly avatar Oct 18 '21 14:10 iloveitaly

I would need @prburke permissions to add code on this PR, right? I can do on a separated PR, what do you think?

diegopolido avatar Oct 20 '21 18:10 diegopolido

@diegopolido if he didn't allow collaborators to add to this PR, then that would be true. A separate PR is fine—let's just link it to this one.

iloveitaly avatar Jan 31 '22 18:01 iloveitaly