From 823d99054955ff8ec884133d8b1edc066319c1bd Mon Sep 17 00:00:00 2001
From: hiendc <hiendc@snine.vn>
Date: Fri, 12 Jul 2024 16:03:45 +0700
Subject: [PATCH] Create module s_hr

---
 s_hr/__init__.py           |  3 +++
 s_hr/__manifest__.py       | 15 +++++++++++++++
 s_hr/models/__init__.py    |  3 +++
 s_hr/models/hr_employee.py | 28 ++++++++++++++++++++++++++++
 s_hr/views/hr_employee.xml | 26 ++++++++++++++++++++++++++
 5 files changed, 75 insertions(+)
 create mode 100644 s_hr/__init__.py
 create mode 100644 s_hr/__manifest__.py
 create mode 100644 s_hr/models/__init__.py
 create mode 100644 s_hr/models/hr_employee.py
 create mode 100644 s_hr/views/hr_employee.xml

diff --git a/s_hr/__init__.py b/s_hr/__init__.py
new file mode 100644
index 0000000..cde864b
--- /dev/null
+++ b/s_hr/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from . import models
diff --git a/s_hr/__manifest__.py b/s_hr/__manifest__.py
new file mode 100644
index 0000000..f5c8ce6
--- /dev/null
+++ b/s_hr/__manifest__.py
@@ -0,0 +1,15 @@
+# -*- coding: utf-8 -*-
+{
+    'name': "Snine HR",
+    'summary': "Custom Module HR",
+    'description': """Custom Module HR""",
+    'author': "Snine",
+    'website': "https://www.snine.vn",
+    'category': 'Uncategorized',
+    'version': '0.1',
+    'depends': ['base', 'hr'],
+    'data': [
+        'views/hr_employee.xml',
+    ],
+    'license': 'LGPL-3',
+}
diff --git a/s_hr/models/__init__.py b/s_hr/models/__init__.py
new file mode 100644
index 0000000..58f27f4
--- /dev/null
+++ b/s_hr/models/__init__.py
@@ -0,0 +1,3 @@
+# -*- coding: utf-8 -*-
+
+from . import hr_employee
diff --git a/s_hr/models/hr_employee.py b/s_hr/models/hr_employee.py
new file mode 100644
index 0000000..a26d43f
--- /dev/null
+++ b/s_hr/models/hr_employee.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+from odoo import api, fields, models
+
+
+class HrEmployee(models.Model):
+    _inherit = 'hr.employee'
+
+    def default_country(self):
+        return self.env.ref('base.vn')
+
+    private_district_id = fields.Many2one(comodel_name='res.country.district', string='District',
+                                          domain="[('state_id','=', private_state_id)]")
+    private_ward_id = fields.Many2one(comodel_name='res.country.ward', string='Ward',
+                                      domain="[('district_id', '=', private_district_id)]")
+    private_country_id = fields.Many2one("res.country", string="Private Country", groups="hr.group_hr_user",
+                                         default=default_country)
+
+    @api.onchange('private_district_id')
+    def _district_onchange(self):
+        self.private_street2 = self.private_district_id.name
+        self.private_ward_id = False
+        self.private_city = self.private_state_id.name
+
+    @api.onchange('private_ward_id')
+    def _ward_onchange(self):
+        self.private_street2 = self.private_ward_id.slug2
+        self.private_city = self.private_state_id.name
diff --git a/s_hr/views/hr_employee.xml b/s_hr/views/hr_employee.xml
new file mode 100644
index 0000000..6d9a5a0
--- /dev/null
+++ b/s_hr/views/hr_employee.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<odoo>
+    <record id="s_hr.view_employee_form" model="ir.ui.view">
+        <field name="name">hr.employee.form</field>
+        <field name="model">hr.employee</field>
+        <field name="inherit_id" ref="hr.view_employee_form"/>
+        <field name="arch" type="xml">
+            <xpath expr="//div[hasclass('o_address_format')]/field[@name='private_state_id']" position="replace">
+                <field name="private_state_id" placeholder="Please choose a State"
+                       options="{'no_open': True, 'no_quick_create': True}"
+                       context="{'private_country_id': private_country_id, 'default_private_country_id': private_country_id, 'private_zip': private_zip}"/>
+                <field name="private_district_id" placeholder="Please choose a District" string="District"
+                       options="{&quot;no_open&quot;: True}" class="oe_edit_only"/>
+                <field name="private_ward_id" placeholder="Please choose a Ward" string="Ward"
+                       options="{&quot;no_open&quot;: True}" class="oe_edit_only"/>
+            </xpath>
+
+            <field name="private_city" position="attributes">
+                <attribute name="invisible">1</attribute>
+            </field>
+            <field name="private_zip" position="attributes">
+                <attribute name="invisible">1</attribute>
+            </field>
+        </field>
+    </record>
+</odoo>
-- 
GitLab