缩进使用条件

时间:2012-08-25 06:59:26

标签: openerp

请帮帮我......有什么不对

 def _amount_all(self, cr, uid, ids, name, args, context=None):
    res = {}
    for invoice in self.browse(cr, uid, ids, context=context):
        res[invoice.id] = {
            'amount_untaxed': 0.0,
            'amount_tax': 0.0,
            'amount_total': 0.0
        }
        for line in invoice.invoice_line:

            res[invoice.id]['amount_untaxed'] += line.price_subtotal
        for line in invoice.tax_line:
            res[invoice.id]['amount_tax'] += line.amount 
        res[invoice.id]['amount_total'] = res[invoice.id]['amount_tax'] + res[invoice.id]['amount_untaxed']
        cr.execute('select payment from sale_order where name = %s',(invoice.origin,))
        ads = cr.fetchone()
        pay = ads and ads[0] or None
        if pay == 'deposit':
            if invoice.partner_id.avail < 0:
                raise osv.except_osv(_('Invalid action !'), _('Deposit must be recharged')
                    if invoice.amount_total != res[invoice.id]['amount_total']:
                        temp = invoice.partner_id.depot - res[invoice.id]['amount_total']
                        cr.execute('update res_partner set depot=%s where id = %s', (temp, invoice.partner_id.id,))
    return res

我检查了条件,如果他使用存款支付,如果没有,如果没有则可用,那么存款减少就完成了。我想..这是正确的..但是当我跑步时,看起来像这样

如果invoice.amount_total!= res [invoice.id] ['amount_total']: SyntaxError:语法无效

1 个答案:

答案 0 :(得分:2)

为什么你在行raise osv.except_osv()之后给出2tabs(8个空格) 您的代码应该像

def _amount_all(self, cr, uid, ids, name, args, context=None):
    res = {}
    for invoice in self.browse(cr, uid, ids, context=context):
        res[invoice.id] = {
            'amount_untaxed': 0.0,
            'amount_tax': 0.0,
            'amount_total': 0.0
        }
        for line in invoice.invoice_line:

            res[invoice.id]['amount_untaxed'] += line.price_subtotal
        for line in invoice.tax_line:
            res[invoice.id]['amount_tax'] += line.amount 
        res[invoice.id]['amount_total'] = res[invoice.id]['amount_tax'] + res[invoice.id]['amount_untaxed']
        cr.execute('select payment from sale_order where name = %s',(invoice.origin,))
        ads = cr.fetchone()
        pay = ads and ads[0] or None
        if pay == 'deposit':
            if invoice.partner_id.avail < 0:
                raise osv.except_osv(_('Invalid action !'), _('Deposit must be recharged')
            if invoice.amount_total != res[invoice.id]['amount_total']:
                temp = invoice.partner_id.depot - res[invoice.id]['amount_total']
                cr.execute('update res_partner set depot=%s where id = %s', (temp, invoice.partner_id.id,))
    return res