| 1 |
import { X2ManyField, x2ManyField } from "@web/views/fields/x2many/x2many_field"; |
| 2 |
import { useX2ManyCrud, useOpenX2ManyRecord } from "@web/views/fields/relational_utils"; |
| 3 |
import { registry } from "@web/core/registry"; |
| 4 |
import { _t } from "@web/core/l10n/translation"; |
| 5 |
import { user } from "@web/core/user"; |
| 6 |
import { CommonSkillsListRenderer } from "../../views/skills_list_renderer"; |
| 7 |
import { useService } from '@web/core/utils/hooks'; |
| 8 |
import { onWillStart } from "@odoo/owl"; |
| 9 |
|
| 10 |
|
| 11 |
export class SkillsListRenderer extends CommonSkillsListRenderer { |
| 12 |
static template = "hr_skills.SkillsListRenderer"; |
| 13 |
setup() { |
| 14 |
super.setup(); |
| 15 |
this.orm = useService('orm'); |
| 16 |
this.actionService = useService("action"); |
| 17 |
|
| 18 |
onWillStart(async () => { |
| 19 |
const res = await this.orm.searchCount('hr.skill.type', []); |
| 20 |
this.anySkills = res > 0; |
| 21 |
[this.user] = await this.orm.read("res.users", [user.userId], ["employee_ids"]); |
| 22 |
this.IsHrUser = await user.hasGroup("hr.group_hr_user"); |
| 23 |
this.userSubordinates = (await this.orm.searchRead( |
| 24 |
"hr.employee", |
| 25 |
[["id", "child_of", this.user.employee_ids]], |
| 26 |
["id"] |
| 27 |
)).map((record) => record["id"]); |
| 28 |
}); |
| 29 |
} |
| 30 |
|
| 31 |
get groupBy() { |
| 32 |
return 'skill_type_id'; |
| 33 |
} |
| 34 |
|
| 35 |
async skillTypesAction() { |
| 36 |
return this.actionService.doAction("hr_skills.hr_skill_type_action"); |
| 37 |
} |
| 38 |
|
| 39 |
async openSkillsReport() { |
| 40 |
// fetch id through employee or public.employee |
| 41 |
const id = this.env.model.root.data.id || this.env.model.root.data.employee_id.id; |
| 42 |
this.actionService.doAction({ |
| 43 |
type: "ir.actions.act_window", |
| 44 |
name: _t("Skills Report"), |
| 45 |
res_model: "hr.employee.skill.history.report", |
| 46 |
view_mode: "graph,list", |
| 47 |
views: [[false, "graph"]], |
| 48 |
context: { |
| 49 |
'fill_temporal': false, |
| 50 |
}, |
| 51 |
target: "current", |
| 52 |
domain: [['employee_id', '=', id]], |
| 53 |
}); |
| 54 |
} |
| 55 |
|
| 56 |
get showTimeline() { |
| 57 |
return this.SkillsRight && !this.props.list.context.no_timeline; |
| 58 |
} |
| 59 |
|
| 60 |
get SkillsRight() { |
| 61 |
let isSubordinate = false; |
| 62 |
if (this.env.model.root.data.employee_id) { |
| 63 |
isSubordinate = this.userSubordinates.includes(this.env.model.root.data.employee_id.id); |
| 64 |
} |
| 65 |
return this.IsHrUser || isSubordinate; |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
export class SkillsX2ManyField extends X2ManyField { |
| 70 |
static components = { |
| 71 |
...X2ManyField.components, |
| 72 |
ListRenderer: SkillsListRenderer, |
| 73 |
}; |
| 74 |
setup() { |
| 75 |
super.setup(); |
| 76 |
this.orm = useService('orm'); |
| 77 |
this.actionService = useService('action'); |
| 78 |
|
| 79 |
const { saveRecord, updateRecord } = useX2ManyCrud( |
| 80 |
() => this.list, |
| 81 |
this.isMany2Many |
| 82 |
); |
| 83 |
|
| 84 |
const openRecord = useOpenX2ManyRecord({ |
| 85 |
resModel: this.list.resModel, |
| 86 |
activeField: this.activeField, |
| 87 |
activeActions: this.activeActions, |
| 88 |
getList: () => this.list, |
| 89 |
saveRecord: saveRecord, |
| 90 |
updateRecord: updateRecord, |
| 91 |
withParentId: this.props.widget !== "many2many", |
| 92 |
}); |
| 93 |
|
| 94 |
this._openRecord = (params) => { |
| 95 |
params.title = this.getWizardTitleName(); |
| 96 |
openRecord({...params}); |
| 97 |
}; |
| 98 |
} |
| 99 |
|
| 100 |
getWizardTitleName() { |
| 101 |
return _t("Update Skills") |
| 102 |
} |
| 103 |
|
| 104 |
async onAdd({ context, editable } = {}) { |
| 105 |
const employeeId = this.props.record.resModel === "res.users" ? this.props.record.data.employee_id.id : this.props.record.resId; |
| 106 |
return super.onAdd({ |
| 107 |
editable, |
| 108 |
context: { |
| 109 |
...context, |
| 110 |
default_employee_id: employeeId, |
| 111 |
} |
| 112 |
}); |
| 113 |
} |
| 114 |
} |
| 115 |
|
| 116 |
export const skillsX2ManyField = { |
| 117 |
...x2ManyField, |
| 118 |
component: SkillsX2ManyField, |
| 119 |
}; |
| 120 |
|
| 121 |
registry.category("fields").add("skills_one2many", skillsX2ManyField); |