如何在onchange上返回域名?

时间:2017-08-15 10:06:33

标签: openerp odoo-10

patient_id == nameLab出现时,我选择patient patient patient_id后我需要的是

class labinvoice (models.Model):
    _name = "lab.invoice"
    name = fields.Char(string='Invoice Reference',  default=lambda self: _('New'), store=True)
    patient_id = fields.Many2one(string='Patient',comodel_name='medical.patient',required=True, store=True )
    order_line = fields.One2many('lab.order.line', 'order_id', string='Order Lines', copy=True,  )  
    nameLab = fields.Many2one('medical.lab.patient',related='order_line.nameLab',string='name Lab', store=True)
    patient = fields.Many2one('medical.patient',related='order_line.patient',string='name Patient', store=True, readonly=True )
class LabOrderLine(models.Model):
    _name = 'lab.order.line'
    _description = 'labs Order Line'
    name = fields.Text(string='Description', required=True)
    order_id = fields.Many2one('lab.invoice', string='Invoice Reference', required=True, ondelete='cascade', index=True, copy=False)


    nameLab = fields.Many2one(
        string='Lab',
        comodel_name='medical.lab.patient',
        required=True,
        ondelete='cascade',
    )

    patient= fields.Many2one(
        'medical.patient',
        string='patient',
         related='nameLab.patient_id',
         readonly=True,
        required=True,
    )
                        <page string="Order Lines">
                            <field name="order_line" mode="tree,kanban" > 
                                <tree  editable="bottom" >

                                    <field name="nameLab"  />
                                    <field name="patient" /> 
                                    <field name="doctor_id"/>
                                     <field name="Test_Prix"/>
                                     <field name="test_type_id" />
                                     <field name="invoice_status"/>
                                     <field name="state" /> 
                                </tree>

我尝试使用onchange但是徒劳无功

    @api.onchange('patient_id')
    def onchange_patient_id(self):
        if self.patient_id:
            self.order_line = False
            return {'domain':{'nameLab':[('nameLab.patient','=',self.patient_id.id)]}}

1 个答案:

答案 0 :(得分:0)

您只需要在XML中的字段定义中使用domain

<field name="nameLab" domain="[('patient', '=', patient)]"/>