This question has been flagged
1 Reply
2753 Views

OpenERP 7.0

Using _constrains gives a warning if the order line date > sale order date but is there way to disable dates based on the entered sale order date to be more user friendly?

  def _check_date (self, cr, uid, ids, context = None):

        sale_line_records = self.browse (cr, uid, ids, context = context)

        for item in sale_line_records:

            line_date = item.x_linedate

            sale_order_date = item.order_id.date_order

            if datetime.strptime (line_date, DEFAULT_SERVER_DATE_FORMAT) .date ()> datetime.strptime (sale_order_date, DEFAULT_SERVER_DATE_FORMAT) .date ():

                return False

        return True


    _constraints = [

        (_check_date, 'Order Line date cannot be > Sale order date!', ['x_linedate']),

    ]


Avatar
Discard
Best Answer

Hi,

You just have to overwrite the method in your custom module.

Ex:

def _check_date (self, cr, uid, ids, context = None):
    # OR check user group and based on that call super method to validate the dates ELSE return True
    return True

If you want to validate the dates based on configuration, you can overwrite the method and check the user group and based on that you can either by pass the constraint or raise an error if dates are not valid.

Sudhir Arya
ERP Harbor Consulting Services
Skype:sudhir@erpharbor.com
Website: http://www.erpharbor.com
Avatar
Discard
Author

The code that I gave above works fine for the validation on "Save" button click.

But I was looking for disabling future dates when user is entering the data as it will be more user friendly.

I think this needs to be done through javascript but need to know how to hook that javascript to this datepicker.

Yes, right. You will need to extend the Odoo datepicker library for that