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
  • Hi, thank you so much for your reply, it really helped me a lot.
    My relationships are One to Many and Many to Many, something like
    Order Management <<--->> Account <<---> Supplier
    so I guess I have to retrieve records using the second solution you told me.
    I can delete relationships and use only related fields, at the least for the One to Many relationships (I don't actually need the 'Many' part)..
    I have just one question: almost all the fields I need to fill in Invoice, are custom. How can I refer those fields? They are columns of the _cstm tables on DB and I don't know how to grab them.
    I was wondering if can I retrieve a record with
    $account->retrieve($bean->account_id);
    and refer a single fields as
    $account->field_name;
    or
    $account->field_name_c; //for a custom field
    Thank you so much for your support.
    Cheers.
Reply
  • Hi, thank you so much for your reply, it really helped me a lot.
    My relationships are One to Many and Many to Many, something like
    Order Management <<--->> Account <<---> Supplier
    so I guess I have to retrieve records using the second solution you told me.
    I can delete relationships and use only related fields, at the least for the One to Many relationships (I don't actually need the 'Many' part)..
    I have just one question: almost all the fields I need to fill in Invoice, are custom. How can I refer those fields? They are columns of the _cstm tables on DB and I don't know how to grab them.
    I was wondering if can I retrieve a record with
    $account->retrieve($bean->account_id);
    and refer a single fields as
    $account->field_name;
    or
    $account->field_name_c; //for a custom field
    Thank you so much for your support.
    Cheers.
Children
No Data