Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] Migrate to Odoo 12. Refactor Date compute and formatting #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions Chapter05/ch05_r08_computed/models/library_book.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,20 @@ class LibraryBook(models.Model):

@api.depends('date_release')
def _compute_age(self):
today = fDate.from_string(fDate.context_today(self))
today = fDate.context_today(self)
for book in self.filtered('date_release'):
delta = (today - fDate.from_string(book.date_release))
delta = today - book.date_release
book.age_days = delta.days

def _inverse_age(self):
today = fDate.from_string(fDate.context_today(self))
today = fDate.context_today(self)
for book in self.filtered('date_release'):
d = today - timedelta(days=book.age_days)
book.date_release = fDate.to_string(d)
d = fDate.subtract(today, days=book.age_days)
book.date_release = d

def _search_age(self, operator, value):
today = fDate.from_string(fDate.context_today(self))
value_days = timedelta(days=value)
value_date = fDate.to_string(today - value_days)
today = fDate.context_today(self)
value_date = fDate.subtract(today, days=value)
# convert the operator:
# book with age > value have a date < value_date
operator_map = {
Expand Down