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

Hi @oscarQ thank you for the solution :+1:

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

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:

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)


    @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

Yes, that’s possible :slightly_smiling_face:.
Wizard class, automatically gives you the active records in self.records. Example: modules/purchase/purchase.py · branch/default · Tryton / Tryton · GitLab

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):

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'

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