| 1 |
import { _t } from "@web/core/l10n/translation"; |
| 2 |
import { registry } from "@web/core/registry"; |
| 3 |
import { useService } from "@web/core/utils/hooks"; |
| 4 |
import { ControlPanel } from "@web/search/control_panel/control_panel"; |
| 5 |
import { formatMonetary } from "@web/views/fields/formatters"; |
| 6 |
import { standardActionServiceProps } from "@web/webclient/actions/action_service"; |
| 7 |
|
| 8 |
import { Component, onWillStart, useChildSubEnv, useState } from "@odoo/owl"; |
| 9 |
|
| 10 |
import { StockValuationReportButtonsBar } from "../stock_valuation/buttons_bar/buttons_bar" |
| 11 |
import { StockValuationReportController } from "../stock_valuation/controller" |
| 12 |
import { StockValuationReportFilters } from "../stock_valuation/filters/filters" |
| 13 |
import { StockValuationReportLine } from "../stock_valuation/line/line" |
| 14 |
import { StockValuationReportToggleLine } from "../stock_valuation/line/toggle_line" |
| 15 |
|
| 16 |
|
| 17 |
export class StockValuationReport extends Component { |
| 18 |
static template = "stock_account.StockValuationReport"; |
| 19 |
static props = { ...standardActionServiceProps }; |
| 20 |
static components = { |
| 21 |
ControlPanel, |
| 22 |
StockValuationReportButtonsBar, |
| 23 |
StockValuationReportFilters, |
| 24 |
StockValuationReportLine, |
| 25 |
StockValuationReportToggleLine, |
| 26 |
}; |
| 27 |
|
| 28 |
setup() { |
| 29 |
this.controller = useState(new StockValuationReportController(this.props.action)); |
| 30 |
this.state = useState({ |
| 31 |
displayInventoryValuationLine: false, |
| 32 |
}) |
| 33 |
this.orm = useService("orm"); |
| 34 |
this.actionService = useService("action"); |
| 35 |
this._t = _t; |
| 36 |
|
| 37 |
onWillStart(async () => { |
| 38 |
await this.controller.load(this.data); |
| 39 |
}) |
| 40 |
|
| 41 |
useChildSubEnv({ |
| 42 |
_t, |
| 43 |
controller: this.controller, |
| 44 |
formatMonetary: this.formatMonetary.bind(this), |
| 45 |
}); |
| 46 |
} |
| 47 |
|
| 48 |
formatMonetary(value) { |
| 49 |
return formatMonetary(value, { |
| 50 |
currencyId: this.data.currency_id, |
| 51 |
}); |
| 52 |
} |
| 53 |
|
| 54 |
get accrual() { |
| 55 |
return { label: _t("Accrual"), lines: [], value: 0 }; |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
get data() { |
| 60 |
return this.controller.data || {}; |
| 61 |
} |
| 62 |
|
| 63 |
get accountingStockValuation() { |
| 64 |
return this.formatMonetary(this.data.accounting_stock_valuation); |
| 65 |
} |
| 66 |
|
| 67 |
get inventoryValuation() { |
| 68 |
return formatMonetary(this.data.inventory_valuation.value, { |
| 69 |
currencyId: this.data.currency_id, |
| 70 |
}); |
| 71 |
} |
| 72 |
|
| 73 |
get stockInitial() { |
| 74 |
return this.formatMonetary(this.data.stock_initial); |
| 75 |
} |
| 76 |
|
| 77 |
get stockVariation() { |
| 78 |
return this.formatMonetary(this.data.stock_variation); |
| 79 |
} |
| 80 |
|
| 81 |
|
| 82 |
openAccountMoves(accountMoves=false) { |
| 83 |
const additionalContext = {}; |
| 84 |
const domain = []; |
| 85 |
if (accountMoves) { |
| 86 |
const ids = accountMoves.map((am) => am.id); |
| 87 |
const names = accountMoves.map((am) => am.name); |
| 88 |
additionalContext.search_default_name = names; |
| 89 |
additionalContext.search_default_ids = ids; |
| 90 |
domain.push(["id", "in", ids]) |
| 91 |
} |
| 92 |
return this.actionService.doAction( |
| 93 |
"account.action_move_journal_line", |
| 94 |
{ additionalContext, domain } |
| 95 |
); |
| 96 |
} |
| 97 |
|
| 98 |
openStockMoveView(title, usage) { |
| 99 |
const domain = [ |
| 100 |
"|", |
| 101 |
["location_id.usage", "=", usage], |
| 102 |
["location_dest_id.usage", "=", usage], |
| 103 |
]; |
| 104 |
if (this.controller.dateAsString) { |
| 105 |
domain.unshift("&"); |
| 106 |
domain.push(["date", "<=", this.controller.dateAsString]); |
| 107 |
} |
| 108 |
return this.actionService.doAction({ |
| 109 |
name: title, |
| 110 |
type: "ir.actions.act_window", |
| 111 |
res_model: "stock.move", |
| 112 |
domain, |
| 113 |
views: [[false, 'list'], [false, 'form']], |
| 114 |
target: 'current', |
| 115 |
}); |
| 116 |
} |
| 117 |
|
| 118 |
openInventoryLoss() { |
| 119 |
return this.openStockMoveView(_t("Inventory Loss"), "inventory"); |
| 120 |
} |
| 121 |
|
| 122 |
openStockReport() { |
| 123 |
const additionalContext = {}; |
| 124 |
if (this.controller.dateAsString) { |
| 125 |
additionalContext.to_date = this.controller.dateAsString; |
| 126 |
} |
| 127 |
return this.actionService.doAction( |
| 128 |
"stock.action_product_stock_view", |
| 129 |
{ additionalContext } |
| 130 |
); |
| 131 |
} |
| 132 |
|
| 133 |
toggleInventoryValuationFold() { |
| 134 |
this.state.displayInventoryValuationLine = !this.state.displayInventoryValuationLine; |
| 135 |
} |
| 136 |
} |
| 137 |
|
| 138 |
registry.category("actions").add("stock_valuation_report", StockValuationReport); |