Want to automatically populate QuoteItems based on account_id?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • worldmiros
    Senior Member
    • Dec 2015
    • 120

    Want to automatically populate QuoteItems based on account_id?

    Task entity in the db has a field called account_id. I want to automatically populate QuoteItem based on the account_id in the Task table. So when creating an invoice, and user selects an account name from Quote entity->account field, QuoteItems populate. If I was to use a query, it would look something like this: "SELECT task.* FROM account INNER JOIN task ON account.id = task.account_id AND task.status = 'Completed' ". If it was manually creating a relationship in entitydefs->task.json/quoteitem.json, it may look something like this:

    //Task entity
    //Task.json
    {
    "links": {
    "quoteitem": {
    "type": "hasMany",
    "foreign": "task",
    "entity": "QuoteItem",
    "isCustom": true
    }
    }
    }


    //QuoteItem entity
    //QuoteItem.json
    {
    "task": {
    "type": "link"
    }
    },
    "links": {
    "task": {
    "type": "belongsTo",
    "foreign": "quoteitems",
    "entity": "Task",
    "isCustom": true
    }
    }
    }

    Not too sure how and where(folder/file) to do this. May I have some assistance?
  • yuri
    Member
    • Mar 2014
    • 8478

    #2
    You can create Hook (in Hooks folder) for Quote record. And define afterSave or beforeSave method.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • worldmiros
      Senior Member
      • Dec 2015
      • 120

      #3
      yuri Which file are you referring to regarding "Quote record"? Espo/modules/advanced/hooks/quote/quoteitem.php?

      Comment

      • worldmiros
        Senior Member
        • Dec 2015
        • 120

        #4
        yuri Would appreciate as much help you can give. I'm on a timetable and I thank you for being patient with me.

        Comment

        Working...