當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。