andreh

andreh

Hi! First, I’d like to say that AshPhoenix.Form is really great, it makes dealing with forms so much easier! To implement an e-invoicing pipeline, I’m playing with Reactor and would like to know if it is possible to use it together with AshPhoenix.Form.

The main issue I’m facing is that my Invoice resource handles many items through manage_relationship and I don’t know how to pass that to the Reactor.

Here’s my Invoice resource:

defmodule Sales.Invoice do
  actions do
    defaults [:read]

    create :issue do
      primary? true

      accept [
        :discount_tax_rate,
        :discount_type,
        :discount_value,
        :issue_date,
        :payment_mean,
        :payment_terms_days,
        :payment_terms_days_end_of_month,
        :status,
        :contact_id
      ]

      argument :items, {:array, :map}, allow_nil?: false
      change manage_relationship(:items, type: :direct_control, order_is_key: :number)

      # many more validations and change
    end

    action :complete_issue, :struct do
     # Do I have to repeat alls arguments here?
     # And what about change manage_relationship(:items, type: :direct_control, order_is_key: :number)?
 
      run Reactors.IssueInvoice
    end
  end
end

And here’s the Reactor:

defmodule Reactors.IssueInvoice do
  use Ash.Reactor

  # Do I have to repeat all the inputs here?
  input :discount_tax_rate
  input :discount_type
  input :discount_value
  input :issue_date
  input :payment_mean
  input :payment_terms_days
  input :payment_terms_days_end_of_month
  input :status
  input :contact_id
  input :items

  step :check_access_point, Sales.Invoice.Steps.CheckAccessPoint do
    max_retries 3
  end

  transaction :create_invoice_transaction, [Sales.Invoice, Audit.AuditLog] do
    wait_for :check_access_point

    # Do I have to repeat all the inputs here?
    create :create_invoice, Sales.Invoice, :issue do
      inputs %{
        discount_tax_rate: input(:discount_tax_rate),
        discount_type: input(:discount_type),
        discount_value: input(:discount_value),
        issue_date: input(:issue_date),
        payment_mean: input(:payment_mean),
        payment_terms_days: input(:payment_terms_days),
        payment_terms_days_end_of_month: input(:payment_terms_days_end_of_month),
        status: input(:status),
        contact_id: input(:contact_id),
        items: input(:items)
      }
    end
    
     # Other steps...
    return :create_invoice
  end

  return :create_invoice_transaction
end

And of course, this is the error I get:

[error] ** (AshPhoenix.Form.NoFormConfigured) items at path [] must be configured in the form to be used with `inputs_for`. For example:

There is an argument called `items` on the action `Sales.Invoice.complete_issue`.

Perhaps you are missing a `change manage_relationship` for that argument, or it is not a type that can have forms generated for it?

So I guess the question is: it is possible to benefit from all the goodness of Ash.Changeset and Ash.Phoenix.Form while using Ash.Reactor?

I’ve managed to get a working solution using hooks, but it would be nice to benefit from the compensation and retry/backoff features of Reactor.

Hope I’m clear enough, let me know!

Showing Posts 1 to 1

ken-kost

ken-kost

Assuming you’re auto deriving the form; it doesn’t work in this case because it’s going through a generic action which has no manage_relationship that could be picked up. Hence the error, and the solution is to manually configure the nested forms, i.e. manually initialize the form and be explicit in what you want:

AshPhoenix.Form.for_action(Sales.Invoice, :complete_issue,  
  forms: [  
    items: [  
      type: :list,  
      resource: Sales.InvoiceItem,  
      create_action: :create 
    ]  
  ]  
)

More on this here.

When AshPhoenix.Form.params/1 is called on submit, it collects all nested item params and assembles them under the "items" key, which gets passed as the items argument to complete_issue — and from there into your Reactor.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews