跳至内容
菜单
此问题已终结
2 回复
16651 查看

 i am trying to create a button that link to account.invoice so this button can make a post request of json data to some url:

what i have achieved is i am able to create a button in customer invoice

right now when i click  on custom button the error appear like this

AttributeError: type object 'account.invoice' has no attribute 'labeltest'

So, this is my shippinglabel.xml file

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

            <field name="name">account.invoice.form.shippinglabel</field>

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

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

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

       <header>

           <button name="labeltest" type="object" string="Print Shipping Label" class="oe_highlight"/>

                </header>

   </field>

       </record>

my models.py

from odoo import models, fields, api import json, urllib2.

@api.multi def labeltest(self):

 data = {'ids': [12, 3, 4, 5, 6]}

 req = urllib2.Request('https://requestb.in/1bz11jv1')

 req.add_header('Content-Type', 'application/json')

 response = urllib2.urlopen(req, json.dumps(data))


PLEASE HELP            

形象
丢弃
最佳答案

Hi,

from odoo import models, fields, api

import json, urllib2

class CustomModel(models.Model):

_inherit = 'account.invoice'


@api.multi

def labeltest(self):

  data = {'ids': [12, 3, 4, 5, 6]}

  req = urllib2.Request('https://requestb.in/1bz11jv1')

 req.add_header('Content-Type', 'application/json')

  response = urllib2.urlopen(req, json.dumps(data))

make the python function as such,

Thank You

形象
丢弃
编写者 最佳答案

HI, still the same error appear, do i have to change anything in xml file ?

形象
丢弃

In the XML it seems that you didn't use xpath, i think your header section will get replaced with the new. there is no much problem in XML, check whether the python file is imported in the __init__.py file and give depends account in the manifest file

相关帖文 回复 查看 活动
0
8月 17
5451
1
6月 17
4143
2
4月 17
3987
5
8月 23
12906
3
1月 20
5327