This question has been flagged
2 Replies
14694 Views

 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            

Avatar
Discard
Best Answer

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

Avatar
Discard
Author Best Answer

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

Avatar
Discard

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