How do you autopopulate a related field in custom module from a related field of another module?

I'm fighting against this issue since a couple of weeks and I can't figure out a way to do that.

I have a custom module for the orders management and I need to produce invoices automatically.
I'm following the example of 'ConverToInvoice.php' from Quotes module so, if I click on that button (under the Edit button in Detail View) I should create a new Invoice whose fields are pre-filled and  editable.
I have to grab fields' values from current order management.
My first problem is that a lot of those fields are related, too.

For example, I need to fill a related field called 'Suppliers' in my invoice. The value I need comes from a module (Suppliers) related to the Account, which is related to the current order management.

How can I easily grab that value and put it in my suppliers field?

I tryed to follow this guide  but it didn't worked.. probably I miss something.
I really need help, as soon as possible.

Thank you.

Parents
  • If you are creating a new invoice in the script then you can do so just populating the supplier id in the invoice bean populating the bean:

    //create a new bean
    $invoice=new AOS_Invoices();
    //for each object populate it
    $invoice->field_name = "field_value";
    //relate the invoice to the supplier
    $invoice->supplier_id = $supplier_id //check the naming of the relate field's id
    $invoice->save();

    Francesca
Reply
  • If you are creating a new invoice in the script then you can do so just populating the supplier id in the invoice bean populating the bean:

    //create a new bean
    $invoice=new AOS_Invoices();
    //for each object populate it
    $invoice->field_name = "field_value";
    //relate the invoice to the supplier
    $invoice->supplier_id = $supplier_id //check the naming of the relate field's id
    $invoice->save();

    Francesca
Children
No Data