user3110268
user3110268

Reputation: 1

How to throw warning if one or two fields are empty in OpenERP

I have a question about OpenERP. How to throw warning if one of the fields is empty? for example, when adding a Product it should give a warning when we forget to add the Name property.

In this case I would like to add more mandatory fields, such as Product Code, etc. Sorry, I'm still new with this system.

Upvotes: 0

Views: 1698

Answers (2)

Pooja
Pooja

Reputation: 573

In order to check for duplicate values you can use _sql_constraints.

You just need to do following code.

This e.g is from account_payment:

  _sql_constraints = [
      ('name_uniq', 'UNIQUE(name)', 'The payment line name must be unique!'),
  ]

Hope this will help you.

Regards,

Upvotes: 0

OmaL
OmaL

Reputation: 5044

One way is you can add constraint. _constraint is a pre-define field in OpenERP. It is used for adding a constraint on the object. It takes list of tuple as its argument.The tuple inside the list contains three parameter

  1. Method(to check the constraint)
  2. The Message(Constraint for End User)
  3. List of Fields(fields to apply the constraint)

    _constraint will fire if the condition returns False on creation and updation of the record and display the message.

    The example code for the _constraint is displayed below.

    def _check_length(self, cr, uid, ids, context=None):
        record = self.browse(cr, uid, ids, context=context)
        for data in record:
            if data.length < 0:
               return False
        return True
    
    
    _columns = {'length': fields.integer('Length'),}
    
    _constraints = [(_check_length, 'Error: Length must be Positive', ['length'])]
    

Another way is to modify create and write functions(which are openerp base functions) and check whether all the necessary data are specified or not.

Upvotes: 2

Related Questions