如何在发票上将Odoo发票默认日记帐设置为空?

时间:2016-02-28 15:32:30

标签: python inheritance odoo-8 odoo odoo-accounting

我希望客户强制在发票表单视图中选择日记,而不是让第一个预选。

在partner_id字段中更新默认值的正确方法是,更改默认日记选择事件是tigger。

修改

如果我尝试覆盖onchange_partner_id函数,我会收到以下错误:

File "/opt/PycharmProjects/gca_odoo/clientes/client_PRINCE/models.py", line 22, in onchange_partner_id
    self.journal_id = False
  File "/opt/PycharmProjects/gca_odoo/3party/server/openerp/fields.py", line 847, in __set__
    record.ensure_one()
  File "/opt/PycharmProjects/gca_odoo/3party/server/openerp/models.py", line 5306, in ensure_one
    raise except_orm("ValueError", "Expected singleton: %s" % self)
except_orm: ('ValueError', 'Expected singleton: account.invoice()')

我使用以下代码:

class account_invoice(models.Model):
    _inherit = 'account.invoice'

    @api.multi
    def onchange_partner_id(self, type, partner_id, date_invoice=False,payment_term=False, partner_bank_id=False, company_id=False):
        ret = super(account_invoice,self).onchange_partner_id(type=type, partner_id= partner_id,
        date_invoice=date_invoice,payment_term=payment_term, partner_bank_id=partner_bank_id, company_id=company_id)
        self.journal_id = False
        return ret

2 个答案:

答案 0 :(得分:0)

您可以覆盖onchange方法,调用为super,然后将jopurnal字段设置为False,以便将其清空。

编辑: 您正在使用 multi 装饰器。您应该使用 one

答案 1 :(得分:0)

我会做类似下面的代码,我假设你压倒正确的方法:

@api.multi
def onchange_partner_id(self, type, partner_id, date_invoice=False, payment_term=False,
                        partner_bank_id=False, company_id=False):
    res = super(invoice, self).onchange_partner_id(
        type, partner_id, date_invoice,
        payment_term, partner_bank_id, company_id
    )
    if partner_id:
        res['value'].update({
            'journal_id': False,
        })
    return res