Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd17d3f8c8 | |||
| 7b44a9cac5 |
@@ -1,3 +1,4 @@
|
|||||||
# Odoo-Tutorial
|
# Odoo-Tutorial
|
||||||
|
|
||||||
Repo for exercise with odoo module
|
|
||||||
|
Repo for exercise with odoo modules
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import controllers
|
|
||||||
from . import models
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
{
|
|
||||||
'name': "hr_managment",
|
|
||||||
|
|
||||||
'summary': "Short (1 phrase/line) summary of the module's purpose",
|
|
||||||
|
|
||||||
'description': """
|
|
||||||
Long description of module's purpose
|
|
||||||
""",
|
|
||||||
|
|
||||||
'author': "Duy Dat",
|
|
||||||
'website': "https://www.yourcompany.com",
|
|
||||||
|
|
||||||
# Categories can be used to filter modules in modules listing
|
|
||||||
# Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml
|
|
||||||
# for the full list
|
|
||||||
'category': 'Human Resources',
|
|
||||||
'version': '0.1',
|
|
||||||
|
|
||||||
# any module necessary for this one to work correctly
|
|
||||||
'depends': ['base'],
|
|
||||||
|
|
||||||
# always loaded
|
|
||||||
'data': [
|
|
||||||
'security/ir.model.access.csv',
|
|
||||||
'views/employee_views.xml',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
from . import controllers
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
# from odoo import http
|
|
||||||
|
|
||||||
|
|
||||||
# class HrManagment(http.Controller):
|
|
||||||
# @http.route('/hr_managment/hr_managment', auth='public')
|
|
||||||
# def index(self, **kw):
|
|
||||||
# return "Hello, world"
|
|
||||||
|
|
||||||
# @http.route('/hr_managment/hr_managment/objects', auth='public')
|
|
||||||
# def list(self, **kw):
|
|
||||||
# return http.request.render('hr_managment.listing', {
|
|
||||||
# 'root': '/hr_managment/hr_managment',
|
|
||||||
# 'objects': http.request.env['hr_managment.hr_managment'].search([]),
|
|
||||||
# })
|
|
||||||
|
|
||||||
# @http.route('/hr_managment/hr_managment/objects/<model("hr_managment.hr_managment"):obj>', auth='public')
|
|
||||||
# def object(self, obj, **kw):
|
|
||||||
# return http.request.render('hr_managment.object', {
|
|
||||||
# 'object': obj
|
|
||||||
# })
|
|
||||||
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
from . import employee
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
from odoo import models, fields, api
|
|
||||||
from datetime import date
|
|
||||||
|
|
||||||
class Employee(models.Model):
|
|
||||||
_name = 'hr.employee'
|
|
||||||
_description = 'Nhân viên'
|
|
||||||
name = fields.Char(string='Tên nhân viên', required=True)
|
|
||||||
employee_code = fields.Char(string='Mã nhân viên', required=True, copy=False, readonly=True, default='New')
|
|
||||||
job_title = fields.Char(string='Chức vụ')
|
|
||||||
date_of_birth = fields.Date(string='Ngày sinh')
|
|
||||||
hire_date = fields.Date(string='Ngày vào làm')
|
|
||||||
active = fields.Boolean(string='Còn làm việc', default=True)
|
|
||||||
age = fields.Integer(string='Tuổi', compute='_compute_age')
|
|
||||||
@api.depends('date_of_birth')
|
|
||||||
def _compute_age(self):
|
|
||||||
for rec in self:
|
|
||||||
if rec.date_of_birth:
|
|
||||||
today = date.today()
|
|
||||||
rec.age = today.year - rec.date_of_birth.year
|
|
||||||
else:
|
|
||||||
rec.age = 0
|
|
||||||
@api.model
|
|
||||||
def create(self, vals):
|
|
||||||
if vals.get('employee_code', 'New') == 'New':
|
|
||||||
# Tạo mã tự động, ví dụ: EMP0001
|
|
||||||
last_employee = self.env['hr.employee'].search([], order='id desc', limit=1)
|
|
||||||
if last_employee:
|
|
||||||
last_code = last_employee.employee_code or 'EMP0000'
|
|
||||||
# Lấy phần số sau "EMP" và tăng lên 1
|
|
||||||
number = int(last_code.replace('EMP', '')) + 1
|
|
||||||
vals['employee_code'] = 'EMP%04d' % number
|
|
||||||
else:
|
|
||||||
vals['employee_code'] = 'EMP0001'
|
|
||||||
return super(Employee, self).create(vals)
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
|
||||||
access_hr_employee,hr.employee,model_hr_employee,base.group_user,1,1,1,1
|
|
||||||
|
|
||||||
|
@@ -1,47 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8" ?>
|
|
||||||
<odoo>
|
|
||||||
<record id="view_hr_employee_list" model="ir.ui.view">
|
|
||||||
<field name="name">hr.employee.list</field>
|
|
||||||
<field name="model">hr.employee</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<list string="Danh sách nhân viên">
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="employee_code"/>
|
|
||||||
<field name="job_title"/>
|
|
||||||
<field name="date_of_birth"/>
|
|
||||||
<field name="age"/>
|
|
||||||
<field name="hire_date"/>
|
|
||||||
<field name="active"/>
|
|
||||||
</list>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="view_hr_employee_form" model="ir.ui.view">
|
|
||||||
<field name="name">hr.employee.form</field>
|
|
||||||
<field name="model">hr.employee</field>
|
|
||||||
<field name="arch" type="xml">
|
|
||||||
<form string="Thông tin nhân viên">
|
|
||||||
<sheet>
|
|
||||||
<group>
|
|
||||||
<field name="name"/>
|
|
||||||
<field name="employee_code" readonly="1"/>
|
|
||||||
<field name="job_title"/>
|
|
||||||
<field name="date_of_birth"/>
|
|
||||||
<field name="age" readonly="1"/>
|
|
||||||
<field name="hire_date"/>
|
|
||||||
<field name="active"/>
|
|
||||||
</group>
|
|
||||||
</sheet>
|
|
||||||
</form>
|
|
||||||
</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<record id="action_hr_employee" model="ir.actions.act_window">
|
|
||||||
<field name="name">Nhân viên</field>
|
|
||||||
<field name="res_model">hr.employee</field>
|
|
||||||
<field name="view_mode">list,form</field>
|
|
||||||
</record>
|
|
||||||
|
|
||||||
<menuitem id="menu_hr_employee_root" name="Quản lý nhân viên" sequence="10"/>
|
|
||||||
<menuitem id="menu_hr_employee" name="Nhân viên" parent="menu_hr_employee_root" action="action_hr_employee" sequence="20"/>
|
|
||||||
</odoo>
|
|
||||||
Reference in New Issue
Block a user