Skip to Content
Menu
This question has been flagged
5 Replies
2608 Views

in the following code i make a journal entry and the debit many2many field when i add in many2many field one record it insert journal entry when more than one field in many2many i get error

ValueError: Expected singleton: employee.rsomconf(1, 2, 3, 4)

the insert code is:


 for rec in self:
            debit = credit = rec.currency_id.compute(rec.rosom_id.mokabel_maly, rec.currency_id)

            move = {
                'name': '/',
                'journal_id': rec.journal_id.id,
                'date': rec.year,

                'line_ids': [(0,0, {
                        'name': rec.name or '/',
                        'debit': debit,
                        'account_id': rec.rosom_id.journal.id,
                        'partner_id': rec.employee.user_id.partner_id.id,
                    }), (0,0 , {
                        'name': rec.name or '/',
                        'credit': credit,
                        'account_id': rec.recieve_account.id,
                        'partner_id': rec.employee.user_id.partner_id.id,
                    })]
            }
            move_id = self.env['account.move'].create(move)
            move_id.post()
            body =_("Rosom Paid")
            subject = _("Rosom - %s") % (rec.name,)
            rec.message_post(body=body, subject=subject,message_type="notification", subtype="mail.mt_comment",)
            return rec.write({ 'state': 'paid','move_id': move_id.id})




Avatar
Discard

Hello Ali,

Yes I was right;

rosom_id is a many2many type field;

You need to replace this line

rec.rosom_id.journal.id

With

rec.rosom_id[0].journal.id ;Make sure this line should be wrapped inside

if rec. rosom_id Condition; in order to avoid none type exception

or need to find the other way to set account_id in debit line

Thanks

Best Answer

Hello Ali,

It seems like rosom_id is a many2many field due to this you are getting issue in below line, 

rec.rosom_id.journal.id,

It will be helpful if you can share the field which belongs to "employee.rsomconf" model

Thanks

Anisha Bahukhandi

Technical Content Writer

Avatar
Discard
Author

# -*- coding: utf-8 -*-

import datetime

from datetime import datetime

from odoo import models, fields, api, _

from odoo.exceptions import Warning

from odoo.exceptions import UserError, ValidationError

import odoo.addons.decimal_precision as dp

class EmployeeRsomConf(models.Model):

_name = 'employee.rsomconf'

_description = 'Employee Rsom Elmokeem Config'

name = fields.Char(string='Rosom Name - اسم الرسوم', copy=False)

journal = fields.Many2one('account.account', string='حساب الرسوم')

mokabel_maly = fields.Float(string="مقابل مالي", digits=(6, 2))

currency_id = fields.Many2one('res.currency', string='Currency',

default=lambda self: self.env.user.company_id.currency_id)

class EmployeeRsom(models.Model):

_name = 'employee.rsom'

_description = 'Employee Rsom Elmokeem'

_inherit = 'mail.thread'

name = fields.Char(string='Request Number', copy=False)

rosom_id = fields.Many2many('employee.rsomconf', string='اختر الرسوم')

currency_id = fields.Many2one('res.currency', string='Currency',

default=lambda self: self.env.user.company_id.currency_id)

journal_id = fields.Many2one('account.journal', string='Journal')

recieve_account = fields.Many2one('account.account', string='حساب الخزينة')

employee = fields.Many2one('hr.employee', string='Employee', required=1, readonly=False)

jstate = fields.Selection([('draft', 'Draft'), ('cancel', 'Cancelled'),

('posted', 'Posted')], default="posted" ,string="journal state")

jtype = fields.Selection([('entry', 'Journal Entry'),('out_invoice', 'customer Invoice')],

default="entry", string="journal type")

year = fields.Date(string="التاريخ للعام")

payment_date = fields.Date(string='Paid Date',default=fields.Date.context_today)

state = fields.Selection([('draft', 'Draft'), ('waiting', 'Waiting for Approval'), ('cancel', 'Cancel'),

('confirm', 'Approved'), ('reject', 'Rejected'), ('paid', 'Paid')],

string="State", default="draft")

Hello Ali,

Yes I was right

rosom_id is a many2many type field;

You need to replace this line

rec.rosom_id.journal.id

With

rec.rosom_id[0].journal.id ;Make sure this line should be wrapped inside

if rec. rosom_id Condition; in order to avoid none type exception

or need to find the other way to set account_id in debit line

Thanks

Author Best Answer

all py file


# -*- coding: utf-8 -*-

import datetime
from datetime import datetime
from odoo import models, fields, api, _
from odoo.exceptions import Warning
from odoo.exceptions import UserError, ValidationError
import odoo.addons.decimal_precision as dp



class EmployeeRsomConf(models.Model):
    _name = 'employee.rsomconf'
    _description = 'Employee Rsom Elmokeem Config'
    name = fields.Char(string='Rosom Name - اسم الرسوم', copy=False)
    journal = fields.Many2one('account.account', string='حساب الرسوم')
    mokabel_maly = fields.Float(string="مقابل مالي", digits=(6, 2))
    currency_id = fields.Many2one('res.currency', string='Currency',
                              default=lambda self: self.env.user.company_id.currency_id)

class EmployeeRsom(models.Model):
    _name = 'employee.rsom'
    _description = 'Employee Rsom Elmokeem'
    _inherit = 'mail.thread'
    name = fields.Char(string='Request Number', copy=False)
    rosom_id = fields.Many2many('employee.rsomconf', string='اختر الرسوم')
    currency_id = fields.Many2one('res.currency', string='Currency',
                              default=lambda self: self.env.user.company_id.currency_id)
    journal_id = fields.Many2one('account.journal', string='Journal')
    recieve_account = fields.Many2one('account.account', string='حساب الخزينة')
    employee = fields.Many2one('hr.employee', string='Employee', required=1, readonly=False)
    jstate = fields.Selection([('draft', 'Draft'), ('cancel', 'Cancelled'),
                              ('posted', 'Posted')], default="posted" ,string="journal state")
    jtype = fields.Selection([('entry', 'Journal Entry'),('out_invoice', 'customer Invoice')],
                             default="entry", string="journal type")

    year = fields.Date(string="التاريخ للعام")
    payment_date = fields.Date(string='Paid Date',default=fields.Date.context_today)

    state = fields.Selection([('draft', 'Draft'), ('waiting', 'Waiting for Approval'), ('cancel', 'Cancel'),
                              ('confirm', 'Approved'), ('reject', 'Rejected'), ('paid', 'Paid')],
                             string="State", default="draft")


Avatar
Discard
Related Posts Replies Views Activity
4
May 24
10073
1
Apr 24
1563
0
Nov 23
525
1
Sep 23
566
2
Aug 23
2425