تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
5 الردود
3524 أدوات العرض

I want to add a new field in a model. I create it in the python file:

class SaleOrderExt(models.Model):
    _inherit = ['sale.order']
    my_new_field = fields.Char()


and then I am going to show it in the view form:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
  <record id="view_order_form_extend" model="ir.ui.view">
  <field name="name">view.order.form.extend</field>
  <field name="model">sale.order</field>
  <field name="inherit_id" ref="sale_stock.view_order_form_inherit_sale_stock"/>
<field name="arch" type="xml">  <xpath expr="//field[@name='picking_policy']" position="after">
<field name="my_new_field"/>
</xpath> </field> </record> </data> </openerp>

When I install the module for the first time, the field appears and everything works fine. The problem comes when I try to update the module. 

It gives an exception that says that field product_tmpl_id doesn't exist.


How can it be possible? The first installation worked fine...

الصورة الرمزية
إهمال
الكاتب

@Sehrish ??? Did you read all the post?

أفضل إجابة

If you do anything that changed in python, restart database and odoo services to make sure things are reloaded.

And in odoo, update all modules and upgrade your custom module to latest.

You didn't show your python code, but product_tmpl_id should not be related to your custom field, and in that case you may have corrupted your .py file format.  Check tab/space coherence, indentation and pretty much all programming grammar errors.
The xml code you posted seems fine.

Edit:
try this
class SaleOrderExt(models.Model):
    _inherit = 'sale.order'
    my_new_field = fields.Char('My New Field')
 
الصورة الرمزية
إهمال
الكاتب

I updated the original post with the python code.

أفضل إجابة

I might be wrong, but I guess you also need to actually create the field you are using on your view.

If the field your are creating belongs to the sale.order module, try adding the following:

<record id="whatever_id_you_want" model="sale.order">

     <field name="name">my_new_field</field>

</record>


الصورة الرمزية
إهمال
الكاتب

I said that the field is created in the python file. That's not the point

المنشورات ذات الصلة الردود أدوات العرض النشاط
0
أكتوبر 16
5076
4
فبراير 25
2338
1
أغسطس 24
1978
2
نوفمبر 24
3162
3
أكتوبر 23
14694