本文整理匯總了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()
示例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
示例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
示例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)]
示例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')