Skip to Content
Menu
This question has been flagged
2 Replies
2775 Views

i want to insert a new button 'Approval' as well as it's state 'Approval' in purchase order ,

but i don't know how to customize current state in purchase_view.xml

<field name="state" widget="statusbar" statusbar_visible="draft,sent,bid,approved,done" statusbar_colors='{"except_picking":"red","except_invoice":"red","confirmed":"blue"}' readonly="1"/>

to :

<field name="state" widget="statusbar" statusbar_visible="draft,sent,bid,approval,approved,done" statusbar_colors='{"except_picking":"red","except_invoice":"red","confirmed":"blue"}' readonly="1"/>

then when i hit Approval button i want to insert the current user login in my custom one2many column

here's the code :

approval_view.xml

<button name="view_picking" position="after">
            <button name="wtc_approval" state="Approval" string="Approval" type="object" class="oe_highlight"/>
</button>

approval.py

def wtc_approval(self, cr, uid, ids, context=None):
        todo = []
        for approval in self.browse(cr, uid, ids, context=context):
            if not approval.app_line:
                raise osv.except_osv(_('Error!'),_('Kolom approval belum terisi'))
            for x in approval.app_line:
                    todo.insert([1, 5,{'pelaksana':x.pelaksana}])        
        self.pool.get('wtc.approval.line').action_confirm(cr, uid, todo, context)
        for id in ids:
            self.write(cr, uid, [id], {'state' : 'approval', 'validator' : uid})
        return True

thanks in advance ,,

Avatar
Discard
Author

Traceback (most recent call last): File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 499, in _handle_exception return super(JsonRequest, self)._handle_exception(exception) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 516, in dispatch result = self._call_function(**self.params) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 282, in _call_function return checked_call(self.db, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/service/model.py", line 113, in wrapper return f(dbname, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 279, in checked_call return self.endpoint(*a, **kw) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 732, in __call__ return self.method(*args, **kw) File "/home/ajeng/odoo/openerp-8.0/openerp/http.py", line 375, in response_wrap response = f(*args, **kw) File "/home/ajeng/odoo/addons/HONDA/web/controllers/main.py", line 948, in call_button action = self._call_kw(model, method, args, {}) File "/home/ajeng/odoo/addons/HONDA/web/controllers/main.py", line 936, in _call_kw return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) File "/home/ajeng/odoo/openerp-8.0/openerp/api.py", line 237, in wrapper return old_api(self, *args, **kwargs) File "/home/ajeng/odoo/addons/HONDA/wtc_approval/approval.py", line 32, in wtc_approval todo.insert([1, 5,5,{'pelaksana':x.pelaksana}]) TypeError: insert() takes exactly 2 arguments (1 given)

@Ajeng.. Can you provided the definition of "insert" method?

Author

i want to insert new list in current state but i don't know the code

Best Answer

Insert takes 2 arguments: list.insert(index, item), so you are missing 1 arguement, which should be the index.  If you don't care about the index use list.append(item).  It will be added as the last item.

Avatar
Discard
Author Best Answer

to ivan , i am currently use append but it didn't work because i have a problem with button state

Avatar
Discard

You can help by describing what is the problem.

Author

here is the code for approval button method def wtc_approval(self, cr, uid, ids,vals, context=None): res = self.pool.get("res.users").browse(cr, uid, uid) data = [] for res in "app_line": data.append([0,False,{ 'sts':'2', 'pelaksana':uid, 'tanggal':datetime.today() }]) vals["app_line"] = data print "=================================",data return True , it should update my existing record in Approval line , before i hit the button approval it has no value ..

If you refresh the screen, does the line appears? I think it is a matter of display reload.