How to get the related line items to an Invoice?

Hello,

I’m trying to get the line items that are related to an invoice.

Logic hook for AOS_Invoices:

$hook_array['after_save'][] = Array(1, 'DecrementProductStock', 'custom/modules/AOS_Invoices/Decrement.php', 'product', 'decrement_stocks');

And then in the class product:

function decrement_stocks ( &$bean, $event, $arguments)
{
			// Tried them all, only with empty arrays as return values
			// $oInvoice->load_relationship('aos_products_quotes');
			$bean->load_relationship('aos_line_item_groups');
			// $aProductQuotes = $oInvoice->aos_products_quotes->getBeans();
			$aProductQuotes = $bean->aos_line_item_groups->get();
			$aLineItemGroups = $bean->get_linked_beans('aos_line_item_groups', 'AOS_Line_Item_Groups');

Everytime I get an empty array.
So if I create and save an invoice, in the after_save logic hook, the invoice including the relationships, should have already been saved, right?
How can I access the line items?

I don’t know the answer, but I can try helping you find it…

There is code you can copy to do this:

https://github.com/salesagility/SuiteCRM/blob/master/modules/AOS_Products_Quotes/Line_Items.php#L88

Drop all that stuff to generate HTML and you’re left with the necessary database queries.

You might also learn something from browsing the database schema:

https://schema–suitedocs.netlify.com/schema/tables/aos_line_item_groups.html

Good luck. Please come back here and share your solution, if you can.