Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
6674 มุมมอง

Hi,

I have a custom Many2one field defined in the model account.invoice which uses the model account.analytic.account and is using a domain in xml as domain="[('customer', '=', True)]" required="1". The domain field here is from account.invoice so when i execute this code it gives an error as

ValueError: Invalid field 'customer' in leaf "<osv.ExtendedLeaf: ('customer', '=', True) on account_analytic_account (ctx: )>"

The field is defined as follows

class AccountInvoiceInherit(models.Model):
_inherit = 'account.invoice'
company_selection = fields.Many2one('account.analytic.account', string="Company")

In the view, i'm using as follows

<record model="ir.ui.view" id="invoice_form_inherit">
<field name="name">account.invoice.form.inherit.account</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet/group[1]/group[2]" position="replace">
<group>
<field name="company_selection" domain="[('customer', '=', True)]" required="1"/>
</group>
</xpath>
</field>
</record>

Can anyone tell me how to use the domain of another model?


อวตาร
ละทิ้ง
ผู้เขียน คำตอบที่ดีที่สุด

I know it is not the correct way to do it but for the time being i solved the issue by using attrs in xml of the invoice screen and did not use any attrs in bills screen as

<field name="company_selection" attrs="{'required': True}"/>

This essentially makes the field required in invoices and not required in bills, It solved the requirement but not in the right way.

If anyone knows the answer to the question, please do answer it.

Thanks,

Sameer

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

this worked for me

domain="[('customer', '!=', False)]"

อวตาร
ละทิ้ง
ผู้เขียน

I want the field to be required in one screen and not required in another and since the domain and the many2one fields model differ from each other it is throwing me an error and no it didn't work for me

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
ม.ค. 21
4023
5
ส.ค. 19
9411
Why won't this xpath work? แก้ไขแล้ว
1
เม.ย. 19
5569
1
มี.ค. 19
10514
Change field alignment(Vertical) in view แก้ไขแล้ว
1
ม.ค. 24
13562