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

I am trying to make a function for the button. 

This is the class:


from openerp import models, fields, api

class ennex(models.Model):

_name = 'ennex'

product_id = fields.Many2one('product.product', 'Product')

@api.one

def creafich(self):

file = open("newfile.txt", "w")

file.write("hello world in the new file")

file.write("and another line")

file.close()


and this is the form:


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

<field name="name">Articles</field>

<field name="model">ennex</field>

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

<form string="Ennex Article Form">

<sheet>

<group>

<field name="product_id"/>

</group>

<button name="creafich" string="Product" type="object" class="oe_highlight"/>

</sheet>

</form>

</field>

</record>


Why when I click the button, it say to me "AttributeError: 'ennex'' object has no attribute 'creafich'"?

الصورة الرمزية
إهمال
أفضل إجابة

ensure the indentation of @api.one def creafich(self):

And check the __init__.py also have the model imported.

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
0
ديسمبر 24
1254
2
سبتمبر 22
8372
1
يوليو 22
3170
4
مارس 19
9685
1
فبراير 25
12482