I'm customizing a module for hr.payroll that registers payment for the payslip, starting with a Register Payment wizard that then passes the data to account.payment when validated for the check to be printed. All other fields like memo and partner_id pass as expected, but doesn't fill anything in my one2many field, which is trying to pull the Name and Amount values from hr.payslip line_ids.
My One2Many field:
pay_line_ids = fields.One2many('pay.line.ids', 'payline_id', string='Paylines', readonly=False, copy=True)
class PayLineIds(models.Model):
_name = 'pay.line.ids'
_description = 'Payslip Payment Lines'
payline_id = fields.Many2one('account.payment', string='Pay Slip', required=False)
name = fields.Char(string='Name', required=False)
amount = fields.Float(digits=dp.get_precision('Payroll'))
I've attempted two methods. Any help is appreciated.
First is setting onchange
@api.onchange('pay_line_ids')
def _onchange_lines(self):
context = dict(self._context or {})
active_ids = context.get('active_ids', [])
payslip = self.env['hr.payslip'].browse(active_ids)
ids = []
for line in payslip.line_ids:
lines = {'name':line.name,'amount':line.amount}
ids.append(lines)
self.pay_line_ids = [(6,0,ids)]
File "/mnt/extra-addons/hr_payroll_payment/hr_payroll_register_payment.py", line 119, in _onchange_lines self.pay_line_ids = [(6,0,ids)] File "/usr/lib/python2.7/dist-packages/odoo/fields.py", line 933, in __set__ value = self.convert_to_cache(value, record) File "/usr/lib/python2.7/dist-packages/odoo/fields.py", line 2055, in convert_to_cache ids = OrderedSet(command[2]) File "/usr/lib/python2.7/dist-packages/odoo/tools/misc.py", line 1121, in __init__ self._map = OrderedDict((elem, None) for elem in elems) File "/usr/lib/python2.7/collections.py", line 52, in __init__ self.__update(*args, **kwds) File "/usr/lib/python2.7/_abcoll.py", line 567, in update self[key] = value File "/usr/lib/python2.7/collections.py", line 58, in __setitem__ if key not in self: TypeError: unhashable type: 'dict'
pay_line_ids = fields.One2many('pay.line.ids', 'payline_id', string='Paylines', readonly=False, copy=True, default=_default_line_ids)
@api.model
Which results in the following error:
DataError: invalid input syntax for integer: "amount" LINE 2: ... WHERE "pay_line_ids".id IN ('amount', ... ^