I’m looking at a new smart action to create “Expenses” objects in our DB. The challenge is that expenses can have multiple items, depending on the vat they have. Example:
- Cleaning 100€ / vat 10%
- Breakfast 25€ / vat 15%
Most of the time, an expense has only one vat rate (hence, 1 item). Though, it could be that we need to have X items in the expense.
On the object design, handling different items is quite simple, we could have JSON meta like this:
Though, on the creation form, I can’t envision how it could look like on Forest… Any idea on what it could look like?
Thanks and have a good day!
Thanks for your message!
If I understood well your use case, an
Expense is an array of price/vat/description (let’s call this object
expenseDetail here), and most of the time the array length is 1.
Just out of curiosity, what database are you using? And what is the
Expense model definition?
Depending on how you defined your models, the
expenseDetails might appear as related data to one
In that case, when using the regular create action of Forest Admin on
Expense (not a smart one), you should be able to add as many related data (
expenseDetails) as you want.
I have some other ideas if a smart action is required. But let’s see if you could simply use the regular action first!
Let me know.
Thanks a lot! A bit more details.
Fields of the expense object:
An expense has one provider
An expense has one building
An expense has one vendor
We could have indeed a child objects, expense_items, but it ask for slighlty more effort to the user:
- Creation of the expense
- Creation of the expense items
While the idea would be to have 1 action to create all the objects.
Do you think this would be do-able within Forest?
Or do you recommend we split the expense and its items?
If the expense item doesn’t have its own model, then when creating the expense we would be able to edit directly the JSON field (so adding the expense items inside the array…). Would it be acceptable for your users?
Otherwise, what I had in mind was to create a smart action with a form with many inputs:
… (and so on up to the max number of items you could have)
You could make only the inputs “1” required and the others optional. And you’ll create the expense into your agent from those inputs.
I don’t know if this is something acceptable too!
Did you create a project already?
Have you made any try yet?
Hey @adriguy, I think we might go for a tricky one, that we already use in another part of our system: Apart from the other fields we will ask for at the expense creation, we will ask:
- Net amount as type String, so that one or many can be added
- VAT as type String, so that one or many can be added
- Description as type String, so that one or many can be added
And the order of the strings will be respected for each field so that we can create expenses_items from this action directly.
@MaximeRobion it’s your call of course!
I would be afraid that this solution might be quite error-prone…