-
-
Notifications
You must be signed in to change notification settings - Fork 664
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] 10.0 Porting hr_employee_age #293
Conversation
Hey @Yopli2k, thank you for your Pull Request. It looks like some users haven't signed our Contributor License Agreement, yet.
Appreciation of efforts, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Little changes.
|
||
from openerp import fields, models, api | ||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as OE_DFORMAT | ||
from openerp import api, fields, models |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use from odoo
instead of from openerp
, as now in version 10 is the default namespace.
@@ -33,9 +32,11 @@ class HrEmployee(models.Model): | |||
) | |||
|
|||
@api.one |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@api.one
is deprecated now (they have decided in this way although here is useful), so better to remove in favor of @api.multi
and a loop with for record in self:
and the rest of the stuff replacing self
by record
.
dToday = datetime.now().date() | ||
self.age = dToday.year - dBday.year - (( | ||
dToday.month, dToday.day) < (dBday.month, dBday.day)) | ||
dBday = fields.Date.from_string(self.birthday) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use upper letters in local variable names (that's something wrong also in the previous version). See PEP8 https://www.python.org/dev/peps/pep-0008/#function-names
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i use the same variables as they were. I'm aiming for future changes. Thank you
dToday.month, dToday.day) < (dBday.month, dBday.day)) | ||
dBday = fields.Date.from_string(self.birthday) | ||
dToday = fields.Date.from_string(fields.Date.today()) | ||
self.age = relativedelta(dToday, dBday).years |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can do directly the substraction of one date minus the other and you will get a relativedelta object.
Ok, all changes are now made to the new commit. |
dToday.month, dToday.day) < (dBday.month, dBday.day)) | ||
for record in self: | ||
if record.birthday: | ||
record.age = relativedelta( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea here is to do:
record.age = (fields.Date.from_string(fields.Date.today()) - fields.Date.from_string(record.birthday)).years
and you save also an import.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code you propose gives me the following error:
File "~/Odoo10/hr/hr_employee_age/models/hr_employee.py", line 39, in _compute_age record.age = (fields.Date.from_string(fields.Date.today()) - fields.Date.from_string(record.birthday)).years **AttributeError: 'datetime.timedelta' object has no attribute 'years'**
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, the returned object is not the same. Well, you can get it with a division, but let's keep this way then
Rebuilding for testing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested in runbot
# The first commit's message is: OCA Transbot updated translations from Transifex # This is the 2nd commit message: OCA Transbot updated translations from Transifex # This is the 3rd commit message: OCA Transbot updated translations from Transifex # This is the 4th commit message: OCA Transbot updated translations from Transifex # This is the 5th commit message: OCA Transbot updated translations from Transifex # This is the 6th commit message: OCA Transbot updated translations from Transifex # This is the 7th commit message: [MIG] Make modules uninstallable # This is the 8th commit message: [FIX] remove en.po that was erroneously created by transbot # This is the 9th commit message: [MIG] Rename manifest files # This is the 10th commit message: [MIG] 10.0 Porting hr_employee_age (OCA#293) # This is the 11th commit message: OCA Transbot updated translations from Transifex # This is the 12th commit message: OCA Transbot updated translations from Transifex # This is the 13th commit message: OCA Transbot updated translations from Transifex # This is the 14th commit message: OCA Transbot updated translations from Transifex # This is the 15th commit message: OCA Transbot updated translations from Transifex # This is the 16th commit message: OCA Transbot updated translations from Transifex # This is the 17th commit message: OCA Transbot updated translations from Transifex # This is the 18th commit message: OCA Transbot updated translations from Transifex # This is the 19th commit message: OCA Transbot updated translations from Transifex # This is the 20th commit message: OCA Transbot updated translations from Transifex # This is the 21st commit message: OCA Transbot updated translations from Transifex
No description provided.