How to create a pop up wizard with compute field?

strike_noir :

I am trying to make a pop-up wizard with one selection with values from a compute function. As shown below. I am still unable to set the selection field values. Inside function _get_quotation_so I always get self.medical_quotation_id FALSE.

Is there a way to fill the selection field values? Maybe in the create function? Can anyone show me how?

class MedicalQuotationInvoiceWizard(models.Model):
_inherit = 'medical.quotation'

    def compute_medical_quotation_so(self):
        # import ipdb; ipdb.set_trace()
        so = []
        sos = self.medical_quotation_so_ids.search([('medical_quotation_id.id', '=', self.id)])
        for record in sos:
            so.append((record.id, record.name))
        return so

    @api.multi
    def invoice_wizard(self):
        # for record in self:
        params={}
        view_id=self.env['prescription.invoice.wizard']
        params = {
            'medical_quotation_id': self.id,
            'invoice_version': self.invoice_version,
        }
        new = view_id.create(params)
        return {
            'type': "ir.actions.act_window",
            'name': "Invoice Wizard",
            'res_model': "prescription.invoice.wizard",
            'view_type': "form",
            'view_mode': "form",
            'res_id': new.id,
            'view_id': self.env.ref('medical_prescription.view_prescription_invoice_wizard', False).id,
            'target': "new",
        }



class PrescriptionInvoiceWizard(models.TransientModel):
_name = 'prescription.invoice.wizard'

    def _get_prescription_invoice(self):
        medical_quotation = self.env['medical.quotation']
        return medical_quotation.compute_prescription_invoice()

    invoice_version = fields.Selection(string="Invoice Version",
        selection=lambda self: self._get_prescription_invoice())

    logo = fields.Boolean("Company Logo")
    paging = fields.Boolean("Paging")

    medical_quotation_id = fields.Many2one(comodel_name='medical.quotation', string="Medical Quotation")

    @api.model
    def create(self, values):
        # Override the original create function for the res.partner model
        record = super(PrescriptionInvoiceWizard, self).create(values)
        import ipdb; ipdb.set_trace()

        medical_quotation = self.env['medical.quotation'].search([('id', '=', values['medical_quotation_id'])])

        record['medical_quotation_id'] = medical_quotation

        # Return the record so that the changes are applied and everything is stored.
        return record

    @api.depends('medical_quotation_id')
    def _get_quotation_so(self):
        # import ipdb; ipdb.set_trace()
        medical_quotation = self.env['medical.quotation'].search([('id', '=', self.medical_quotation_id.id)])  <--- HERE self.medical_quotation_id ALWAYS FALSE
        return medical_quotation.compute_medical_quotation_so()

    medical_quotation_so_select = fields.Selection(string="SO",
        selection=lambda self: self._get_quotation_so())
strike_noir :

I actually solved this, but without using select field. I used many2one field then in the xml I put domain that filter using another field.

Thats it. If the python back end cannot do it. Then I guess the view front end will do it.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220349&siteId=1