| 1 |
import { Component } from "@odoo/owl"; |
| 2 |
import { _t } from "@web/core/l10n/translation"; |
| 3 |
import { registry } from "@web/core/registry"; |
| 4 |
import { buildM2OFieldDescription, Many2OneField } from "@web/views/fields/many2one/many2one_field"; |
| 5 |
import { standardFieldProps } from "@web/views/fields/standard_field_props"; |
| 6 |
|
| 7 |
export function getRottingDaysTitle(modelName, rotDays) { |
| 8 |
switch (modelName) { |
| 9 |
case "crm.lead": |
| 10 |
return _t("This lead has been stuck in this stage for %(numberOfDays)s days.", { |
| 11 |
numberOfDays: rotDays, |
| 12 |
}); |
| 13 |
case "hr.applicant": |
| 14 |
return _t("This applicant has been stuck in this stage for %(numberOfDays)s days.", { |
| 15 |
numberOfDays: rotDays, |
| 16 |
}); |
| 17 |
case "project.task": |
| 18 |
return _t("This task has been stuck in this stage for %(numberOfDays)s days.", { |
| 19 |
numberOfDays: rotDays, |
| 20 |
}); |
| 21 |
} |
| 22 |
return _t("This record has been stuck in this stage for %(numberOfDays)s days.", { |
| 23 |
numberOfDays: rotDays, |
| 24 |
}); |
| 25 |
} |
| 26 |
|
| 27 |
export class KanbanRottingField extends Component { |
| 28 |
static props = { |
| 29 |
...standardFieldProps, |
| 30 |
}; |
| 31 |
static template = "mail.KanbanRottingField"; |
| 32 |
|
| 33 |
setup() { |
| 34 |
// Preprocess all sentences as childless strings so they're easier to format in the DOM |
| 35 |
this.dayCount = _t("%(numberOfDays)sd", { |
| 36 |
numberOfDays: this.props.record.data.rotting_days, |
| 37 |
}); |
| 38 |
|
| 39 |
this.title = getRottingDaysTitle( |
| 40 |
this.props.record.model.config.resModel, |
| 41 |
this.props.record.data.rotting_days |
| 42 |
); |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
export class Many2OneFieldRotting extends Many2OneField { |
| 47 |
static template = "mail.Many2OneFieldRotting"; |
| 48 |
|
| 49 |
setup() { |
| 50 |
super.setup(); |
| 51 |
// As this widget is appended to another field's value, we display no additional title to prevent title overlap |
| 52 |
this.dayCount = _t("%(numberOfDays)sd", { |
| 53 |
numberOfDays: this.props.record.data.rotting_days, |
| 54 |
}); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
registry.category("fields").add("kanban.rotting", { |
| 59 |
component: KanbanRottingField, |
| 60 |
}); |
| 61 |
|
| 62 |
registry.category("fields").add("list.badge_rotting", { |
| 63 |
...buildM2OFieldDescription(Many2OneFieldRotting), |
| 64 |
}); |