2016-08-23 79 views
1

我有这样的代码:NameError:全局名称“工作流程”没有定义 - Odoo V9

def compute_refund(self, cr, uid, ids, mode='refund', context=None): 
    """@param cr: the current row, from the database cursor, 
    @param uid: the current user’s ID for security checks, 
    @param ids: the account invoice refund’s ID or list of IDs 

    """ 
    inv_obj = self.pool.get('account.invoice') 
    reconcile_obj = self.pool.get('account.move.reconcile') 
    account_m_line_obj = self.pool.get('account.move.line') 
    mod_obj = self.pool.get('ir.model.data') 
    act_obj = self.pool.get('ir.actions.act_window') 
    wf_service = workflow 
    inv_tax_obj = self.pool.get('account.invoice.tax') 
    inv_line_obj = self.pool.get('account.invoice.line') 
    res_users_obj = self.pool.get('res.users') 
    if context is None: 
     context = {} 

每次我试图执行这个它抛出NameError: global name 'workflow' is not defined

这是完整的回溯:

Traceback (most recent call last): 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 646, in _handle_exception 
return super(JsonRequest, self)._handle_exception(exception) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 683, in dispatch 
result = self._call_function(**self.params) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 319, in _call_function 
return checked_call(self.db, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/service/model.py", line 118, in wrapper 
return f(dbname, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 312, in checked_call 
result = self.endpoint(*a, **kw) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 962, in __call__ 
return self.method(*args, **kw) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/http.py", line 512, in response_wrap 
response = f(*args, **kw) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/web/controllers/main.py", line 901, in call_button 
action = self._call_kw(model, method, args, {}) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/web/controllers/main.py", line 889, in _call_kw 
return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/api.py", line 250, in wrapper 
return old_api(self, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/wizard/account_invoice_refund.py", line 279, in invoice_refund 
return self.compute_refund(cr, uid, ids, data_refund, context=context) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/api.py", line 250, in wrapper 
return old_api(self, *args, **kwargs) 
File "/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/wizard/account_invoice_refund.py", line 116, in compute_refund 
wf_service = workflow 
NameError: global name 'workflow' is not defined 

我发现函数应该有self作为参数,但它确实有它,我对此很困惑,我不知道这是关于我打电话的方式workflow

任何想法?

在此先感谢!

编辑

这是所有的功能:

def compute_refund(self, cr, uid, ids, mode='refund', context=None): 
    """@param cr: the current row, from the database cursor, 
    @param uid: the current user’s ID for security checks, 
    @param ids: the account invoice refund’s ID or list of IDs 

    """ 
    inv_obj = self.pool.get('account.invoice') 
    reconcile_obj = self.pool.get('account.move.reconcile') 
    account_m_line_obj = self.pool.get('account.move.line') 
    mod_obj = self.pool.get('ir.model.data') 
    act_obj = self.pool.get('ir.actions.act_window') 
    wf_service = workflow 
    inv_tax_obj = self.pool.get('account.invoice.tax') 
    inv_line_obj = self.pool.get('account.invoice.line') 
    res_users_obj = self.pool.get('res.users') 
    if context is None: 
     context = {} 

    for form in self.browse(cr, uid, ids, context=context): 
     created_inv = [] 
     date = False 
     period = False 
     description = False 
     company = res_users_obj.browse(
      cr, uid, uid, context=context).company_id 
     journal_id = form.journal_id.id 
     for inv in inv_obj.browse(cr, uid, context.get('active_ids'), 
            context=context): 
      if inv.state in ['draft', 'proforma2', 'cancel']: 
       raise osv.except_osv(_('Error!'), _(
        'Cannot %s draft/proforma/cancel invoice.') % (mode)) 
      if inv.reconciled and mode in ('cancel', 'modify'): 
       raise osv.except_osv(_('Error!'), _(
        'Cannot %s invoice which is already reconciled, ' 
        'invoice should be unreconciled first. You can only ' 
        'refund this invoice.') % (mode)) 
      if form.period.id: 
       period = form.period.id 
      else: 
       period = inv.period_id and inv.period_id.id or False 

      if not journal_id: 
       journal_id = inv.journal_id.id 

      if form.date: 
       date = form.date 
       if not form.period.id: 
        cr.execute("select name from ir_model_fields \ 
            where model = 'account.period' \ 
            and name = 'company_id'") 
        result_query = cr.fetchone() 
        if result_query: 
         cr.execute("""select p.id from account_fiscalyear y 
             , account_period p 
             where y.id=p.fiscalyear_id \ 
          and date(%s) between p.date_start AND 
          p.date_stop and y.company_id = %s limit 1""", 
            (date, company.id,)) 
        else: 
         cr.execute("""SELECT id 
           from account_period where date(%s) 
           between date_start AND date_stop \ 
           limit 1 """, (date,)) 
        res = cr.fetchone() 
        if res: 
         period = res[0] 
      else: 
       date = inv.date_invoice 
      if form.description: 
       description = form.description 
      else: 
       description = inv.name 

      if not period: 
       raise osv.except_osv(_('Insufficient Data!'), 
            _('No period found on the invoice.')) 

      refund_id = inv_obj.refund(cr, uid, [ 
             inv.id], date, period, 
             description, journal_id, 
             context=context) 
      refund = inv_obj.browse(cr, uid, refund_id[0], context=context) 
      # Add parent invoice 
      inv_obj.write(cr, uid, [refund.id], 
          {'date_due': date, 
          'check_total': inv.check_total, 
          'parent_id': inv.id}) 
      inv_obj.button_compute(cr, uid, refund_id) 

      created_inv.append(refund_id[0]) 
      if mode in ('cancel', 'modify'): 
       movelines = inv.move_id.line_id 
       to_reconcile_ids = {} 
       for line in movelines: 
        if line.account_id.id == inv.account_id.id: 
         to_reconcile_ids[line.account_id.id] = [line.id] 
        if type(line.reconcile_id) != osv.orm.browse_null: 
         reconcile_obj.unlink(cr, uid, line.reconcile_id.id) 
       wf_service.trg_validate(uid, 'account.invoice', 
             refund.id, 'invoice_open', cr) 
       refund = inv_obj.browse(
        cr, uid, refund_id[0], context=context) 
       for tmpline in refund.move_id.line_id: 
        if tmpline.account_id.id == inv.account_id.id: 
         to_reconcile_ids[ 
          tmpline.account_id.id].append(tmpline.id) 
       for account in to_reconcile_ids: 
        account_m_line_obj.reconcile(
         cr, uid, to_reconcile_ids[account], 
         writeoff_period_id=period, 
         writeoff_journal_id=inv.journal_id.id, 
         writeoff_acc_id=inv.account_id.id 
        ) 
       if mode == 'modify': 
        invoice = inv_obj.read(cr, uid, [inv.id], 
              ['name', 'type', 'number', 
              'reference', 'comment', 
              'date_due', 'partner_id', 
              'partner_insite', 
              'partner_contact', 
              'partner_ref', 'payment_term', 
              'account_id', 'currency_id', 
              'invoice_line', 'tax_line', 
              'journal_id', 'period_id'], 
              context=context) 
        invoice = invoice[0] 
        del invoice['id'] 
        invoice_lines = inv_line_obj.browse(
         cr, uid, invoice['invoice_line'], context=context) 
        invoice_lines = inv_obj._refund_cleanup_lines(
         cr, uid, invoice_lines, context=context) 
        tax_lines = inv_tax_obj.browse(
         cr, uid, invoice['tax_line'], context=context) 
        tax_lines = inv_obj._refund_cleanup_lines(
         cr, uid, tax_lines, context=context) 
        invoice.update({ 
         'type': inv.type, 
         'date_invoice': date, 
         'state': 'draft', 
         'number': False, 
         'invoice_line': invoice_lines, 
         'tax_line': tax_lines, 
         'period_id': period, 
         'name': description, 
         'origin': self._get_orig(cr, uid, inv, context={}), 
        }) 
        for field in (
         'partner_id', 'account_id', 'currency_id', 
          'payment_term', 'journal_id'): 
         invoice[field] = invoice[ 
          field] and invoice[field][0] 
        inv_id = inv_obj.create(cr, uid, invoice, {}) 
        if inv.payment_term.id: 
         data = inv_obj.onchange_payment_term_date_invoice(
          cr, uid, [inv_id], inv.payment_term.id, date) 
         if 'value' in data and data['value']: 
          inv_obj.write(cr, uid, [inv_id], data['value']) 
        created_inv.append(inv_id) 
     xml_id = (inv.type == 'out_refund') and 'action_invoice_tree1' or \ 
       (inv.type == 'in_refund') and 'action_invoice_tree2' or \ 
       (inv.type == 'out_invoice') and 'action_invoice_tree3' or \ 
       (inv.type == 'in_invoice') and 'action_invoice_tree4' 
     result = mod_obj.get_object_reference(cr, uid, 'account', xml_id) 
     id = result and result[1] or False 
     result = act_obj.read(cr, uid, id, context=context) 
     invoice_domain = eval(result['domain']) 
     invoice_domain.append(('id', 'in', created_inv)) 
     result['domain'] = invoice_domain 
     return result 
+2

什么'workflow'应该为b è?它不会出现在代码中的任何地方。当然,如果在此之前没有定义它,那么当您引用它时将会是NameError。 –

+2

你认为'工作流程'是在哪里定义的?它没有出现在发布的代码中。 –

+0

显示/home/kristian/odoov9/odoo-9.0c-20160712/openerp/addons/debit_credit_note/wizard/account_invoice_refund.py的内容。在lne 116上,你使用变量'workflow',然后定义它 –

回答

1

你可以用下面的代码试试。

替换代码

wf_service.trg_validate(uid, 'account.invoice',refund.id, 'invoice_open', cr) 

refund.signal_workflow('invoice_open') 

编辑

删除以下行

wf_service = workflow 
+0

嗨,非常感谢,但仍然是相同的错误:(,我不明白 – NeoVe

+0

尝试用更新的答案。我不认为它会给出同样的错误。期待 –

+0

太棒了!非常感谢! – NeoVe

相关问题