Python odoo.fields.Date() Examples

The following are 30 code examples of odoo.fields.Date(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module odoo.fields , or try the search function .
Example #1
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def onchange_member_id(self):
        today = fields.Date.today()
        if self.request_date != today:
            self.request_date = fields.Date.today()
            return {
                'warning': {
                    'title': 'Changed Request Date',
                    'message': 'Request date changed to today.'
                }
            } 
Example #2
Source File: library_book.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def _compute_age(self):
        today = fields.Date.today()
        for book in self.filtered('date_release'):
            delta = today - book.date_release
            book.age_days = delta.days

    # This reverse method of _compute_age. Used to make age_days field editable
    # It is optional if you don't want to make compute field editable then you can remove this 
Example #3
Source File: library_book.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def _inverse_age(self):
        today = fields.Date.today()
        for book in self.filtered('date_release'):
            d = today - timedelta(days=book.age_days)
            book.date_release = d

    # This used to enable search on copute fields
    # It is optional if you don't want to make enable search then you can remove this 
Example #4
Source File: library_book.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def _search_age(self, operator, value):
        today = fields.Date.today()
        value_days = timedelta(days=value)
        value_date = today - value_days
        # convert the operator:
        # book with age > value have a date < value_date
        operator_map = {
            '>': '<', '>=': '<=',
            '<': '>', '<=': '>=',
        }
        new_op = operator_map.get(operator, operator)
        return [('date_release', new_op, value_date)] 
Example #5
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #6
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #7
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #8
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #9
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #10
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #11
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #12
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def onchange_member_id(self):
        today = fields.Date.today()
        if self.request_date != today:
            self.request_date = fields.Date.today()
            return {
                'warning': {
                    'title': 'Changed Request Date',
                    'message': 'Request date changed to today.'
                }
            } 
Example #13
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def create(self, vals):
        # Code before create: should use the `vals` dict
        if 'stage_id' in vals:
            Stage = self.env['library.checkout.stage']
            new_state = Stage.browse(vals['stage_id']).state
            if new_state == 'open':
                vals['checkout_date'] = fields.Date.today()
        new_record = super().create(vals)
        # Code after create: can use the `new_record` created
        if new_record.state == 'done':
            raise exceptions.UserError(
                'Not allowed to create a checkout in the done state.')
        return new_record 
Example #14
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def write(self, vals):
        # Code before write: can use `self`, with the old values
        if 'stage_id' in vals:
            Stage = self.env['library.checkout.stage']
            new_state = Stage.browse(vals['stage_id']).state
            if new_state == 'open' and self.state != 'open':
                vals['checkout_date'] = fields.Date.today()
            if new_state == 'done' and self.state != 'done':
                vals['close_date'] = fields.Date.today()
        super().write(vals)
        # Code after write: can use `self`, with the updated values
        return True 
Example #15
Source File: library_book.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def _check_release_date(self):
        for record in self:
            if record.date_release and record.date_release > fields.Date.today():
                raise models.ValidationError('Release date must be in the past') 
Example #16
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def create(self, vals):
        # Code before create: should use the `vals` dict
        if 'stage_id' in vals:
            Stage = self.env['library.checkout.stage']
            new_state = Stage.browse(vals['stage_id']).state
            if new_state == 'open':
                vals['checkout_date'] = fields.Date.today()
        new_record = super().create(vals)
        # Code after create: can use the `new_record` created
        if new_record.state == 'done':
            raise exceptions.UserError(
                'Not allowed to create a checkout in the done state.')
        return new_record 
Example #17
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def onchange_member_id(self):
        today = fields.Date.today()
        if self.request_date != today:
            self.request_date = fields.Date.today()
            return {
                'warning': {
                    'title': 'Changed Request Date',
                    'message': 'Request date changed to today.'
                }
            } 
Example #18
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def create(self, vals):
        # Code before create: should use the `vals` dict
        if 'stage_id' in vals:
            Stage = self.env['library.checkout.stage']
            new_state = Stage.browse(vals['stage_id']).state
            if new_state == 'open':
                vals['checkout_date'] = fields.Date.today()
        new_record = super().create(vals)
        # Code after create: can use the `new_record` created
        if new_record.state == 'done':
            raise exceptions.UserError(
                'Not allowed to create a checkout in the done state.')
        return new_record 
Example #19
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def write(self, vals):
        # Code before write: can use `self`, with the old values
        if 'stage_id' in vals:
            Stage = self.env['library.checkout.stage']
            new_state = Stage.browse(vals['stage_id']).state
            if new_state == 'open' and self.state != 'open':
                vals['checkout_date'] = fields.Date.today()
            if new_state == 'done' and self.state != 'done':
                vals['close_date'] = fields.Date.today()
        super().write(vals)
        # Code after write: can use `self`, with the updated values
        return True 
Example #20
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def onchange_member_id(self):
        today = fields.Date.today()
        if self.request_date != today:
            self.request_date = fields.Date.today()
            return {
                'warning': {
                    'title': 'Changed Request Date',
                    'message': 'Request date changed to today.'
                }
            } 
Example #21
Source File: library_checkout.py    From Odoo-12-Development-Essentials-Fourth-Edition with MIT License 5 votes vote down vote up
def create(self, vals):
        # Code before create: should use the `vals` dict
        if 'stage_id' in vals:
            Stage = self.env['library.checkout.stage']
            new_state = Stage.browse(vals['stage_id']).state
            if new_state == 'open':
                vals['checkout_date'] = fields.Date.today()
        new_record = super().create(vals)
        # Code after create: can use the `new_record` created
        if new_record.state == 'done':
            raise exceptions.UserError(
                'Not allowed to create a checkout in the done state.')
        return new_record 
Example #22
Source File: schedule.py    From -Odoo--- with GNU General Public License v3.0 5 votes vote down vote up
def check_dates(self):
        for record in self:
            start_date = fields.Date.from_string(record.start_date)
            end_date = fields.Date.from_string(record.end_date)
            if start_date > end_date:
                raise ValidationError(_("End Date cannot be set before \
                Start Date.")) 
Example #23
Source File: student.py    From -Odoo--- with GNU General Public License v3.0 5 votes vote down vote up
def _check_birthdate(self):
        for record in self:
            if record.birth_date > fields.Date.today():
                raise ValidationError(_(
                    "出生日期不可以晚于今天!")) 
Example #24
Source File: teacher.py    From -Odoo--- with GNU General Public License v3.0 5 votes vote down vote up
def _check_birthdate(self):
        for record in self:
            if record.birth_date > fields.Date.today():
                raise ValidationError(_(
                    "出生日期不可以晚于今天!")) 
Example #25
Source File: generate_timetable.py    From -Odoo--- with GNU General Public License v3.0 5 votes vote down vote up
def check_dates(self):
        start_date = fields.Date.from_string(self.start_date)
        end_date = fields.Date.from_string(self.end_date)
        if start_date > end_date:
            raise ValidationError(_("End Date cannot be set before \
            Start Date.")) 
Example #26
Source File: models.py    From Odoo-11-Development-Coobook-Second-Edition with MIT License 5 votes vote down vote up
def _prepare_loan(self, book):
        values = super(LibraryLoanWizard, self)._prepare_loan(book)
        loan_duration = self.member_id.loan_duration
        today_str = fields.Date.context_today(self)
        today = fields.Date.from_string(today_str)
        expected = (today +
                    timedelta(days=loan_duration))
        values.update(
            {'expected_return_date': fields.Date.to_string(expected)}
        )
        return values 
Example #27
Source File: library_book.py    From Odoo-11-Development-Coobook-Second-Edition with MIT License 5 votes vote down vote up
def _check_release_date(self):
        for r in self:
            if r.date_release > fields.Date.today():
                raise models.ValidationError(
                    'Release date must be in the past') 
Example #28
Source File: library_book.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def _check_release_date(self):
        for record in self:
            if record.date_release and record.date_release > fields.Date.today():
                raise models.ValidationError('Release date must be in the past') 
Example #29
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
Example #30
Source File: library_book_rent.py    From Odoo-12-Development-Cookbook-Third-Edition with MIT License 5 votes vote down vote up
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        })