콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
16484 화면

 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
5172
1
6월 17
3879
Paypal redirection 해결 완료
2
4월 17
3754
5
8월 23
12643
3
1월 20
5130