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

Hello, I have a problem while adding a new field to account.move.

This is my code in module.py file, but nothing happened


from odoo import models, fields, api

class AccountMove(models.Model):

_inherit = 'account.move

x_myField = fields.Float(0, store=False)


This is my code on view.xml

    <record id="_myField" model = "ir.ui.view">

      <field name="name">Name</field>

      <field name="model">account.move</field>

      <field name="inherit_id" ref = "account.view_invoice_tree" />

      <field name="arch" type = "xml"> 

<field name="company_id" position="after">

          <field name = "x_myField" />

        </field>

      </field>

    </record>


No matter what I try, it always returns the error:

Field "x_myField" does not exist in model "account.move"



อวตาร
ละทิ้ง

This may look simple, everything looks fine other than this,

_inherit = 'account.move'

close your table with proper syntax

คำตอบที่ดีที่สุด

Hi,

It seems everything written correctly, just make sure that the python file has been imported in the init file and service has been restarted before upgrading the module.

class AccountMove(models.Model):
_inherit = 'account.move'

x_myField = fields.Float(0, store=False)

XML,

<record id="view_invoice_tree" model = "ir.ui.view">
<field name="name">Name</field>
<field name="model">account.move</field>
<field name="inherit_id" ref = "account.view_invoice_tree"/>
<field name="arch" type = "xml">
<field name="company_id" position="after">
<field name = "x_myField" />
</field>
</field>
</record>

For Reference: How To Inherit And Add New Fields To Existing Views

Thanks

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

Thank you very much! the quotes were fine... I think the problem was that I didn't reset the server :( I've been trying for hours and now it works!

อวตาร
ละทิ้ง