This question has been flagged
1 Reply
15186 Views

Hi friends,

When i inherit the code of account_voucher class it shows the error in following lines:

 res = super(account_voucher, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)

In terminal it shows error like:

for key, val in sel:
ValueError: too many values to unpack

 

Avatar
Discard

Post your full code and error log. This error is commonly raised when you have the wrong xml reference to the inherited form in your xml file.

Author

.py file class voucher_approval(osv.osv): _inherit = 'account.voucher' _columns = { 'type':fields.selection([ ('sale','Sale'), ('purchase','Purchase'), ('payment','Payment'), ('receipt','Receipt'), ], 'Default Type', readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'name':fields.char('Memo', size=256, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'date':fields.date('Date', readonly=True, select=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}, help="Effective date for accounting entries"), 'journal_id':fields.many2one('account.journal', 'Journal', required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'account_id':fields.many2one('account.account', 'Account', required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'line_ids':fields.one2many('account.voucher.line','voucher_id','Voucher Lines', readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'line_cr_ids':fields.one2many('account.voucher.line','voucher_id','Credits', domain=[('type','=','cr')], context={'default_type':'cr'}, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'line_dr_ids':fields.one2many('account.voucher.line','voucher_id','Debits', domain=[('type','=','dr')], context={'default_type':'dr'}, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'period_id': fields.many2one('account.period', 'Period', required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'narration':fields.text('Notes', readonly=True,states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'company_id': fields.many2one('res.company', 'Company', required=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'state':fields.selection( [('to_be_checked'), ('waiting_for_approval'), ('draft','Draft'), ('cancel','Cancelled'), ('proforma','Pro-forma'), ('posted','Posted') ], 'Status', readonly=True, size=32, track_visibility='onchange', help=' * The \'Draft\' status is used when a user is encoding a new and unconfirmed Voucher. \ \n* The \'Pro-forma\' when voucher is in Pro-forma status,voucher does not have an voucher number. \ \n* The \'Posted\' status is used when user create voucher,a voucher number is generated and voucher entries are created in account \ \n* The \'Cancelled\' status is used when user cancel voucher.'), 'amount': fields.float('Total', digits_compute=dp.get_precision('Account'), required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'tax_amount':fields.float('Tax Amount', digits_compute=dp.get_precision('Account'), readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'reference': fields.char('Ref #', size=64, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}, help="Transaction reference number."), 'move_ids': fields.related('move_id','line_id', type='one2many', relation='account.move.line', string='Journal Items', readonly=True), 'partner_id':fields.many2one('res.partner', 'Partner', change_default=1, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'pay_now':fields.selection([ ('pay_now','Pay Directly'), ('pay_later','Pay Later or Group Funds'), ],'Payment', select=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'tax_id': fields.many2one('account.tax', 'Tax', readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}, domain=[('price_include','=', False)], help="Only for tax excluded from price"), 'pre_line':fields.boolean('Previous Payments ?', required=False), 'date_due': fields.date('Due Date', readonly=True, select=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'payment_option':fields.selection([ ('without_writeoff', 'Keep Open'), ('with_writeoff', 'Reconcile Payment Balance'), ], 'Payment Difference', required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}, help="This field helps you to choose what you want to do with the eventual difference between the paid amount and the sum of allocated amounts. You can either choose to keep open this difference on the partner's account, or reconcile it with the payment(s)"), 'writeoff_acc_id': fields.many2one('account.account', 'Counterpart Account', readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'comment': fields.char('Counterpart Comment', size=64, required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'analytic_id': fields.many2one('account.analytic.account','Write-Off Analytic Account', readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'payment_rate_currency_id': fields.many2one('res.currency', 'Payment Rate Currency', required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}), 'payment_rate': fields.float('Exchange Rate', digits=(12,6), required=True, readonly=True, states={'draft':[('readonly',False)],'to_be_checked': [('readonly', False)]}, help='The specific rate that will be used, in this voucher, between the selected currency (in \'Payment Rate Currency\' field) and the voucher currency.'), 'approval_line': fields.one2many('account.voucher.approval.lines', 'voucher_id', 'Approval Lines'), } def button_send_for_approval(self, cr, uid, ids, context={}): print "uidddddddddddddddddd",uid approval_obj = self.pool.get('voucher.approval.hierarchy') approval_lines_obj = self.pool.get('res.users.voucher.approval.lines') voucher_approval_lines_obj = self.pool.get('account.voucher.approval.lines') models_data = self.pool.get('ir.model.data') res={} for this_id in self.browse(cr, uid, ids, context): approval_ids = approval_obj.search(cr, uid, [('start_amount','=',this_id.amount)],limit=1) if approval_ids: for approval in approval_obj.browse(cr, uid, approval_ids, context=context): user_ids = approval_lines_obj.search(cr, uid, [('hierarchy_id','=',approval.id)]) if user_ids: for user in approval_lines_obj.browse(cr, uid, user_ids, context=context): user_name = user.user_id.id voucher_approval_lines_obj.create(cr, uid, {'approver': user_name, 'voucher_id':this_id.id }) this_id.write({'no_of_approvals': approval.name, 'state': 'waiting_for_approval', }) dummy, form_view = models_data.get_object_reference(cr, uid, 'account_voucher', 'view_vendor_receipt_form') return { 'name': _('Account Voucher'), 'view_type': 'form', 'view_mode': 'form', 'res_model': 'account.voucher', 'domain': [], 'res_id': int(this_id.id), 'view_id': False, 'views': [(form_view or False, 'form')], 'type': 'ir.actions.act_window', } else: raise osv.except_osv(_('Cannot Proceed'), _('Please define an approval hierarchy.')) else: this_id.write({'no_of_approvals': 0, 'state': 'draft', }) return res def button_approve1(self, cr, uid, ids, context=None): print "uidddddddddddddddddd",uid approval_obj = self.pool.get('voucher.approval') voucher_approval_lines_obj = self.pool.get('account.voucher.approval.lines') now = datetime.now() for this_id in self.browse(cr, uid, ids, context): count = this_id.no_of_approvals if this_id.amount != 0.0: not_approved_user_ids = voucher_approval_lines_obj.search(cr, uid, [('status','=',False), ('invoice_id','=',this_id.id)],limit=1) if not_approved_user_ids: for lines in voucher_approval_lines_obj.browse(cr, uid, not_approved_user_ids, context): approver_id = lines.approver.id if uid == approver_id: user_ids = approval_obj.search(cr, uid, [('user_id','=',uid)],limit=1) if user_ids: for user in approval_obj.browse(cr, uid, user_ids, context): if user.start_amount = this_id.amount: if count == 0: this_id.write({'state': 'draft', }) else: approval_count = count-1 if approval_count == 0: this_id.write({'no_of_approvals': approval_count, 'state': 'draft', }) else: this_id.write({'no_of_approvals': approval_count, 'state': 'waiting_for_approval', }) lines.write({'approved_date': now, 'status': True, 'voucher_id': this_id.id }) else: raise osv.except_osv(_('Cannot Proceed'), _('Higher authority must approve the Invoice.')) else: raise osv.except_osv(_('Cannot Proceed'), _('Please define an approval range for the user')) else: raise osv.except_osv(_('Cannot Proceed'), _('Some other user in the hierarchy needs to approve the quotation.')) else: this_id.write({'state': 'waiting_for_approval', }) return True voucher_approval() class account_voucher_approval_lines(osv.osv): _name = "account.voucher.approval.lines" _description = 'Account Voucher Approval Lines' _columns = { 'approver' : fields.many2one('res.users', 'Approver'), 'voucher_id':fields.many2one('account.voucher', 'Account Invoice'), 'approved_date': fields.datetime('Approval Date'), 'status': fields.boolean('Approved'), } _defaults = { 'status':False, } account_voucher_approval_lines() class voucher_approval(osv.osv): _name = 'voucher.approval' _description = 'Account Voucher Approval' _columns = { 'user_id' : fields.many2one('res.users', 'User'), 'start_amount' : fields.float('Start Amount'), 'end_amount' : fields.float('End Amount'), } _defaults = { 'start_amount':1.0, 'end_amount':1.0, } voucher_approval() class voucher_approval_hierarchy(osv.osv): _name = 'voucher.approval.hierarchy' _description = 'Account Voucher Approval Hierarchy' _columns = { 'name': fields.integer('No of Approvals'), 'start_amount' : fields.float('Start Amount'), 'end_amount' : fields.float('End Amount'), 'users_approval_lines_ids': fields.one2many('res.users.voucher.approval.lines','hierarchy_id', 'User Approval Lines'), } _defaults = { 'start_amount':1.0, 'end_amount':1.0, } voucher_approval_hierarchy() class res_users_voucher_approval_lines(osv.osv): _name = "res.users.voucher.approval.lines" _description = 'Account voucher User Approval Lines' _columns = { 'user_id' : fields.many2one('res.users', 'User'), 'hierarchy_id':fields.many2one('voucher.approval.hierarchy', 'Voucher Approval Hierarchy'), } res_users_voucher_approval_lines() xml file voucher.approval.treevoucher.approval1treevoucher.approval.formvoucher.approvalform Voucher Approvalir.actions.act_windowvoucher.approvalformtree,formtreeformaccount.voucher.approval.lines.treeaccount.voucher.approval.lines1treeaccount.voucher.approval.extended.form.viewaccount.voucherform <xpath expr="/form/header/button[@name='proforma_voucher']" position="before"> <xpath expr="/form/header/field[@name='state']" position="replace"> account.payment.approval.extended.form.viewaccount.voucherform <xpath expr="/form/header/button[@name='proforma_voucher']" position="before"> <xpath expr="/form/header/field[@name='state']" position="replace">

Author

sorry alignment is like nasty i have inherited the account_voucher class and i have added two more states before draft state,added two more buttons for value based approval

Best Answer

Hi,

Try this one it may help you

for key, val in sel.iteritems():

Avatar
Discard