我正在尝试制作一个弹出式向导,其中包含一个来自计算函数的值。如下所示。我仍然无法设置selection字段值。在函数_get_quotation_so中,我总是得到self.medical_quotation_id FALSE。
是否有一种方法来填充选择字段值?也许在create函数中?有人能告诉我怎么做吗?
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())发布于 2020-03-12 13:57:36
我实际上解决了这个问题,但没有使用select field。我使用了many2one field,然后在xml中放置了使用另一个field进行筛选的domain。
就是这样。如果python后端做不到这一点。那么我想视图前端就能做到这一点。
https://stackoverflow.com/questions/60619713
复制相似问题