Search code examples
python-2.7odoo-9

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


I'm using odoo and i want to prohibit printing invoices when client adresse is empty any idea for help please ? How can'i verify if this field or any other field is empty or not this the function of printing i tried this code but nothing is happend

      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')

Solution

  • In this function self is the record of invoice model that you are trying partner_id which is the client record for this invoice. All you have to do is add a if condition on self.partner_id.street and if that field is False which means not set, return a kind of warning. Which will prevent invoice from printing if the client has no address associated.