| 1 |
import { Component, useState } from "@odoo/owl"; |
| 2 |
|
| 3 |
|
| 4 |
export class StockValuationReportLine extends Component { |
| 5 |
static template = "stock_account.StockValuationReport.InventoryValuationLine"; |
| 6 |
static props = { |
| 7 |
class: { type: String, optional: true }, |
| 8 |
displayDebitCredit: { type: Boolean, optional: true }, |
| 9 |
label: { type: String, optional: true }, |
| 10 |
level: { type: Number, optional: true }, |
| 11 |
line: { type: Object, optional: true }, |
| 12 |
sublines: { type: Array, optional: true }, |
| 13 |
onClickMethod: { type: Function, optional: true }, |
| 14 |
value: { type: Number, optional: true }, |
| 15 |
}; |
| 16 |
static defaultProps = { |
| 17 |
level: 0, |
| 18 |
}; |
| 19 |
|
| 20 |
setup() { |
| 21 |
this.hasSublines = Boolean(this.props.sublines?.length); |
| 22 |
this.state = useState({ displaySublines: this.hasSublines }); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
get credit() { |
| 27 |
if (this.props.line?.credit) { |
| 28 |
return this.env.formatMonetary(this.props.line.credit); |
| 29 |
} |
| 30 |
return false; |
| 31 |
} |
| 32 |
|
| 33 |
get cssClass() { |
| 34 |
let cssClass = this.props.class || ""; |
| 35 |
cssClass += ` line_level_${this.props.level}`; |
| 36 |
return cssClass; |
| 37 |
} |
| 38 |
|
| 39 |
get debit() { |
| 40 |
if (this.props.line?.debit) { |
| 41 |
return this.env.formatMonetary(this.props.line.debit); |
| 42 |
} |
| 43 |
return false; |
| 44 |
} |
| 45 |
|
| 46 |
get displayTotalOnSeparateLine() { |
| 47 |
return Boolean(this.props.value && this.state.displaySublines); |
| 48 |
} |
| 49 |
|
| 50 |
get formattedValue() { |
| 51 |
if (this.props.value !== undefined) { |
| 52 |
return this.env.formatMonetary(this.props.value); |
| 53 |
} |
| 54 |
return false; |
| 55 |
} |
| 56 |
|
| 57 |
get label() { |
| 58 |
return this.props.label || this.props.line.account?.display_name; |
| 59 |
} |
| 60 |
|
| 61 |
get totalProps() { |
| 62 |
const props = { |
| 63 |
class: "total", |
| 64 |
label: this.env._t("Total"), |
| 65 |
level: this.props.level, |
| 66 |
value: this.props.value, |
| 67 |
}; |
| 68 |
if (this.props.onClickMethod) { |
| 69 |
props.onClickMethod = this.props.onClickMethod; |
| 70 |
} |
| 71 |
return props; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
onClick() { |
| 76 |
this.props.onClickMethod && this.props.onClickMethod(this.props.line); |
| 77 |
} |
| 78 |
|
| 79 |
onClickToggle() { |
| 80 |
if (this.props.sublines && this.props.sublines.length) { |
| 81 |
this.state.displaySublines = !this.state.displaySublines; |
| 82 |
} |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
StockValuationReportLine.components = { StockValuationReportLine }; |