Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

what will i do if my constraints doesn't work?(SOLVE)

By
Alcaline
on 8/16/14, 2:08 AM 686 views

      I've created my own module for purchase rental and i want to put a constraints in Start Date and End Date. for exmaple, the user input an invalid Dates my created constraints pop up to warn the user that he/she inputs an invalid Date. How will I going to do that? and how will i call my def function in the save button?? here my codes in creating my def:

 

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

       for line in self.browse(cr,uid,ids,context=context):

           netsvc.Logger().notifyChannel("NETSV NETSV NETSV NETSV NETSV NETSV NETSV NETSV START DATE", netsvc.LOG_INFO, ' '+str(line.start_date))

           netsvc.Logger().notifyChannel("NETSV NETSV NETSV NETSV NETSV NETSV NETSV NETSV ENDSS DATE", netsvc.LOG_INFO, ' '+str(line.end_date))

           if line.start_date and not line.end_date:

               raise orm.except_orm(

                   _('Error:'),

                   _("Missing End Date for purchase order line with"

                       "Description '%s'.")

                   % (line.name))

           if line.end_date and not line.start_date:

               raise orm.except_orm(

                   _('Error:'),

                   _("Missing Start Date for purchase order line with"

                        "Description '%s'.")

                   % (line.name))

           if line.end_date and line.start_date and \

                   line.start_date > line.end_date:

               raise orm.except_orm(

                   _('Error:'),

                   _("Start Date should be before or be the same as "

                       "End Date for purchase order line with Description '%s'.")

                   % (line.name))

       return True

   

   _constraints = [

       (_validate_date, "Error msg in raise",

            ['start_date','end_date','product_id']),

       ]

1

Prakash

--Prakash--
3173
| 5 4 7
Bikaner, India
--Prakash--

OpenERP Devloper at SunARC Technology

Prakash
On 8/16/14, 2:26 AM

If not Start Date or End Date then use return False.

 def _validate_date(self,cr,uid,ids,context=None):
        for line in self.browse(cr,uid,ids,context=context):
           #netsvc.Logger().notifyChannel("NETSV NETSV NETSV NETSV NETSV NETSV NETSV NETSV START DATE", netsvc.LOG_INFO, ' '+str(line.start_date))
           #netsvc.Logger().notifyChannel("NETSV NETSV NETSV NETSV NETSV NETSV NETSV NETSV ENDSS DATE", netsvc.LOG_INFO, ' '+str(line.end_date))
           if line.start_date and not line.end_date:
              return False
           if line.end_date and not line.start_date:
              return False
           if line.end_date and line.start_date and line.start_date > line.end_date:
              return False
        return True

   

   _constraints = [(_validate_date, "Please check Start and End date!...", ['start_date','end_date','product_id'])]

I've already tried that one but it doesn't work. Do i need to declare something like import for this?

Alcaline
on 8/16/14, 3:32 AM

No need to import. check your table if any records with start_date or end_date null or start_date>end_date remove the records and update the module.

Prakash
on 8/16/14, 5:07 AM

thanks prakash

Alcaline
on 8/17/14, 11:11 PM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 8/16/14, 2:08 AM
Seen: 686 times
Last updated: 3/16/15, 8:10 AM