title: Check count before insert data odoo 9
body: <p>How in custom module odoo 9 before insert new record in database, check is record exists?</p>
  
  <p>For example: </p>
  
  <p>If in table project.task we have name "PARIS" and date_deadline "2017-01-01" in code below I need warning before execute...</p>
  
  <pre class="lang-py prettyprint-override"><code>vals = {'name': 'PARIS','date_deadline': '2017-01-01']}
  create_new_task = http.request.env['project.task'].create(vals)
  </code></pre>
  
  <p>Or maybe try get count from project.task where name='PARIS' and date_deadline='2017-01-01' before click on button save!</p>
  
  <p>Any simple solution?</p>
  
  <pre><code>@api.one
  @api.constrains('date','time') #Time is Many2one
      def _check_existing(self):
          count = self.env['test.module'].search_count([('date','=',self.date),('time','=',self.time.id)])
          print(self.date)  #2017-01-01
          print(self.time.id) #1
          if(count &gt;= 1):
              raise ValidationError(_('DUPLICATE!'))
  </code></pre>
  
  <p>After try insert new record in database where is date = 2017-02-02 and time = 1 get this message:</p>
  
  <p>duplicate key value violates unique constraint "test_module_time_uniq"
  DETAIL: Key (time)=(1) already exists.</p>
  
  <p>Time exist but date is different! I need constrains for 2 value! In databse I have only one row where is date = 2017-01-01 and time = 1</p>