1

希望朋友们能帮帮我。

我有我创建的代码,目标是在日记帐分录中输入一个值。那是我的代码。

class deposit(osv.osv):
    _name='deposit.travel'
    _description='Deposit2 Travel'

    def action_process(self, cr, uid, ids, context=None):
        move_lines = []
        for deposit in self.browse(cr, uid, ids, context=context):
            # Create the move lines first
            move_lines.append((0,0, self.get_move_line(cr, uid, deposit, 'src')))
            #print deposit
            move_lines.append((0, 0, self.get_move_line(cr, uid, deposit, 'dest')))
            # Create the move for the deposit
            move = {
                'journal_id': deposit.journal_id.id,
                'date': deposit.date,
                'deposit_id': deposit.id,
                'name':'/',
                'line_id': move_lines
            }
            move_id = self.pool.get('account.move').create(cr, uid, move, context=context)
            self.pool.get('account.move').post(cr, uid, [move_id])
            self.write(cr, uid, [deposit.id], {'move_id': move_id,
                                              'state': 'done'},context=context)
        return True

        def get_move_line(self, cr, uid, deposit, type, context=None):
            return {
                'type': type,
                'name': deposit.name or '/',
                'debit': type == 'dest' and deposit.amount or 0.0,
                'credit': type == 'src' and deposit.amount or 0.0,
                'account_id': type == 'src' and deposit.dept_from.id or deposit.dept_to.id,
                'date': deposit.date,
                'deposit_id': deposit.id
            }
     _columns = {
        'partner':fields.many2one('res.partner','Partner',required=True),
        'date':fields.date('Date of Deposit',required=True),
        'period_id':fields.many2one('account.period','Force Period', required=True),
        'journal_id':fields.many2one('account.journal','Journal', required=True),
        'amount':fields.float('Amount',required=True,digits_compute=dp.get_precision('Account')),
        'move_id':fields.many2one('account.move','Journal Entry', readonly=True, select=1),
        'name':fields.related('move_id','name',type='char',readonly=True, size=64, relation='account.move',string='Deposit Ticket #'),
        'dept_from':fields.many2one('account.account','Deposit From'),
        'dept_to':fields.many2one('account.account','Deposit To'),
        'state': fields.selection([
            ('draft','Draft'),
            ('to_be_reviewed','Ready for Review'),
            ('done','Done'),
            ('cancel', 'Cancel')
            ],'State', select=True, readonly=True),
        }
         _defaults = {
        'date': time.strftime('%Y-%m-%d'),
        'period_id':_get_period,
        'state': 'draft',
         }
deposit()

但是当我单击放置命令action_process的按钮时,会出现错误,例如这个'deposit' 对象没有属性 'get_move_line'。get_move_line 是一个函数,为什么属性错误?我需要你的帮助。谢谢之前

4

2 回答 2

3

function 的缩进不正确get_move_line。取消缩进功能一个选项卡。

于 2012-08-02T07:54:42.670 回答
0

它应该像这样 _default 也应该在某个缩进级别:

class deposit(osv.osv):
    _name='deposit.travel'
    _description='Deposit2 Travel'

    def action_process(self, cr, uid, ids, context=None):
        move_lines = []
        for deposit in self.browse(cr, uid, ids, context=context):
            # Create the move lines first
            move_lines.append((0,0, self.get_move_line(cr, uid, deposit, 'src')))
            #print deposit
            move_lines.append((0, 0, self.get_move_line(cr, uid, deposit, 'dest')))
            # Create the move for the deposit
            move = {
                'journal_id': deposit.journal_id.id,
                'date': deposit.date,
                'deposit_id': deposit.id,
                'name':'/',
                'line_id': move_lines
            }
            move_id = self.pool.get('account.move').create(cr, uid, move, context=context)
            self.pool.get('account.move').post(cr, uid, [move_id])
            self.write(cr, uid, [deposit.id], {'move_id': move_id,
                                              'state': 'done'},context=context)
        return True

    def get_move_line(self, cr, uid, deposit, type, context=None):
        return {
            'type': type,
            'name': deposit.name or '/',
            'debit': type == 'dest' and deposit.amount or 0.0,
            'credit': type == 'src' and deposit.amount or 0.0,
            'account_id': type == 'src' and deposit.dept_from.id or deposit.dept_to.id,
            'date': deposit.date,
            'deposit_id': deposit.id,}

    _columns = {
        'partner':fields.many2one('res.partner','Partner',required=True),
        'date':fields.date('Date of Deposit',required=True),
        'period_id':fields.many2one('account.period','Force Period', required=True),
        'journal_id':fields.many2one('account.journal','Journal', required=True),
        'amount':fields.float('Amount',required=True,digits_compute=dp.get_precision('Account')),
        'move_id':fields.many2one('account.move','Journal Entry', readonly=True, select=1),
        'name':fields.related('move_id','name',type='char',readonly=True, size=64, relation='account.move',string='Deposit Ticket #'),
        'dept_from':fields.many2one('account.account','Deposit From'),
        'dept_to':fields.many2one('account.account','Deposit To'),
        'state': fields.selection([
            ('draft','Draft'),
            ('to_be_reviewed','Ready for Review'),
            ('done','Done'),
            ('cancel', 'Cancel')
            ],'State', select=True, readonly=True),
    }

    _defaults = {
        'date': time.strftime('%Y-%m-%d'),
        'period_id':_get_period,
        'state': 'draft',
    }

deposit()
于 2012-08-03T04:29:55.773 回答