I am working on a membership module with recurring invoices from a contract. The invoice should have a copy of the line items of the contract.
The problem is, when i execute this, the result is a duplicate of the line item for a contract in the database. Is this a bug/feature/hook for saving invoices ? Now i am stuck because of this… Some one?
Are you sure it’s a duplicate in the database, as seen through myPhpAdmin, for example?
Or is it just a duplicate showing in some list view or subpanel in the UI? Because that could be a consequence of a SQL JOIN that is not ready for what you’re doing.
I am especially suspicious of this line here:
… because it is messing with the relationship. I don’t understand all the connections in the data, but I would be very careful to make sure the relationships are what SuiteCRM expects.
I’m running into an issue where duplicate line items are being created in the aos_products_quotes table when I programmatically generate an invoice from a contract.
Here’s what happens:
I have a contract with 1 line item.
When my renewal script runs (via a logic hook), I end up with 3 entries in the aos_products_quotes table:
2 rows with parent_type = 'AOS_Contracts'
1 row with parent_type = 'AOS_Invoices' (as expected)
I initially suspected the following line might be the cause:
However, even after commenting it out, the duplication still occurs.
I then discovered that the duplication only stops if I comment out the $invoice->save(); line. That’s what really triggers the unexpected additional aos_products_quotes entries linked to the contract.
So my questions are:
Is there an internal logic hook or workflow in SuiteCRM that might automatically copy aos_products_quotes from a contract to an invoice on save()?
Where could this behavior be coming from? I’ve already disabled all my custom save() logic temporarily.
Any help is greatly appreciated — happy to share the full logic hook and code if needed!
I’ve investigated further and discovered that the problem only occurs when the function is triggered via an after_save logic hook on the AOS_Contracts module. When I run the exact same logic from a cronjob (scheduler task), the unexpected behavior (e.g. line item duplication or multiple invoice generation) does not happen.
So for now, I have a working workaround by moving the logic out of the hook and into a scheduled process.
Still, I’d really like to understand why this happens — what is it about the after_save context that triggers this kind of behavior? If anyone has insights into how SuiteCRM handles subpanel relations, internal bean saves, or potential cascading updates during a save() inside a hook, I’d love to hear your thoughts.