Odoo Help

0

1
1 Answer
0
jerry
10/11/16, 01:57

add this after 'dummy': fields.datetime('Dummy'),
    'duration' = fields.Float('Nuité', compute = '_compute_duration',  help="Number of days which will automatically  count from the check-in and check-out date. ", store = True),

and this after


    _defaults = {
        'reservation_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'hotel.reservation'),
        'state': lambda *a: 'draft',
        'date_order': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
    }


    @api.depends('checkout', 'checkin')

    def _compute_duration(self):
         myduration = 0

        chckin = self.checkin

        chckout = self.checkou

        if (chckin and chckout) :
            server_dt = DEFAULT_SERVER_DATETIME_FORMAT

            chkin_dt = datetime.datetime.strptime(chckin, server_dt)

            chkout_dt = datetime.datetime.strptime(chckout, server_dt)

            chkin = chkin_dt.time()

            chkout = chkout_dt.time()

            ckin = chkin_dt.date()

            ckout = chkout_dt.date()

            if (chkout < datetime.time(12, 10, 00, 000000)) :          # If the client leaves the hotel before 12h 10min
                dur = ckout - ckin

                myduration = (dur.total_seconds()) / 86400

            else :
                dur = ckout - ckin

                myduration = ((dur.total_seconds()) / 86400) + 1

            self.duration = myduration

Ask a Question
Writer
Keep Informed
2 follower(s)
About This Community

This platform 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.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now