当前位置: 首页>>代码示例>>Python>>正文


Python fields.Date方法代码示例

本文整理汇总了Python中odoo.fields.Date方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Date方法的具体用法?Python fields.Date怎么用?Python fields.Date使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在odoo.fields的用法示例。


在下文中一共展示了fields.Date方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_borrowed

# 需要导入模块: from odoo import fields [as 别名]
# 或者: from odoo.fields import Date [as 别名]
def make_borrowed(self):
        day_to_borrow = self.category_id.max_borrow_days or 10
        self.date_return = fields.Date.today() + timedelta(days=day_to_borrow)
        return super(LibraryBook, self).make_borrowed() 
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Cookbook-Third-Edition,代码行数:6,代码来源:library_return.py

示例2: book_return

# 需要导入模块: from odoo import fields [as 别名]
# 或者: from odoo.fields import Date [as 别名]
def book_return(self):
        self.ensure_one()
        self.book_id.make_available()
        self.write({
            'state': 'returned',
            'return_date': fields.Date.today()
        }) 
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Cookbook-Third-Edition,代码行数:9,代码来源:library_book_rent.py

示例3: _compute_age

# 需要导入模块: from odoo import fields [as 别名]
# 或者: from odoo.fields import Date [as 别名]
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 
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Cookbook-Third-Edition,代码行数:10,代码来源:library_book.py

示例4: _inverse_age

# 需要导入模块: from odoo import fields [as 别名]
# 或者: from odoo.fields import Date [as 别名]
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 
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Cookbook-Third-Edition,代码行数:10,代码来源:library_book.py

示例5: _search_age

# 需要导入模块: from odoo import fields [as 别名]
# 或者: from odoo.fields import Date [as 别名]
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)] 
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Cookbook-Third-Edition,代码行数:14,代码来源:library_book.py

示例6: _check_release_date

# 需要导入模块: from odoo import fields [as 别名]
# 或者: from odoo.fields import Date [as 别名]
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') 
开发者ID:PacktPublishing,项目名称:Odoo-12-Development-Cookbook-Third-Edition,代码行数:6,代码来源:library_book.py


注:本文中的odoo.fields.Date方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。