Odoo Help

1
2 Answers
1
Dennis Ochse
3/19/19, 8:20 AM

Best way to do this is to create a 'Server Action'.


1. Activate developer mode

2. Go to settings menu 'Technical - Actions - Server Actions'

3. Create action, this is pretty self explanatory when you open it, if not I can help

4. Save action

5. Click on 'Create contextual action' and this action will appear under the action button of the tree view . 

13 Comments
VENI V R
4/2/19, 2:50 AM

'list' object has no attribute 'setdefault'

It shows this error

Dennis Ochse
4/2/19, 2:55 AM

Can you share the action that you've created?

VENI V R
4/2/19, 2:56 AM

<record id="leave_approve_action_server" model="ir.actions.server">

<field name="name">Leave Approve</field>

<field name="type">ir.actions.server</field>

<field name="model_id" ref="leave_management_ft.model_hr_holidays"/>

<field name="binding_model_id" ref="leave_management_ft.model_hr_holidays"/>

<field name="state">code</field>

<field name="code">

if records:

for rec in records:

action = rec.batch_approve_leave()

</field>

</record>

Dennis Ochse
4/2/19, 3:05 AM

Okay, I don't have a complete overview of the fields you have a on your model but I'll try to help.

records: recordset of all records on which the action is triggered in multi-mode; may be void

So there is no need to check if records is filled, remove this line.

There is also no need to create a loop, remove this line.

And replace it with:

records.batch_approve_leave()

Go to your records in Odoo in the list view, select multiple records and click on 'Action -> <action_name>'.

let me know if that worked

VENI V R
4/2/19, 3:09 AM

OK thank you I'll try

VENI V R
4/2/19, 4:09 AM

same error occurs

Dennis Ochse
4/2/19, 4:27 AM

There there is a problem in the method batch_approve_leave

VENI V R
4/2/19, 5:12 AM

@api.one

def batch_approve_leave(self):

if self.state == 'confirm':

if self.holiday_status_id.double_validation:

self.sudo().update({

'state': 'approved'

})

else:

self.sudo().update({

'state': 'hr_approval'

})

mail_values_leave_request = {

'email_from': self.employee_id.work_email,

'email_to': self.employee_id.work_email,

'subject': ' Leave request approved ',

'body_html': 'Dear ' +self.employee_id.name+', <br><br> Your request for ' + self.holiday_status_id.name+ ' from ' + self.from_date +

' to '+ self.to_date + ' has been approved. <br>',

# 'notification': True,

}

mail = self.env['mail.mail'].create(mail_values_leave_request)

mail.send()

This is the function

Dennis Ochse
4/2/19, 6:18 AM

Can you copy/paste the full error message

VENI V R
4/2/19, 6:36 AM

Error:

Odoo Server Error

Traceback (most recent call last):

File "/home/devuser/Odoo/odoo-11C/odoo/http.py", line 650, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "/home/devuser/Odoo/odoo-11C/odoo/http.py", line 310, in _handle_exception

raise pycompat.reraise(type(exception), exception, sys.exc_info()[2])

File "/home/devuser/Odoo/odoo-11C/odoo/tools/pycompat.py", line 87, in reraise

raise value

File "/home/devuser/Odoo/odoo-11C/odoo/http.py", line 692, in dispatch

result = self._call_function(**self.params)

File "/home/devuser/Odoo/odoo-11C/odoo/http.py", line 342, in _call_function

return checked_call(self.db, *args, **kwargs)

File "/home/devuser/Odoo/odoo-11C/odoo/service/model.py", line 97, in wrapper

return f(dbname, *args, **kwargs)

File "/home/devuser/Odoo/odoo-11C/odoo/http.py", line 335, in checked_call

result = self.endpoint(*a, **kw)

File "/home/devuser/Odoo/odoo-11C/odoo/http.py", line 936, in __call__

return self.method(*args, **kw)

File "/home/devuser/Odoo/odoo-11C/odoo/http.py", line 515, in response_wrap

response = f(*args, **kw)

File "/home/devuser/Odoo/odoo-11C/odoo/addons/web/controllers/main.py", line 1229, in run

return clean_action(result) if result else False

File "/home/devuser/Odoo/odoo-11C/odoo/addons/web/controllers/main.py", line 308, in clean_action

action.setdefault('flags', {})

AttributeError: 'list' object has no attribute 'setdefault'

Dennis Ochse
4/2/19, 6:47 AM

Can you change @api.one to @api.multi, see if that makes a difference

VENI V R
4/2/19, 6:54 AM

Thank you..It works

Dennis Ochse
4/2/19, 7:03 AM

You're welcome, good luck.

0
Avatar

subbarao

--subbarao--

1108
| 5 1 5
Chennai, India
--subbarao--


subbarao
3/19/19, 8:39 AM

You can see the example code of Journal Entries posting

goto Journal Entries menu select few and check in action have Post selected entries.

Ask a Question
Writer
Keep Informed
1 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now