首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何创建带有计算字段的弹出向导?

如何创建带有计算字段的弹出向导?
EN

Stack Overflow用户
提问于 2020-03-10 14:29:33
回答 1查看 528关注 0票数 2

我正在尝试制作一个弹出式向导,其中包含一个来自计算函数的值。如下所示。我仍然无法设置selection字段值。在函数_get_quotation_so中,我总是得到self.medical_quotation_id FALSE。

是否有一种方法来填充选择字段值?也许在create函数中?有人能告诉我怎么做吗?

代码语言:javascript
复制
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())
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-12 13:57:36

我实际上解决了这个问题,但没有使用select field。我使用了many2one field,然后在xml中放置了使用另一个field进行筛选的domain

就是这样。如果python后端做不到这一点。那么我想视图前端就能做到这一点。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60619713

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档