Skip to content
Advertisement

Using an _sql_constraints in Odoo 12 date

Hi I created the following model:

class PrescriptionsPrescriptions(models.Model):
  _name = 'prescriptions.prescriptions'
  name = fields.Many2one('res.users','Name', default=lambda self: self.env.user, readonly=True)
  Date_entered = fields.Date(string='Date', default=fields.Date.today())
  paper_prescriptions = fields.Selection([('yes', 'Yes'), ('no', 'No')], string='Paper Prescriptions?')    

However I cannot get the _sql_constraints to work:

_sql_constraints = [('log_unique','unique(name,Date_entered)','You have already logged data for that date.')]

I’m trying to get it so that each person can log only one prescription per Date_entered. Would greatly appreciate any help. 🙂

Advertisement

Answer

Odoo will not be able to add the constraint because of a psycopg2.ProgrammingError

column “date_entered” named in key does not exist

You just need to rename it to date_entered and update the module.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement