fix: correct department and branch name display logic

- Add is_branch check to prevent name duplication
- Branches (is_branch=true) show name only
- Departments (is_branch=false) show 'name - branch' when branch exists
- Fix display_name property with same logic
- Prevent cases like 'فرع الافلاج - فرع الافلاج'

Examples:
- Branch: 'فرع الجنوب' (name only)
- Department: 'أجهزة كهربائية - فرع الجنوب' (with branch)
- Department: 'إدارة التسويق' (no branch)

Synced with latest dev_odex25_hr on Thu Nov 13 23:35:00 +03 2025
This commit is contained in:
maltayyar2 2025-11-13 23:35:01 +03:00
parent 7e99f90276
commit 6510ca14e4
1 changed files with 14 additions and 13 deletions

View File

@ -26,24 +26,25 @@ class HrDepartment(models.Model):
def name_get(self):
result = []
for department in self:
# إذا كان السياق يطلب المسار الكامل
if self.env.context.get('show_full_path'):
name = super(HrDepartment, department).name_get()[0][1]
else:
# الاسم المختصر (الافتراضي)
name = department.name
# إضافة اسم الفرع فقط للأقسام (ليس للفروع)
if not department.is_branch and department.branch_name:
name = f"{department.name} - {department.branch_name.name}"
result.append((department.id, name))
return result
@property
def display_name(self):
"""Override display_name to show short name for all departments"""
# إذا كان السياق يطلب المسار الكامل
if self.env.context.get('show_full_path'):
return super().display_name
else:
# الاسم المختصر (الافتراضي)
return self.name
"""Override display_name to show department name with branch"""
name = self.name
# إضافة اسم الفرع فقط للأقسام (ليس للفروع)
if not self.is_branch and self.branch_name:
name = f"{self.name} - {self.branch_name.name}"
return name
@api.depends('is_branch','parent_id')
def get_is_branch(self):