Skip to Content
Menu
This question has been flagged

Odoo 10 - Custom Button with Action (Posting JSON customer data help !!)

Hi i have been able to create a button in the account.invoice with the following code in xml


<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="label" string="Print Shipping Label" class="oe_highlight"/>

                </header>

   </field>

</record>

 

Now i want to add function after user press the button

so in my 'models.py' i have try to put this code

def label(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))


so basically, i want to send some sample data to https://requestb.in/1bz11jv1

but it doesn't work when i restart odoo it give me this error in odoo.log

  File "/odoo/odoo-server/addons/labelprint/models/models.py", line 14
    def label(self):
    ^
IndentationError: unexpected indent


Am not very sure why it cause that error i have googled about Indentation and it doesnt help at all

Also i have a little more question on  if i can post json data already

how do i get information like customer.address , customer.phone, customer.name because i will be need these in sending json data


Thank you very much

Avatar
Discard
Best Answer

Hi,

For the indentation error, check if the function is in your model class. And if you did a copy/paste, sometimes it can gives you an issue even if your indentation seems good, so if you did a copy/paste, erase the function and rewrite it.

I hope this will help you,

Regards

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 24
99
2
Oct 24
195
1
Dec 23
604
1
Apr 21
5864
1
Mar 21
3351