我需要的是一旦我選擇患者,當我搜索選擇nameLab時我想僅顯示與選定患者相關的實驗室(patient_id should = patient)。如何使用動態域名?
我的課:
class labinvoice (models.Model):
_name = "lab.invoice"
order_line = fields.One2many('lab.order.line', 'order_id', string='Order Lines', copy=True)
nameLab = fields.Many2one('medical.lab.patient',related='order_line.namelab')
patient = fields.Many2one('medical.patient',related='order_line.patient_id')
patient_id = fields.Many2one(comodel_name='medical.patient',required=True,)
class LabOrderLine(models.Model):
_name = 'lab.order.line'
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,
)
我的觀點:
<record id="view_invoice_lab_form" model="ir.ui.view">
<field name="name">lab.invoice.form</field>
<field name="model">lab.invoice</field>
<field name="arch" type="xml">
<form string="Labs Invoices" class="o_sale_order">
<sheet>
<div class="oe_title">
<h1>
<field name="name" readonly="1"/>
</h1>
</div>
<group>
<group>
<field name="patient_id" />
</group>
</group>
<notebook>
<page string="Order Lines">
<field name="order_line" mode="tree,kanban">
<tree string="labs Order Lines" editable="bottom" >
<field name="nameLab" />
<field name="patient" />
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
什麼我想要做的東西像saleOrder而是選擇客戶我在這裏選擇患者,而不是選擇我喜歡的產品ULD選擇關係到病人的nameLab選用
EDITS
@api.onchange('patient_id')
def onchange_patient(self):
if self.patient_id:
#to clean the line everytime i change the patient
self.order_line = False
return {'domain':{'nameLab':[('patient','=',self.patient_id.id)]}}
認爲問題是由於one2many關係
它返回no nameLab – Borealis
你可以用全視圖和錯誤更新你的問題嗎? – travisw
我做過了,請參閱編輯 – Borealis