| 1 |
import { Component, onWillStart, onWillUpdateProps } from "@odoo/owl"; |
| 2 |
import { standardWidgetProps } from "@web/views/widgets/standard_widget_props"; |
| 3 |
import { registry } from "@web/core/registry"; |
| 4 |
import { useService } from "@web/core/utils/hooks"; |
| 5 |
import { formatDate } from "@web/core/l10n/dates"; |
| 6 |
|
| 7 |
export class InternalResumeLineComponent extends Component { |
| 8 |
static template = "hr_skills.InternalResumeLineComponent"; |
| 9 |
static props = { ...standardWidgetProps }; |
| 10 |
|
| 11 |
setup(){ |
| 12 |
super.setup(); |
| 13 |
this.orm = useService("orm"); |
| 14 |
onWillStart(async () => { |
| 15 |
this.internalResumeLines = await this.getInternalResumeLines( |
| 16 |
this.props.record.resId, |
| 17 |
this.props.record.resModel |
| 18 |
) |
| 19 |
}) |
| 20 |
onWillUpdateProps(async (nextProps) => { |
| 21 |
this.internalResumeLines = await this.getInternalResumeLines( |
| 22 |
nextProps.record.resId, |
| 23 |
nextProps.record.resModel |
| 24 |
) |
| 25 |
}) |
| 26 |
} |
| 27 |
|
| 28 |
async getInternalResumeLines(resId, resModel){ |
| 29 |
const internalResumeLines = await this.orm.call( |
| 30 |
"hr.employee", |
| 31 |
"get_internal_resume_lines", |
| 32 |
[resId, resModel] |
| 33 |
); |
| 34 |
return internalResumeLines; |
| 35 |
} |
| 36 |
|
| 37 |
get companyId(){ |
| 38 |
return this.props.record.data.company_id.display_name; |
| 39 |
} |
| 40 |
|
| 41 |
get haveResumeLines(){ |
| 42 |
return this.props.record.data.resume_line_ids.records.length || this.internalResumeLines.length; |
| 43 |
} |
| 44 |
|
| 45 |
formatDate(date) { |
| 46 |
const formattedDate = luxon.DateTime.fromISO(date); |
| 47 |
return formatDate(formattedDate); |
| 48 |
} |
| 49 |
} |
| 50 |
|
| 51 |
export const internalResumeLinesComponent = { |
| 52 |
component: InternalResumeLineComponent, |
| 53 |
fieldDependencies: [ |
| 54 |
{ name: "company_id", type: "many2one" }, |
| 55 |
{ name: "resume_line_ids", type: "one2many"} |
| 56 |
], |
| 57 |
}; |
| 58 |
|
| 59 |
registry.category("view_widgets").add("internal_resume_lines", internalResumeLinesComponent); |