如何创建带有计算字段的弹出向导?
How to create a pop up wizard with compute field?
我正在尝试制作一个弹出式向导,其中包含一个选择以及来自计算函数的值。如下所示。我仍然无法设置 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())
我实际上解决了这个问题,但没有使用 select field
。我使用了 many2one field
然后在 xml 中我使用另一个 field
.
放置了那个过滤器 domain
就是这样。如果python后端做不到。那我估计view前端就可以了
我正在尝试制作一个弹出式向导,其中包含一个选择以及来自计算函数的值。如下所示。我仍然无法设置 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())
我实际上解决了这个问题,但没有使用 select field
。我使用了 many2one field
然后在 xml 中我使用另一个 field
.
domain
就是这样。如果python后端做不到。那我估计view前端就可以了