Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
2079 มุมมอง

I have added a new function to register a batch payment. When I am pressing it, its giving me the following error: 

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/odoo/src/odoo/odoo/http.py", line 654, in _handle_exception
    return super(JsonRequest, self)._handle_exception(exception)
  File "/home/odoo/src/odoo/odoo/http.py", line 301, in _handle_exception
    raise exception.with_traceback(None) from new_cause
ValueError: Expected singleton: account.payment(29747, 29748, 29749, 29750, 29751)

This is the code:

def action_register_payment(self):
_logger.info(f'\n\n\n START \n\n\n.')
action = self.mapped('slip_ids').action_register_payment()
_logger.info(f'\n\n\n Action {action}\n\n\n.')
payments = self.env['account.payment'].browse(action['res_ids'])
_logger.info(f'\n\n\n PAYMENT {payments}\n\n\n.')
batch_action = payments.with_context(payment_date = self.date_end).create_batch_payment()
_logger.info(f'\n\n\n batch_action {batch_action}\n\n\n.')
edit = self.write({'batch_payment_id': batch_action['res_id']})
_logger.info(f'\n\n\n EDit {edit}\n\n\n.')

return batch_action


On Odoo version 13 its working fine, but on Version 15 its not

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

In order to fix this singleton error, you might want to loop through the actions and process them individually, because it returns multiple payments

Here's a possible way to handle multiple actions:


def action_register_payment(self):

_logger.info(f'\n\n\n START \n\n\n.')


actions = self.mapped('slip_ids').action_register_payment()


for action in actions:

payments = self.env['account.payment'].browse(action['res_ids'])

_logger.info(f'\n\n\n PAYMENT {payments}\n\n\n.')

batch_action = payments.with_context(payment_date=self.date_end).create_batch_payment()

_logger.info(f'\n\n\n batch_action {batch_action}\n\n\n.')

edit = self.write({'batch_payment_id': batch_action['res_id']})

_logger.info(f'\n\n\n EDit {edit}\n\n\n.')


return batch_action # This might need to be adjusted based on your requirements


You have to verify in which variable, you are getting multiple records and based on it, iterate it over the for loop to fix the issue.



further more, you can refer below links for more detailed explanation

Singleton Error In Odoo || Reason And Solution || How To Fix Singleton Error in Odoo


hope this will help you

thanks

อวตาร
ละทิ้ง
ผู้เขียน

Thanks for your assistance, I tried to implement it and got this error:
TypeError: string indices must be integers

can you confirm from which line you are getting error?

ผู้เขียน

This line : payments = self.env['account.payment'].browse(action['res_ids'])

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 15
5522
Accounting entries in payroll Odoo 15 แก้ไขแล้ว
1
ก.ย. 23
4315
Batch Payment of Supplier Invoices แก้ไขแล้ว
1
ก.ย. 15
6675
1
เม.ย. 24
3048
Batches of pay slips แก้ไขแล้ว
1
ก.ย. 25
510