This question has been flagged
2 Replies
16723 Views

Hi,

I have tree view of submitted timesheets,and if the manager needs to select some of them and need to approve it,how could it be done in a tree view?how can I insert a button in a tree view?

The need is,I have to approve multiple timesheet in a single click.

Avatar
Discard
Best Answer

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 . 

Avatar
Discard
Author

'list' object has no attribute 'setdefault'

It shows this error

Can you share the action that you've created?

Author

<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>

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

Author

OK thank you I'll try

Author

same error occurs

There there is a problem in the method batch_approve_leave

Author

@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

Can you copy/paste the full error message

Author

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'

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

Author

Thank you..It works

You're welcome, good luck.

Best Answer

You can see the example code of Journal Entries posting

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

Avatar
Discard

I am unable to select multiple records in post journal entries its give me singleton error.

raise ValueError("Expected singleton: %s" % self)

ValueError: Expected singleton: hr.expense.sheet(4, 3)

my code

from odoo import api, fields, models, _

class Multi_Expense_Inherit(models.TransientModel):

_inherit = "hr.expense.sheet.register.payment.wizard"

_name= 'multi.expense'

@api.multi

def multi_expense(self):

payslip_ids = self.env['hr.expense.sheet'].browse(self._context.get(

'active_ids'))

payslip_idsss = self.env['hr.expense'].search([])

for payslip in payslip_ids:

for abc in payslip_idsss:

if payslip.state == 'post':

abc.hr_expense_sheet_register_payment_wizard_action()

xml:

<act_window id="wizard_multi_payslip_approve" name="Multi Expenses Approve"

src_model="hr.expense.sheet" res_model="hr.expense.sheet.register.payment.wizard"

view_mode="form,tree" target="new" key2="client_action_multi"/>

i found this answer useful. Please locate this two files:

account_validate_account_move.py
account_validate_move_view.xml

At the following link:

https://github.com/odoo/odoo/blob/14.0/addons/account/wizard/

-