如何在客户地址字段为空时禁止打印发票

How to prohibit printing invoice when the client address field is empty

我正在使用 odoo,我想在客户地址为空时禁止打印发票请问有什么帮助吗?如何验证此字段或任何其他字段是否为空 这是打印的功能我试过这段代码但没有任何反应

      def invoice_print(self,cr,uid,values):
    """ Print the invoice and mark it as sent, so that we can see more
        easily the next step of the workflow
    """
    res_partner = self.pool.get('res.partner')
    adresse_partner = res_partner.browse(cr, uid, values.get('partner_id')).street
    code_tva_partner = res_partner.browse(cr, uid, values.get('partner_id')).CodeTVA
    if (code_tva_partner==False)or (adresse_partner==False) :
        raise UserError(_(
            "you cannot print invoice unless you enter partner adress and code TVA "))
    elif (code_tva_partner==True) and (adresse_partner==True):
      self.ensure_one()
      self.sent = True
    return self.env['report'].get_action(self, 'account.report_invoice')

在此函数中,self 是您正在尝试的发票模型的记录 partner_id,它是此发票的客户记录。您所要做的就是在 self.partner_id.street 上添加一个 if 条件,如果该字段为 False,这意味着未设置,return 是一种警告。如果客户没有关联地址,这将阻止打印发票。