简体   繁体   English

AttributeError:“ account.invoice.refund”对象没有属性“ journal_id”-Odoo v9社区

[英]AttributeError: 'account.invoice.refund' object has no attribute 'journal_id' - Odoo v9 community

I'm having a hard time with a Odoo v9 module I'm adapting, for debit/credit notes. 对于借记/贷方通知单,我正在适应的Odoo v9模块很难处理。

I'm fixing the bugs on it, so far, I have this issue right now, on this function: 我正在修复它上的错误,到目前为止,我现在在此功能上遇到此问题:

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')
    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)
                refund.signal_workflow('invoice_open')
                #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

Every time I try to make a refund invoice, it throws this error: 每当我尝试制作退款发票时,都会引发此错误:

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 280, 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 130, in compute_refund
journal_id = form.journal_id.id
AttributeError: 'account.invoice.refund' object has no attribute 'journal_id'

I've added this line to the logic journal_obj = self.pool.get('account.journal') after res_users_obj = self.pool.get('res.users') but still get the same error, I think I need to load the account.jounal objects for this operation, but with this line I still can't do it. 我已经添加了此行的逻辑journal_obj = self.pool.get('account.journal')之后res_users_obj = self.pool.get('res.users')但仍然得到同样的错误,我想我需要加载此操作的account.jounal对象,但是用这一行我还是做不到。

Does anybody can shed some light upon this? 有人能对此有所启发吗?

If You need more info please let me know. 如果您需要更多信息,请告诉我。

Thanks in advance! 提前致谢!

Activate Developer mode, go to Settings -> Technical -> Database Structure -> Models and search for account.invoice.refund then check if this model has any field named journal_id . 激活开发人员模式,转到设置->技术->数据库结构->模型,然后搜索account.invoice.refund然后检查该模型是否包含任何名为journal_id字段。 As I can see this field existed on v8 but does not exist on v9. 如我所见,此字段在v8上存在,但在v9上不存在。

You can check this on runbot.odoo.com admin/admin 您可以在runbot.odoo.com admin / admin上进行检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM