# Is it possible to pass the record ID to the Form class automatically when the user click the button?

**URL:** <https://discuss.tryton.org/t/is-it-possible-to-pass-the-record-id-to-the-form-class-automatically-when-the-user-click-the-button/8819>\
**Category:** Developer\
**Created:** [September 7, 2025, 3:43am UTC](https://discuss.tryton.org/t/is-it-possible-to-pass-the-record-id-to-the-form-class-automatically-when-the-user-click-the-button/8819 "2025-09-07T03:43:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bromoapp](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@bromoapp](https://discuss.tryton.org/u/bromoapp)\
**Post date:** [September 7, 2025, 3:43am UTC](https://discuss.tryton.org/t/is-it-possible-to-pass-the-record-id-to-the-form-class-automatically-when-the-user-click-the-button/8819/1 "2025-09-07T03:43:30Z")

</div>

Hi @oscarQ thank you for the solution 👍

Now I have another challenge, my wizard form code is like below:

```auto
class RAGQuotationReportForm(ModelView):
    'Download RAG Quotation Form'
    __name__ = 'ltl.crm.rag.quotation.report.form'

    quotation = fields.Many2One('ltl.crm.rag.quotation', 'Quotation', required=True)

    subject = fields.Char('Subject', readonly=True)
    to_company = fields.Char('To Company', readonly=True)
    to_company_address = fields.Char('To Company Address', readonly=True)
    attn_to_name = fields.Char('Attn To Name', readonly=True)
    attn_to_email = fields.Char('Attn To Email', readonly=True)
    attn_to_phone = fields.Char('Attn To Phone', readonly=True)
    quot_reff = fields.Char('Ref No', readonly=True)
    quot_no = fields.Char('No', readonly=True)
    quot_date = fields.Date('Date', readonly=True)
    quot_term = fields.Char('Term')
    quot_inquiry = fields.Selection([
        (None, 'Select..'),
        ('By Email', 'By Email'),
        ('By Phone', 'By Phone'),
        ('By Document', 'By Document'),
    ], 'Inquiry', sort=False, states={
        'readonly': Eval('quotation', None) == None,
    })
    quot_scenario = fields.Selection([
        (None, 'Select..'),
        ('12M', '12 Months'),
        ('6M', '6 Months'),
        ('3M', '3 Months'),
        ('Custom', 'Custom')
    ], 'Pricing Scenario', sort=False, states={
        'readonly': Eval('quotation', None) == None,
    }, required=True)

    @fields.depends('quotation')
    def on_change_quotation(self):
        if self.quotation:
            self.subject = self.quotation.subject
            self.to_company = self.quotation.proposal.client.company.name
            self.to_company_address = self.quotation.proposal.requestor.address
            self.attn_to_name = self.quotation.proposal.requestor.party.name
            self.attn_to_email = self.quotation.proposal.requestor.email
            self.attn_to_phone = self.quotation.proposal.requestor.mobile
            self.quot_reff = self.quotation.proposal.pro_no
            self.quot_no = self.quotation.quo_no
            self.quot_date = datetime.date.today()

```

And so far this form can works well… it can then be use to print the quotation based on selected quotation (Many2One field)

Currently the Quotation creation is like below:

 ![image](https://discuss-cdn.tryton.org/uploads/default/original/2X/1/1c617ef8aee588e2d23a599ab409ebb0875e341b.png)

Since the button is located in the Quotation generator UI, that actually stored Quotation ID.. is it possible to **PASSED** the **Quotation ID** of the opened Quotation to the Form class automatically when the user click the **Download Quotation** button? so there si no need for the user to select a Quotation at the wizard form?

My code that triggers the Wizard popup is like below (based on your previous guide)

```auto

    @classmethod
    def __setup__ (cls):
        super(RAGQuotation, cls). __setup__ ()
        cls._buttons.update({
            "print_quotation": {}
        })

    @classmethod
    @ModelView.button_action('ltl_crm.act_crm_rag_quotation_report_menu_item')
    def print_quotation(cls, obj):
        pass

```

If this possible, it would be great.

Bromo

---

<div class="post-metadata">

**Author:** ![oscarQ](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/oscarq/32/413_2.png) [@oscarQ](https://discuss.tryton.org/u/oscarQ)\
**Post date:** [September 8, 2025, 7:43am UTC](https://discuss.tryton.org/t/is-it-possible-to-pass-the-record-id-to-the-form-class-automatically-when-the-user-click-the-button/8819/2 "2025-09-08T07:43:24Z")

</div>

Yes, that’s possible 🙂.  
**Wizard** class, automatically gives you the active records in `self.records`. Example: [modules/purchase/purchase.py · branch/default · Tryton / Tryton · GitLab](https://foss.heptapod.net/tryton/tryton/-/blob/branch/default/modules/purchase/purchase.py?ref_type=heads#L2425)

In your case, if you really need to use a form view (not sure at all taht you need it), you can set a default value for the quotation field using the value from self.records. Here’s an improved example (note: this is untested and may require adaptation for your specific scenario):

```python
class RAGQuotationReportForm(ModelView):
    'Download RAG Quotation Form'
    __name__ = 'ltl.crm.rag.quotation.report.form'

    quotation = fields.Many2One('ltl.crm.rag.quotation', 'Quotation', required=True)

class RAGQuotationReport(Wizard):
    'Quotation Report Wizard'
    __name__ = 'ltl.crm.rag.quotation.report'

    start_state = 'form'

    form = StateView(
        'ltl.crm.rag.quotation.report.form',
        'ltl_crm.rag_quotation_report_form_view',
        [Button('Cancel', 'end', 'tryton-cancel'),
         Button('Print', 'print_', 'tryton-print', default=True)]
    )

    print_ = StateTransition()

    def default_form(self, fields):
        quotation, = self.records # active Quotation(s) are available here
        return {
            'quotation': self.records,
        }

    def transition_print_(self):
        # implement your report generation here
        return 'end'

```

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [September 9, 2025, 7:44am UTC](https://discuss.tryton.org/t/is-it-possible-to-pass-the-record-id-to-the-form-class-automatically-when-the-user-click-the-button/8819/3 "2025-09-09T07:44:08Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
