在我的自定义Odoo模块中,我必须在按钮单击时调用python函数。我遵循文件中的确切方式。但我得到的错误如下..
AttributeError: 'book.meeting' object has no attribute 'checkout_function'
我的代码如下..
class BookMRoom(models.Model):
_name="book.meeting"
name=fields.Char(string="Enter booking person name",required=True)
company_name=fields.Many2one('res.company','Enter your company name',required=True)
start_time=fields.Datetime(string="Starting date",select=True,required=True)
end_time=fields.Datetime(string="Ending date",select=True)
meeting_room=fields.Many2one('mroom', 'select the room',required=True)
room_info=fields.Many2one(comodel_name='mroom', field='description')
amenities=fields.Many2one('mroom','Select amenities')
ob =fields.Many2one('mroom')
@api.multi
def checkout_function(self,cr,uid,ids,context=None):
#raise Exception('Coming Inside Checkout Function')
current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self.end_time=current_time
meeting_obj=self.env['mroom']
meeting_room.status='available'
return meeting_room.status
我的XML文件..
<record model="ir.ui.view" id="book-form">
<field name="name">book.meeting.form</field>
<field name="model">book.meeting</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="booking_view_form">
<sheet string="Book meeting room">
<label for="name" string="Booking person name"/>
<h1>
<field name="name" placeholder="Booking person" class="oe_inline" string="Booking person"/>
</h1>
<group>
<group>
<field name="company_name" string="Company name"/>
<field name="meeting_room" string="select a room" options="{'no_quick_create':True,'no_create_edit':True}"/>
</group>
<group>
<field name="start_time" string="Booked date"/>
<field name="end_time" string="Ending date" help="Give check out time after the usage of room" disable="True"/>
<button string="Check Out" name='checkout_function' type="object"/>
</group>
</group>
<notebook>
<page string="Room description">
<field name="room_info"/>
</page>
<page string="Amenities of the room">
</page>
</notebook>
</sheet>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="booking_action">
<field name="name">Book meeting room</field>
<field name="res_model">book.meeting</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="book-tree"/>
<field name="help" type="html">
<p>To book a meeting room click create</p>
</field>
</record>
有人能帮助我吗?
答案 0 :(得分:4)
在您的情况下,问题基本上是因为您没有正确升级自定义模块,并且可能在创建方法后没有从终端重新启动odoo服务器。
第二点对于您在模型(类)中的新API装饰器方法中使用不需要的方法参数听取cr,uid,ids,context=None
非常重要。
请尝试检查重新启动odoo服务器,然后检查该模块操作中的影响。
我希望我的回答对您有所帮助:)。