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

関数のインデントが正しくありませんget_move_line。関数のインデントを1つのタブから外します。

于 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 に答える