Skip to content

Commit

Permalink
[MIG] 10.0 Porting hr_employee_age (OCA#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yopli2k authored and Chandresh-SerpentCS committed Nov 24, 2018
1 parent cabac8f commit 28fcea2
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
4 changes: 2 additions & 2 deletions hr_employee_age/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

{
"name": "Employee Age",
'version': '8.0.1.0.0',
'version': '10.0.1.0.0',
'license': 'AGPL-3',
'author': "Salton Massally <smassally@idtlabs.sl>, "
"Odoo Community Association (OCA)",
Expand All @@ -33,5 +33,5 @@
"data": [
'views/hr_employee.xml',
],
'installable': False,
'installable': True,
}
22 changes: 12 additions & 10 deletions hr_employee_age/models/hr_employee.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,27 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###############################################################################
from datetime import datetime

from openerp import fields, models, api
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT as OE_DFORMAT
from odoo import api, fields, models
from dateutil.relativedelta import relativedelta


class HrEmployee(models.Model):
_inherit = 'hr.employee'

age = fields.Integer(
'Age',
string='Age',
readonly=True,
compute='_compute_age'
)

@api.one
@api.multi
@api.depends('birthday')
def _compute_age(self):
if self.birthday:
dBday = datetime.strptime(self.birthday, OE_DFORMAT).date()
dToday = datetime.now().date()
self.age = dToday.year - dBday.year - ((
dToday.month, dToday.day) < (dBday.month, dBday.day))
for record in self:
if record.birthday:
record.age = relativedelta(
fields.Date.from_string(fields.Date.today()),
fields.Date.from_string(record.birthday)).years
else:
record.age = 0
31 changes: 12 additions & 19 deletions hr_employee_age/views/hr_employee.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>

<record id="hr_employee_view_form" model="ir.ui.view">
<field name="name">hr.employee.view.form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='birthday']" position="after">
<field name="age"/>
</xpath>
</data>
</field>
</record>

</data>
</openerp>
<odoo>
<record id="hr_employee_view_form" model="ir.ui.view">
<field name="name">hr.employee.view.form</field>
<field name="model">hr.employee</field>
<field name="inherit_id" ref="hr.view_employee_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='birthday']" position="after">
<field name="age"/>
</xpath>
</field>
</record>
</odoo>

0 comments on commit 28fcea2

Please sign in to comment.