accountant_cn
This commit is contained in:
BIN
accountant_cn/static/description/icon.png
Normal file
BIN
accountant_cn/static/description/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
44
accountant_cn/static/src/js/dn_fr_filter_comparison.js
Normal file
44
accountant_cn/static/src/js/dn_fr_filter_comparison.js
Normal file
@@ -0,0 +1,44 @@
|
||||
/** @odoo-module **/
|
||||
/**
|
||||
* Comparison filter for the report control panel.
|
||||
*
|
||||
* Same shape as enterprise: a `btn btn-secondary` labelled "Comparison" with
|
||||
* the selected period appended, backed by a Dropdown of choices. Keeps the
|
||||
* control panel consistent with the date filter next to it.
|
||||
*/
|
||||
import { Component } from "@odoo/owl";
|
||||
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
|
||||
export class DnFrComparisonFilter extends Component {
|
||||
static template = "dn_financial_reports.DnFrComparisonFilter";
|
||||
static components = { Dropdown, DropdownItem };
|
||||
|
||||
get options() {
|
||||
return [
|
||||
{ value: "", label: _t("No Comparison") },
|
||||
{ value: "previous_period", label: _t("Previous Period") },
|
||||
{ value: "previous_year", label: _t("Previous Year") },
|
||||
{ value: "both", label: _t("Previous Period + Previous Year") },
|
||||
];
|
||||
}
|
||||
|
||||
get labelComparison() {
|
||||
return _t("Comparison");
|
||||
}
|
||||
|
||||
get selectedLabel() {
|
||||
const value = this.view.comparison();
|
||||
const found = this.options.find((o) => o.value === value);
|
||||
return found ? found.label : _t("No Comparison");
|
||||
}
|
||||
|
||||
select(value) {
|
||||
this.view.setComparison(value);
|
||||
}
|
||||
|
||||
get view() {
|
||||
return this.env.dnFrView;
|
||||
}
|
||||
}
|
||||
21
accountant_cn/static/src/js/dn_fr_filter_comparison.xml
Normal file
21
accountant_cn/static/src/js/dn_fr_filter_comparison.xml
Normal file
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="dn_financial_reports.DnFrComparisonFilter">
|
||||
<Dropdown menuClass="'account_report_filter comparison'">
|
||||
<button class="btn btn-secondary">
|
||||
<t t-out="this.labelComparison"/>
|
||||
<t t-if="this.view.comparison()">
|
||||
<span>: </span><t t-out="this.selectedLabel"/>
|
||||
</t>
|
||||
</button>
|
||||
<t t-set-slot="content">
|
||||
<t t-foreach="this.options" t-as="option" t-key="option.value">
|
||||
<DropdownItem onSelected="() => this.select(option.value)"
|
||||
class="{ 'selected': this.view.comparison() === option.value }">
|
||||
<t t-out="option.label"/>
|
||||
</DropdownItem>
|
||||
</t>
|
||||
</t>
|
||||
</Dropdown>
|
||||
</t>
|
||||
</templates>
|
||||
88
accountant_cn/static/src/js/dn_fr_filter_date.js
Normal file
88
accountant_cn/static/src/js/dn_fr_filter_date.js
Normal file
@@ -0,0 +1,88 @@
|
||||
/** @odoo-module **/
|
||||
/**
|
||||
* Date filter for the report control panel.
|
||||
*
|
||||
* Enterprise renders this as a `btn btn-secondary` carrying a calendar icon
|
||||
* and the human-readable period ("January 2026", "This Year", ...), with a
|
||||
* Dropdown of periods behind it. Reproducing that shape — rather than a bare
|
||||
* `<input type="date">` with a `<label>` above it — is what makes the control
|
||||
* panel read as an Odoo report instead of a custom form.
|
||||
*
|
||||
* The actual dates live on the parent view (shared through the sub-env), so
|
||||
* this component only formats and offers the choices; it never owns state.
|
||||
*/
|
||||
import { Component } from "@odoo/owl";
|
||||
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
|
||||
import { _t } from "@web/core/l10n/translation";
|
||||
|
||||
// Luxon is loaded globally by Odoo's web assets and its default locale is set
|
||||
// to the session language, so `toLocaleString` renders "2026年1月" in zh_CN and
|
||||
// "January 2026" in en_US. Using it instead of a hard-coded English month list
|
||||
// is what keeps the control-panel button in the user's language.
|
||||
const DateTime = luxon.DateTime;
|
||||
|
||||
export class DnFrDateFilter extends Component {
|
||||
static template = "dn_financial_reports.DnFrDateFilter";
|
||||
static components = { Dropdown, DropdownItem };
|
||||
|
||||
/** Presets the reviewer can pick without typing two dates. */
|
||||
get presets() {
|
||||
const now = new Date();
|
||||
const y = now.getFullYear();
|
||||
const m = now.getMonth();
|
||||
const iso = (d) => {
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||
};
|
||||
return [
|
||||
{ key: "this_month", label: _t("This Month"),
|
||||
from: iso(new Date(y, m, 1)), to: iso(new Date(y, m + 1, 0)) },
|
||||
{ key: "last_month", label: _t("Last Month"),
|
||||
from: iso(new Date(y, m - 1, 1)), to: iso(new Date(y, m, 0)) },
|
||||
{ key: "this_year", label: _t("This Year"),
|
||||
from: iso(new Date(y, 0, 1)), to: iso(new Date(y, 11, 31)) },
|
||||
{ key: "last_year", label: _t("Last Year"),
|
||||
from: iso(new Date(y - 1, 0, 1)), to: iso(new Date(y - 1, 11, 31)) },
|
||||
{ key: "today", label: _t("Today"),
|
||||
from: iso(now), to: iso(now) },
|
||||
];
|
||||
}
|
||||
|
||||
/** Human description shown on the button, in the session language. */
|
||||
get description() {
|
||||
const from = this.view.dateFrom();
|
||||
const to = this.view.dateTo();
|
||||
if (!from || !to) return _t("Custom Dates");
|
||||
const start = DateTime.fromISO(from);
|
||||
const end = DateTime.fromISO(to);
|
||||
const short = (d) => d.toLocaleString({ month: "short", day: "numeric" });
|
||||
if (from === to) {
|
||||
return start.toLocaleString(luxon.DateTime.DATE_FULL);
|
||||
}
|
||||
if (this.isFullMonth(from, to)) {
|
||||
// "2026年1月" / "January 2026" — no day, because the whole month
|
||||
// is selected. This mirrors the enterprise date button exactly.
|
||||
return start.toLocaleString({ month: "long", year: "numeric" });
|
||||
}
|
||||
return `${short(start)} – ${short(end)}, ${end.year}`;
|
||||
}
|
||||
|
||||
isFullMonth(from, to) {
|
||||
if (!from || !to) return false;
|
||||
const start = new Date(from + "T00:00:00");
|
||||
const end = new Date(to + "T00:00:00");
|
||||
return start.getDate() === 1 &&
|
||||
end.getDate() === new Date(end.getFullYear(), end.getMonth() + 1, 0).getDate() &&
|
||||
start.getFullYear() === end.getFullYear() &&
|
||||
start.getMonth() === end.getMonth();
|
||||
}
|
||||
|
||||
get view() {
|
||||
return this.env.dnFrView;
|
||||
}
|
||||
|
||||
applyPreset(preset) {
|
||||
this.view.setDates(preset.from, preset.to);
|
||||
}
|
||||
}
|
||||
29
accountant_cn/static/src/js/dn_fr_filter_date.xml
Normal file
29
accountant_cn/static/src/js/dn_fr_filter_date.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="dn_financial_reports.DnFrDateFilter">
|
||||
<Dropdown menuClass="'account_report_filter date'">
|
||||
<button class="btn btn-secondary">
|
||||
<i class="oi oi-filled me-1" data-icon="calendar_today"/>
|
||||
<t t-out="this.description"/>
|
||||
</button>
|
||||
<t t-set-slot="content">
|
||||
<t t-foreach="this.presets" t-as="preset" t-key="preset.key">
|
||||
<DropdownItem onSelected="() => this.applyPreset(preset)"
|
||||
class="{ 'date_filter': true, 'selected': this.view.dateFrom() === preset.from and this.view.dateTo() === preset.to }">
|
||||
<span t-out="preset.label"/>
|
||||
</DropdownItem>
|
||||
</t>
|
||||
<div class="dropdown-divider"/>
|
||||
<div class="dropdown-item date d-flex align-items-center gap-2">
|
||||
<input type="date" class="o_input form-control form-control-sm"
|
||||
t-att-value="this.view.dateFrom()"
|
||||
t-on-change="(ev) => this.view.setDates(ev.target.value, this.view.dateTo())"/>
|
||||
<span t-out="'→'"/>
|
||||
<input type="date" class="o_input form-control form-control-sm"
|
||||
t-att-value="this.view.dateTo()"
|
||||
t-on-change="(ev) => this.view.setDates(this.view.dateFrom(), ev.target.value)"/>
|
||||
</div>
|
||||
</t>
|
||||
</Dropdown>
|
||||
</t>
|
||||
</templates>
|
||||
47
accountant_cn/static/src/js/dn_fr_header.js
Normal file
47
accountant_cn/static/src/js/dn_fr_header.js
Normal file
@@ -0,0 +1,47 @@
|
||||
/** @odoo-module **/
|
||||
/**
|
||||
* DN Financial Reports — table header.
|
||||
*
|
||||
* A separate component from the body, for the same reason the enterprise report
|
||||
* has one: the header is sticky, and re-rendering it on every fold would make
|
||||
* the whole page flicker. Here it renders once per payload and stays put.
|
||||
*
|
||||
* The header is also where the column widths are decided. There is no
|
||||
* `<colgroup>` on purpose — see `dn_fr_view.scss` — because `<col>` widths
|
||||
* override the hints given here, and the hint is the only mechanism that makes
|
||||
* the amount columns sit next to the label column instead of at the far right
|
||||
* edge of a stretched table:
|
||||
*
|
||||
* 1. the label header asks for `width: 100%`, so it absorbs all slack;
|
||||
* 2. every amount header asks for `width: 1%` plus a `min-width` floor, so it
|
||||
* shrinks to exactly its content — or to the floor when the content is
|
||||
* narrower than the floor.
|
||||
*/
|
||||
import { Component, t, useProps } from "@odoo/owl";
|
||||
|
||||
export class DnFrHeader extends Component {
|
||||
static template = "dn_financial_reports.DnFrHeader";
|
||||
|
||||
props = useProps({
|
||||
columns: t.array(),
|
||||
labels: t.object(),
|
||||
isLedger: t.boolean().optional(false),
|
||||
});
|
||||
|
||||
/**
|
||||
* The dates under a column title.
|
||||
*
|
||||
* Only one of the two ends is always present: a balance-sheet column has a
|
||||
* date_to but no date_from (it is a point in time), so printing
|
||||
* "— 2026-12-31" with a leading dash reads like a missing value. Emitting
|
||||
* whichever ends exist avoids that.
|
||||
*/
|
||||
formatRange(column) {
|
||||
const from = column.date_from || "";
|
||||
const to = column.date_to || "";
|
||||
if (from && to) {
|
||||
return `${from} — ${to}`;
|
||||
}
|
||||
return from || to;
|
||||
}
|
||||
}
|
||||
33
accountant_cn/static/src/js/dn_fr_header.xml
Normal file
33
accountant_cn/static/src/js/dn_fr_header.xml
Normal file
@@ -0,0 +1,33 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="dn_financial_reports.DnFrHeader">
|
||||
<!-- `sticky` is the enterprise class name and this stylesheet defines
|
||||
it, so the header stays pinned while the card scrolls. `dn_fr_label_col`
|
||||
asks for 100% of the remaining width and `dn_fr_amount_col` for 1%,
|
||||
which is the only reliable way to get "label takes the rest,
|
||||
amounts take their content width" out of `table-layout: auto`. -->
|
||||
<thead class="dn_fr_thead sticky">
|
||||
<tr t-if="this.props.isLedger" data-id="column_headers_row">
|
||||
<th class="dn_fr_label_col" t-out="this.props.labels.ledgerHeader"/>
|
||||
<th class="dn_fr_amount_col column_header numeric-header" t-out="this.props.labels.debit"/>
|
||||
<th class="dn_fr_amount_col column_header numeric-header" t-out="this.props.labels.credit"/>
|
||||
<th class="dn_fr_amount_col column_header numeric-header" t-out="this.props.labels.cumulativeBalance"/>
|
||||
</tr>
|
||||
<tr t-else="" data-id="column_headers_row">
|
||||
<th class="dn_fr_label_col" t-out="this.props.labels.accountHeader"/>
|
||||
<t t-foreach="this.props.columns" t-as="column" t-key="column.key">
|
||||
<th class="dn_fr_amount_col column_header numeric-header">
|
||||
<div t-out="column.label"/>
|
||||
<!-- Second line: the period the column covers. Only
|
||||
rendered when the server actually sent a range, so
|
||||
a single-column report does not get an empty
|
||||
sub-heading that doubles the header height. -->
|
||||
<div t-if="column.date_from or column.date_to"
|
||||
class="dn_fr_subhead fw-normal"
|
||||
t-out="this.formatRange(column)"/>
|
||||
</th>
|
||||
</t>
|
||||
</tr>
|
||||
</thead>
|
||||
</t>
|
||||
</templates>
|
||||
72
accountant_cn/static/src/js/dn_fr_line.js
Normal file
72
accountant_cn/static/src/js/dn_fr_line.js
Normal file
@@ -0,0 +1,72 @@
|
||||
/** @odoo-module **/
|
||||
/**
|
||||
* DN Financial Reports — one report line.
|
||||
*
|
||||
* The line is a component so that folding one section does not re-render the
|
||||
* whole table: the row reads its own `DnFrLine` model instance, and Owl only
|
||||
* repaints the rows whose model object actually changed.
|
||||
*
|
||||
* The label cell is inline rather than a sub-component like the enterprise
|
||||
* `AccountReportLineName`. Enterprise needs that extra layer because it also
|
||||
* hosts chatter annotations, caret menus and account status badges; none of
|
||||
* that exists here, so a sub-component would only add a render boundary with
|
||||
* nothing to gain. The amount cells *are* separate components — there are many
|
||||
* of them, and they change independently.
|
||||
*/
|
||||
import { Component, computed, t, useProps } from "@odoo/owl";
|
||||
import { formatFloat } from "@web/views/fields/formatters";
|
||||
import { DnFrLineCell } from "./dn_fr_line_cell";
|
||||
|
||||
export class DnFrLine extends Component {
|
||||
static template = "dn_financial_reports.DnFrLine";
|
||||
static components = { DnFrLineCell };
|
||||
|
||||
props = useProps({
|
||||
line: t.object(),
|
||||
labels: t.object(),
|
||||
unfolded: t.boolean().optional(false),
|
||||
isLedger: t.boolean().optional(false),
|
||||
onToggle: t.function(),
|
||||
onAction: t.function(),
|
||||
});
|
||||
|
||||
/**
|
||||
* Recomputed only when this row's own fold state changes.
|
||||
*
|
||||
* The fold state is a prop rather than something the row reads off the
|
||||
* model, so toggling one section re-runs the class computation for that
|
||||
* row alone instead of for every row of the table.
|
||||
*/
|
||||
classes = computed(() => this.props.line.lineClasses(this.props.unfolded));
|
||||
|
||||
get line() {
|
||||
return this.props.line;
|
||||
}
|
||||
|
||||
toggle() {
|
||||
this.props.onToggle(this.props.line);
|
||||
}
|
||||
|
||||
runAction(ev) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
this.props.onAction(this.props.line);
|
||||
}
|
||||
|
||||
/**
|
||||
* A detail row's figures are already plain numbers; format them the same
|
||||
* way a normal cell does so the columns stay aligned. An empty figure
|
||||
* renders as an empty cell rather than "0.00": on a ledger, a line with no
|
||||
* debit has no debit, and printing a zero would imply it does.
|
||||
*/
|
||||
detailValue(key) {
|
||||
const value = this.line.detail ? this.line.detail[key] : undefined;
|
||||
if (value === null || value === undefined || value === "") {
|
||||
return "";
|
||||
}
|
||||
if (!value) {
|
||||
return "";
|
||||
}
|
||||
return formatFloat(Number(value), { digits: [16, 2] });
|
||||
}
|
||||
}
|
||||
75
accountant_cn/static/src/js/dn_fr_line.xml
Normal file
75
accountant_cn/static/src/js/dn_fr_line.xml
Normal file
@@ -0,0 +1,75 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="dn_financial_reports.DnFrLine">
|
||||
<!-- ==========================================================
|
||||
A journal-item detail row (ledger expansion).
|
||||
The date, entry number, label and partner share the first
|
||||
cell: they are one piece of information, and splitting them
|
||||
across columns would leave three near-empty columns on
|
||||
every other report.
|
||||
========================================================== -->
|
||||
<tr t-if="this.line.detail" data-id="line" t-att-class="this.classes()">
|
||||
<td data-id="line_name" class="line_name">
|
||||
<span class="text-muted me-2" t-out="this.line.detail.date"/>
|
||||
<span class="fw-semibold me-2" t-out="this.line.detail.move_name"/>
|
||||
<span t-out="this.line.detail.label"/>
|
||||
<span t-if="this.line.detail.partner" class="text-muted ms-2"
|
||||
t-out="'· ' + this.line.detail.partner"/>
|
||||
</td>
|
||||
<td data-id="line_cell" class="line_cell numeric text-end"
|
||||
t-out="this.detailValue('debit')"/>
|
||||
<td data-id="line_cell" class="line_cell numeric text-end line_cell_odd"
|
||||
t-out="this.detailValue('credit')"/>
|
||||
<td data-id="line_cell" class="line_cell numeric text-end"
|
||||
t-out="this.detailValue('cumulative')"/>
|
||||
</tr>
|
||||
|
||||
<!-- ==========================================================
|
||||
A summary / account row.
|
||||
========================================================== -->
|
||||
<tr t-else="" data-id="line" t-att-class="this.classes()">
|
||||
<!-- Name column. A foldable section keeps its arrow in a fixed
|
||||
20px box so that labels line up whether or not they can be
|
||||
unfolded; enterprise calls this `.btn_foldable` and the
|
||||
geometry below is identical. -->
|
||||
<td data-id="line_name"
|
||||
t-att-class="this.line.unfoldable ? 'line_name unfoldable' : 'line_name'"
|
||||
tabindex="-1"
|
||||
t-on-click="() => this.toggle()">
|
||||
|
||||
<i t-if="this.line.unfoldable"
|
||||
data-id="btn_foldable"
|
||||
class="btn btn_foldable oi"
|
||||
tabindex="-1"
|
||||
t-att-data-icon="this.props.unfolded ? 'arrow_drop_down' : 'arrow_right'"/>
|
||||
|
||||
<span t-if="this.line.showCode"
|
||||
class="text-muted me-2" t-out="this.line.code"/>
|
||||
|
||||
<a t-if="this.line.hasAction"
|
||||
class="clickable cursor-pointer"
|
||||
tabindex="-1"
|
||||
t-on-click="(ev) => this.runAction(ev)"
|
||||
t-out="this.line.label"/>
|
||||
<t t-else="" t-out="this.line.label"/>
|
||||
|
||||
<!-- Drill-down affordance, revealed on row hover exactly like
|
||||
the enterprise `.btn_action`. It is a hover-only button,
|
||||
not a permanent arrow, so an accountant reading a column
|
||||
of figures is not distracted by 300 icons. -->
|
||||
<button t-if="this.line.hasAction"
|
||||
data-id="btn_action"
|
||||
class="btn btn_action"
|
||||
tabindex="-1"
|
||||
t-att-title="this.props.labels.viewDetails"
|
||||
t-on-click="(ev) => this.runAction(ev)">
|
||||
<i class="fa fa-arrow-right"/>
|
||||
</button>
|
||||
</td>
|
||||
|
||||
<t t-foreach="this.line.cells" t-as="cell" t-key="cell.key">
|
||||
<DnFrLineCell cell="cell"/>
|
||||
</t>
|
||||
</tr>
|
||||
</t>
|
||||
</templates>
|
||||
39
accountant_cn/static/src/js/dn_fr_line_cell.js
Normal file
39
accountant_cn/static/src/js/dn_fr_line_cell.js
Normal file
@@ -0,0 +1,39 @@
|
||||
/** @odoo-module **/
|
||||
/**
|
||||
* DN Financial Reports — one amount cell.
|
||||
*
|
||||
* A component of its own rather than an inline `<td>` in the row template, so
|
||||
* that a cell re-renders only when its own value changes. On a balance sheet
|
||||
* with 300 accounts and two comparison columns that is 900 cells; keeping them
|
||||
* as separate components is what stops a fold from repainting all of them.
|
||||
*
|
||||
* All the decisions live in `DnFrCell` (see `dn_fr_model.js`); this component
|
||||
* is deliberately thin and only maps the model onto markup.
|
||||
*/
|
||||
import { Component, computed, t, useProps } from "@odoo/owl";
|
||||
import { COMPARISON_MODE } from "./dn_fr_model";
|
||||
|
||||
export class DnFrLineCell extends Component {
|
||||
static template = "dn_financial_reports.DnFrLineCell";
|
||||
|
||||
props = useProps({
|
||||
cell: t.object(),
|
||||
});
|
||||
|
||||
/** The styling hooks, recomputed only when the value itself changes. */
|
||||
classes = computed(() => {
|
||||
const classes = this.props.cell.cssClass;
|
||||
switch (this.props.cell.comparisonMode) {
|
||||
case COMPARISON_MODE.MUTED:
|
||||
return `${classes} muted`;
|
||||
case COMPARISON_MODE.RED:
|
||||
return `${classes} text-danger`;
|
||||
default:
|
||||
return classes;
|
||||
}
|
||||
});
|
||||
|
||||
get name() {
|
||||
return this.props.cell.name;
|
||||
}
|
||||
}
|
||||
6
accountant_cn/static/src/js/dn_fr_line_cell.xml
Normal file
6
accountant_cn/static/src/js/dn_fr_line_cell.xml
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="dn_financial_reports.DnFrLineCell">
|
||||
<td data-id="line_cell" t-att-class="this.classes()" t-out="this.name"/>
|
||||
</t>
|
||||
</templates>
|
||||
362
accountant_cn/static/src/js/dn_fr_model.js
Normal file
362
accountant_cn/static/src/js/dn_fr_model.js
Normal file
@@ -0,0 +1,362 @@
|
||||
/** @odoo-module **/
|
||||
/**
|
||||
* DN Financial Reports — row and cell model.
|
||||
*
|
||||
* This file is the structural half of the report renderer. It turns the nested
|
||||
* tree the server sends into the shape the components want to render, and it
|
||||
* owns every decision about *how* a line or a cell should look. The components
|
||||
* in `dn_fr_line.js` / `dn_fr_line_cell.js` then do nothing but read from this
|
||||
* model, which keeps them cheap to re-render and easy to override one at a
|
||||
* time through the component registry.
|
||||
*
|
||||
* Two shape decisions are deliberate and mirror the way enterprise reports are
|
||||
* built, because they are what makes the rendered page look right:
|
||||
*
|
||||
* 1. **Lines are a flat array, not a tree.** A report page is a long list of
|
||||
* rows. Nesting depth survives as `level`, which is all the indentation
|
||||
* CSS needs; parenthood survives as a `parentId`, which is all the fold
|
||||
* logic needs. Deciding what is drawn is then a single pass over an
|
||||
* already-ordered array instead of a recursive walk on every render.
|
||||
* 2. **A line owns a `cells` array, one entry per amount column.** Columns
|
||||
* are data (they change with the comparison filter), so they cannot be
|
||||
* hard-coded in a template. Each cell carries its own figure type and
|
||||
* sign semantics, which is what lets a loss render in the danger colour
|
||||
* and a zero render muted without any conditional logic in the template.
|
||||
*
|
||||
* **The model is immutable from the view's point of view.** Fold state is not
|
||||
* stored here: it lives in the view as a reactive `{lineId: folded}` map. That
|
||||
* split matters, because mutating a deeply-nested reactive tree is what makes
|
||||
* Owl re-render every row whenever one section is folded. With the fold state
|
||||
* separate, the view re-renders, the fold map decides which rows are drawn, and
|
||||
* each row's `unfolded` prop changes only for the row that was clicked.
|
||||
*/
|
||||
import { formatFloat } from "@web/views/fields/formatters";
|
||||
|
||||
/** Column figure types, matching what the server sends per expression. */
|
||||
export const FIGURE_TYPE = {
|
||||
MONETARY: "monetary",
|
||||
PERCENT: "percent",
|
||||
RATIO: "ratio",
|
||||
INTEGER: "integer",
|
||||
FLOAT: "float",
|
||||
STRING: "string",
|
||||
DATE: "date",
|
||||
};
|
||||
|
||||
/**
|
||||
* Numeric types are end-aligned and go through `formatFloat`.
|
||||
*
|
||||
* `ratio` belongs here: the server uses it for a plain quotient that has no
|
||||
* percent sign, so it must be right-aligned like any other figure but must not
|
||||
* get the `%` suffix that `percent` gets.
|
||||
*/
|
||||
const NUMERIC_TYPES = new Set([
|
||||
FIGURE_TYPE.MONETARY,
|
||||
FIGURE_TYPE.PERCENT,
|
||||
FIGURE_TYPE.RATIO,
|
||||
FIGURE_TYPE.INTEGER,
|
||||
FIGURE_TYPE.FLOAT,
|
||||
]);
|
||||
|
||||
/**
|
||||
* Comparison semantics for a cell value.
|
||||
*
|
||||
* Enterprise distinguishes three cases: a normal figure, a zero ("muted"), and
|
||||
* a negative figure shown in red. Applying the red only to cells the server did
|
||||
* not already flag as text avoids the classic false positive — a credit-balance
|
||||
* asset account is not an error and must not be painted red.
|
||||
*/
|
||||
export const COMPARISON_MODE = {
|
||||
DEFAULT: "default",
|
||||
MUTED: "muted",
|
||||
RED: "red",
|
||||
};
|
||||
|
||||
/**
|
||||
* One amount in one column of one line.
|
||||
*
|
||||
* Constructed once per line per column and never mutated afterwards, so the
|
||||
* getters can be cheap and the component can trust them. `raw` keeps the
|
||||
* unformatted value so CSV export and drill-downs do not have to re-parse a
|
||||
* localised string.
|
||||
*/
|
||||
export class DnFrCell {
|
||||
/**
|
||||
* @param {object} params
|
||||
* @param {*} params.raw server value (number, string, null)
|
||||
* @param {boolean} params.isText the server says this is a label, not a figure
|
||||
* @param {string} params.figureType one of FIGURE_TYPE
|
||||
* @param {string} params.key the column key (`c0`, `c1`, …)
|
||||
* @param {number} params.index position in the row, used for striping
|
||||
*/
|
||||
constructor({ raw, isText, figureType, key, index }) {
|
||||
this.raw = raw;
|
||||
this.isText = isText;
|
||||
this.figureType = figureType || FIGURE_TYPE.MONETARY;
|
||||
this.key = key;
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/** True when the value should be rendered right-aligned as a figure. */
|
||||
get isNumeric() {
|
||||
return !this.isText && NUMERIC_TYPES.has(this.figureType);
|
||||
}
|
||||
|
||||
/** True when there is nothing to show at all. */
|
||||
get isEmpty() {
|
||||
return this.raw === null || this.raw === undefined || this.raw === "";
|
||||
}
|
||||
|
||||
/**
|
||||
* The value as it should appear on screen.
|
||||
*
|
||||
* `formatFloat` applies the user's own language parameters (thousands
|
||||
* separator, decimal point) rather than a fixed locale, so a French user
|
||||
* reads 1 234,56 and an English user 1,234.56. The precision is 2 for
|
||||
* amounts and 1 for percentages, which is what enterprise shows.
|
||||
*/
|
||||
get name() {
|
||||
if (this.isEmpty) {
|
||||
return "";
|
||||
}
|
||||
if (!this.isNumeric) {
|
||||
return String(this.raw);
|
||||
}
|
||||
const value = Number(this.raw);
|
||||
if (Number.isNaN(value)) {
|
||||
return String(this.raw);
|
||||
}
|
||||
if (this.figureType === FIGURE_TYPE.PERCENT) {
|
||||
return `${formatFloat(value, { digits: [16, 1] })}%`;
|
||||
}
|
||||
if (this.figureType === FIGURE_TYPE.INTEGER) {
|
||||
// An integer figure (a headcount, a count of entries) must not grow
|
||||
// two decimals: 12 stays 12, not 12.00.
|
||||
return formatFloat(value, { digits: [16, 0] });
|
||||
}
|
||||
return formatFloat(value, { digits: [16, 2] });
|
||||
}
|
||||
|
||||
/** The value used for export and for drill-downs. */
|
||||
get no_format() {
|
||||
return this.isEmpty ? "" : this.raw;
|
||||
}
|
||||
|
||||
/** Zero renders muted, negatives render in the danger colour. */
|
||||
get comparisonMode() {
|
||||
if (!this.isNumeric || this.isEmpty) {
|
||||
return COMPARISON_MODE.DEFAULT;
|
||||
}
|
||||
const value = Number(this.raw);
|
||||
if (!value) {
|
||||
return COMPARISON_MODE.MUTED;
|
||||
}
|
||||
return value < 0 ? COMPARISON_MODE.RED : COMPARISON_MODE.DEFAULT;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extra classes the stylesheet hooks into.
|
||||
*
|
||||
* `line_cell` is the base class every amount cell carries in enterprise,
|
||||
* and the whole cell stylesheet is written as `.line_cell.numeric` /
|
||||
* `.line_cell.date`. Leaving it out would silently drop the right-aligned
|
||||
* gutter and the date centring, so it is added here rather than in the
|
||||
* template — the template writes `t-att-class` and a static `class`
|
||||
* attribute would be overwritten by it.
|
||||
*
|
||||
* `line_cell_odd` is the zebra stripe for every second amount column. It
|
||||
* exists in enterprise too and is the reason a comparison report reads as
|
||||
* pairs of columns instead of one wide block of numbers.
|
||||
*/
|
||||
get cssClass() {
|
||||
const classes = ["line_cell"];
|
||||
if (this.isNumeric) {
|
||||
classes.push("numeric");
|
||||
} else if (this.figureType === FIGURE_TYPE.DATE) {
|
||||
classes.push("date");
|
||||
} else {
|
||||
classes.push("text");
|
||||
}
|
||||
if (this.index % 2) {
|
||||
classes.push("line_cell_odd");
|
||||
}
|
||||
return classes.join(" ");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* One rendered row.
|
||||
*
|
||||
* @param {object} payload one node from the server tree
|
||||
* @param {Array<object>} columns the column descriptors
|
||||
* @param {number|null} parentId id of the enclosing line
|
||||
*/
|
||||
export class DnFrLine {
|
||||
constructor(payload, columns, parentId = null) {
|
||||
this.level = payload.level || 0;
|
||||
this.id = payload.id;
|
||||
this.parentId = parentId;
|
||||
this.code = payload.code || "";
|
||||
this.label = payload.name || "";
|
||||
this.isTotal = Boolean(payload.is_total);
|
||||
this.actionId = payload.action_id || false;
|
||||
this.detail = payload.detail || null;
|
||||
|
||||
// `unfoldable` comes from the server, but the child count is the
|
||||
// authority: a pruned tree can leave the flag set on a line whose
|
||||
// children were all dropped for being zero, and showing a fold arrow
|
||||
// that opens onto nothing is worse than showing none.
|
||||
this.childCount = (payload.children || []).length;
|
||||
this.unfoldable = this.childCount > 0;
|
||||
|
||||
this.cells = columns.map(
|
||||
(column, index) =>
|
||||
new DnFrCell({
|
||||
raw: (payload.values || {})[column.key],
|
||||
isText: Boolean((payload.is_text || {})[column.key]),
|
||||
figureType: payload.figure_type,
|
||||
key: column.key,
|
||||
index,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/** True when the line is a section header drawn as a filled band. */
|
||||
get isLevelZero() {
|
||||
return this.level === 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* The classes that drive the whole visual hierarchy.
|
||||
*
|
||||
* `line_level_N` is the same vocabulary enterprise uses: it carries the
|
||||
* indentation and, for `line_level_0`, the filled band. `total` makes a row
|
||||
* bold, `unfolded` thickens its bottom rule. Keeping these names identical
|
||||
* means the stylesheet can be reasoned about next to the enterprise one.
|
||||
*
|
||||
* `unfolded` is only honoured on a line that actually has children. The
|
||||
* view passes `!folded[id]`, and for a leaf that expression is `true`
|
||||
* (nothing is folded away), which would otherwise make every leaf bold.
|
||||
*
|
||||
* @param {boolean} unfolded whether this section is currently open
|
||||
*/
|
||||
lineClasses(unfolded) {
|
||||
const classes = [`line_level_${this.level}`];
|
||||
if (this.isTotal) {
|
||||
classes.push("total");
|
||||
}
|
||||
if (this.unfoldable) {
|
||||
classes.push("unfoldable");
|
||||
if (unfolded) {
|
||||
classes.push("unfolded");
|
||||
}
|
||||
}
|
||||
if (this.detail) {
|
||||
classes.push("detail");
|
||||
}
|
||||
return classes.join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Indentation is *not* set here.
|
||||
*
|
||||
* Enterprise drives it from the stylesheet, with one rule per
|
||||
* `line_level_N` class, and that turns out to matter: the amount cells
|
||||
* need `padding-right: calc(20px + 0.75rem) !important` to keep the same
|
||||
* gutter as the header, and `!important` in the stylesheet beats a plain
|
||||
* inline `padding-left`. Setting the indent inline would therefore be
|
||||
* silently overridden on the first cell. The class alone is enough.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Report line codes are technical identifiers ("REVENUE", "BS_AP"). Show
|
||||
* them only when they look like real account codes, otherwise the label is
|
||||
* duplicated by an internal key that means nothing to the user.
|
||||
*/
|
||||
get showCode() {
|
||||
if (!this.code) {
|
||||
return false;
|
||||
}
|
||||
return !/^[A-Z][A-Z0-9_]*$/.test(this.code);
|
||||
}
|
||||
|
||||
/** The label cell carries the fold arrow and, on ledger rows, the details. */
|
||||
get hasAction() {
|
||||
return Boolean(this.actionId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the flat line array from the server tree.
|
||||
*
|
||||
* A recursive walk whose *result* is flat: the components never see a nested
|
||||
* structure, they see an ordered array where an ancestor always precedes its
|
||||
* descendants. That ordering is what lets the fold logic be a single forward
|
||||
* pass, and it is also the order the browser paints in.
|
||||
*
|
||||
* @param {Array<object>} tree the `lines` array from the server payload
|
||||
* @param {Array<object>} columns the `columns` array from the same payload
|
||||
* @returns {Array<DnFrLine>}
|
||||
*/
|
||||
export function buildLines(tree, columns) {
|
||||
const lines = [];
|
||||
|
||||
const walk = (nodes, parentId) => {
|
||||
for (const node of nodes || []) {
|
||||
const line = new DnFrLine(node, columns, parentId);
|
||||
lines.push(line);
|
||||
if (node.children && node.children.length) {
|
||||
walk(node.children, line.id);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
walk(tree, null);
|
||||
return lines;
|
||||
}
|
||||
|
||||
/**
|
||||
* The ids that must be folded for a report to start collapsed.
|
||||
*
|
||||
* Only sections below the first level: a balance sheet with every account
|
||||
* expanded is unreadable, but hiding its main headings behind a fold would hide
|
||||
* the structure the report exists to show.
|
||||
*/
|
||||
export function defaultFoldedIds(lines) {
|
||||
const folded = {};
|
||||
for (const line of lines) {
|
||||
if (line.unfoldable && line.level > 0) {
|
||||
folded[line.id] = true;
|
||||
}
|
||||
}
|
||||
return folded;
|
||||
}
|
||||
|
||||
/**
|
||||
* Which lines are drawn, given a fold map.
|
||||
*
|
||||
* One forward pass over the ordered array: an ancestor always appears before
|
||||
* its descendants, so by the time a descendant is reached its parent's
|
||||
* visibility is already known. Lines whose parent chain contains a folded
|
||||
* section are dropped.
|
||||
*
|
||||
* @param {Array<DnFrLine>} lines
|
||||
* @param {Object} folded `{lineId: true}` for every closed section
|
||||
* @returns {Array<DnFrLine>}
|
||||
*/
|
||||
export function visibleLines(lines, folded) {
|
||||
const visible = [];
|
||||
const hidden = new Set();
|
||||
for (const line of lines) {
|
||||
const parentHidden = line.parentId !== null && hidden.has(line.parentId);
|
||||
if (parentHidden) {
|
||||
hidden.add(line.id);
|
||||
continue;
|
||||
}
|
||||
visible.push(line);
|
||||
if (line.unfoldable && folded[line.id]) {
|
||||
hidden.add(line.id);
|
||||
}
|
||||
}
|
||||
return visible;
|
||||
}
|
||||
426
accountant_cn/static/src/js/dn_fr_view.js
Normal file
426
accountant_cn/static/src/js/dn_fr_view.js
Normal file
@@ -0,0 +1,426 @@
|
||||
/** @odoo-module **/
|
||||
/**
|
||||
* DN Financial Reports — report renderer.
|
||||
*
|
||||
* A client action that draws a hierarchical financial report: sticky header,
|
||||
* collapsible line tree, journal-item drill-down, date / comparison / filter
|
||||
* controls and CSV export. Written for Odoo 20's Owl 3 runtime.
|
||||
*
|
||||
* ## Architecture
|
||||
*
|
||||
* The page is split the same way the enterprise report page is, because that
|
||||
* split is what makes the geometry come out right:
|
||||
*
|
||||
* DnFrView control panel, filter bar, scroll container
|
||||
* ├── DnFrHeader sticky <thead>, owns the column widths
|
||||
* └── DnFrLine one <tr> per line, reads a DnFrLine model
|
||||
* └── DnFrLineCell one <td> per amount column
|
||||
*
|
||||
* with `dn_fr_model.js` holding the row/cell model that all three read from.
|
||||
* The dedicated `dn_fr_model.js` / `dn_fr_line.js` / `dn_fr_line_cell.js` files
|
||||
* exist so a report variant can override exactly one of those layers without
|
||||
* copying the rest.
|
||||
*
|
||||
* ## Why the lines are flat
|
||||
*
|
||||
* The server sends a nested tree; `buildLines` flattens it into an ordered
|
||||
* array where an ancestor always precedes its descendants. Fold state lives
|
||||
* here in a reactive `{lineId: folded}` map rather than inside the model, so
|
||||
* folding a section repaints the rows whose visibility actually changed
|
||||
* instead of rebuilding the tree — and the template stays a single
|
||||
* `t-foreach`, which is what keeps a 300-account balance sheet responsive.
|
||||
*/
|
||||
import { registry } from "@web/core/registry";
|
||||
import { Component, onWillStart, proxy, signal, t, useProps } from "@odoo/owl";
|
||||
import { rpc } from "@web/core/network/rpc";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { useSubEnv } from "@web/owl2/utils";
|
||||
import { _t, translationIsReady } from "@web/core/l10n/translation";
|
||||
import { ControlPanel } from "@web/search/control_panel/control_panel";
|
||||
import { Dropdown } from "@web/core/dropdown/dropdown";
|
||||
import { DropdownItem } from "@web/core/dropdown/dropdown_item";
|
||||
|
||||
import { DnFrHeader } from "./dn_fr_header";
|
||||
import { DnFrLine } from "./dn_fr_line";
|
||||
import { DnFrDateFilter } from "./dn_fr_filter_date";
|
||||
import { DnFrComparisonFilter } from "./dn_fr_filter_comparison";
|
||||
import {
|
||||
buildLines,
|
||||
defaultFoldedIds,
|
||||
visibleLines as computeVisibleLines,
|
||||
} from "./dn_fr_model";
|
||||
|
||||
function isoDate(value) {
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
return `${value.getFullYear()}-${pad(value.getMonth() + 1)}-${pad(value.getDate())}`;
|
||||
}
|
||||
|
||||
export class DnFrView extends Component {
|
||||
static template = "dn_financial_reports.DnFrView";
|
||||
static components = {
|
||||
ControlPanel,
|
||||
Dropdown,
|
||||
DropdownItem,
|
||||
DnFrHeader,
|
||||
DnFrLine,
|
||||
DnFrDateFilter,
|
||||
DnFrComparisonFilter,
|
||||
};
|
||||
|
||||
// Owl 3 no longer reads a static `props`; the schema must be declared
|
||||
// through the `useProps` hook, which also returns the live props object.
|
||||
props = useProps({
|
||||
action: t.object().optional({}),
|
||||
actionId: t.number().optional(0),
|
||||
});
|
||||
|
||||
setup() {
|
||||
this.orm = useService("orm");
|
||||
this.actionService = useService("action");
|
||||
this.notification = useService("notification");
|
||||
this.state = proxy({
|
||||
loading: true,
|
||||
error: null,
|
||||
report: null,
|
||||
// The flat line array from `buildLines`. Kept in state (not
|
||||
// derived in a getter) because the array is the identity Owl uses
|
||||
// to decide whether the table changed at all.
|
||||
lines: [],
|
||||
filtersOpen: false,
|
||||
});
|
||||
|
||||
// Fold state, kept outside the model: `{lineId: true}` for every closed
|
||||
// section. A reactive proxy rather than a plain object so the template
|
||||
// can read `this.folded[line.id]` directly, and kept as **one object
|
||||
// for the lifetime of the component** — replacing it with a new proxy
|
||||
// would not notify Owl, because the property holding it is not itself
|
||||
// reactive.
|
||||
this.folded = proxy({});
|
||||
|
||||
const today = new Date();
|
||||
this.dateFrom = signal(isoDate(new Date(today.getFullYear(), 0, 1)));
|
||||
this.dateTo = signal(isoDate(today));
|
||||
this.comparison = signal("");
|
||||
this.unreconciled = signal(false);
|
||||
this.includeDraft = signal(false);
|
||||
|
||||
const action = this.props.action || {};
|
||||
const params = action.params || {};
|
||||
const context = action.context || {};
|
||||
this.reportId = params.report_id || context.report_id || context.active_id || null;
|
||||
this.reportCode = params.report_code || context.report_code || null;
|
||||
|
||||
// The control-panel filter components read and write the dates and
|
||||
// comparison from here. Sharing the view through the sub-env is the
|
||||
// same pattern the community stock-valuation report uses to let its
|
||||
// filter component drive the parent controller — it keeps a single
|
||||
// source of truth (these signals) instead of copying values around.
|
||||
useSubEnv({ dnFrView: this });
|
||||
|
||||
onWillStart(() => this.initialise());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set both dates from the control-panel filter and reload.
|
||||
* Kept as one method so the preset buttons and the two date inputs always
|
||||
* move together — a range whose end precedes its start is never sent.
|
||||
*/
|
||||
setDates(from, to) {
|
||||
if (from) this.dateFrom.set(from);
|
||||
if (to) this.dateTo.set(to);
|
||||
if (from && to && from <= to) {
|
||||
return this.load();
|
||||
}
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
setComparison(value) {
|
||||
this.comparison.set(value || "");
|
||||
return this.load();
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------- lifecycle
|
||||
async initialise() {
|
||||
// The localization service is a proxy that throws while the language
|
||||
// parameters are still loading, and the template formats numbers
|
||||
// during its very first render. Waiting here is what keeps
|
||||
// `formatNumber` callable (otherwise: "parameters are not ready yet").
|
||||
await translationIsReady;
|
||||
try {
|
||||
let reportId = this.reportId;
|
||||
if (!reportId && this.reportCode) {
|
||||
const found = await this.orm.searchRead(
|
||||
"dn.fr", [["code", "=", this.reportCode]], ["id"], { limit: 1 }
|
||||
);
|
||||
reportId = found.length ? found[0].id : null;
|
||||
}
|
||||
if (!reportId) {
|
||||
this.state.error = _t("No report configuration found.");
|
||||
this.state.loading = false;
|
||||
return;
|
||||
}
|
||||
this.reportId = reportId;
|
||||
// Pull the default dates declared by the report definition.
|
||||
const defaults = await this.orm.call(
|
||||
"dn.fr", "get_default_dates", [[reportId]]
|
||||
);
|
||||
if (defaults && defaults.date_from) this.dateFrom.set(defaults.date_from);
|
||||
if (defaults && defaults.date_to) this.dateTo.set(defaults.date_to);
|
||||
await this.load();
|
||||
} catch (error) {
|
||||
this.state.error = error.message || String(error);
|
||||
this.state.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
async load() {
|
||||
if (!this.reportId) return;
|
||||
this.state.loading = true;
|
||||
this.state.error = null;
|
||||
try {
|
||||
const result = await rpc("/dn/fr/data", {
|
||||
report_id: this.reportId,
|
||||
options: {
|
||||
date_from: this.dateFrom() || undefined,
|
||||
date_to: this.dateTo() || undefined,
|
||||
comparison: this.comparison() || undefined,
|
||||
unreconciled: this.unreconciled(),
|
||||
include_draft: this.includeDraft(),
|
||||
},
|
||||
});
|
||||
if (!result.ok) {
|
||||
this.state.error = result.error || _t("Computation failed.");
|
||||
this.state.report = null;
|
||||
this.state.lines = [];
|
||||
} else {
|
||||
this.state.report = result.data;
|
||||
this.rebuildLines();
|
||||
}
|
||||
} catch (error) {
|
||||
this.state.error = error.message || String(error);
|
||||
} finally {
|
||||
this.state.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Rebuild the line model array from the payload.
|
||||
*
|
||||
* Called on every successful load. The fold state is reset here on
|
||||
* purpose: the filters changed, so the set of lines changed too, and
|
||||
* keeping stale fold flags would hide rows the user is now looking for.
|
||||
* A report that declares `unfold_all` starts fully open; every other
|
||||
* report starts with its sub-sections collapsed and its top-level
|
||||
* headings visible.
|
||||
*/
|
||||
rebuildLines() {
|
||||
const report = this.state.report;
|
||||
if (!report) {
|
||||
this.state.lines = [];
|
||||
this.applyFoldState({});
|
||||
return;
|
||||
}
|
||||
const lines = buildLines(report.lines || [], report.columns || []);
|
||||
this.state.lines = lines;
|
||||
const unfoldAll = Boolean(report.features && report.features.unfold_all);
|
||||
this.applyFoldState(unfoldAll ? {} : defaultFoldedIds(lines));
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the fold state in place.
|
||||
*
|
||||
* The `folded` object is mutated rather than reassigned: Owl tracks reads
|
||||
* of its keys, not of the property that holds it, so swapping in a fresh
|
||||
* proxy would leave the table body showing the previous fold state.
|
||||
*/
|
||||
applyFoldState(folded) {
|
||||
for (const id of Object.keys(this.folded)) {
|
||||
delete this.folded[id];
|
||||
}
|
||||
for (const [id, value] of Object.entries(folded)) {
|
||||
this.folded[id] = value;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- getters
|
||||
get report() {
|
||||
return this.state.report;
|
||||
}
|
||||
/** Title shown in the control panel, with a sane fallback while loading. */
|
||||
get reportTitle() {
|
||||
return (this.state.report && this.state.report.name) || _t("Financial Reports");
|
||||
}
|
||||
get ready() {
|
||||
return Boolean(this.state.report) && !this.state.loading;
|
||||
}
|
||||
|
||||
/**
|
||||
* UI strings, resolved through `_t` on every read.
|
||||
*
|
||||
* Owl templates can only be translated through `_t(...)` calls, and those
|
||||
* calls have to live in JavaScript — a literal like `<label>Start Date</label>`
|
||||
* inside the template is never picked up by `i18n export` and therefore can
|
||||
* never be translated. Keeping them in a getter (not a module-level const)
|
||||
* avoids freezing the language at import time.
|
||||
*/
|
||||
get labels() {
|
||||
return {
|
||||
exportCsv: _t("Export CSV"),
|
||||
print: _t("Print"),
|
||||
startDate: _t("Start Date"),
|
||||
endDate: _t("End Date"),
|
||||
comparison: _t("Comparison"),
|
||||
noComparison: _t("No comparison"),
|
||||
previousPeriod: _t("Previous Period"),
|
||||
previousYear: _t("Previous Year"),
|
||||
bothPeriods: _t("Previous Period + Previous Year"),
|
||||
apply: _t("Apply"),
|
||||
moreFilters: _t("More Filters"),
|
||||
includeDraft: _t("Include draft entries"),
|
||||
unreconciledOnly: _t("Unreconciled only"),
|
||||
unfoldAll: _t("Expand All"),
|
||||
foldAll: _t("Collapse All"),
|
||||
reset: _t("Reset"),
|
||||
hideFilters: _t("Hide Filters"),
|
||||
computing: _t("Computing…"),
|
||||
noData: _t("No accounting data for this period."),
|
||||
viewDetails: _t("View details"),
|
||||
ledgerHeader: _t("Date / Entry / Label / Partner"),
|
||||
debit: _t("Debit"),
|
||||
credit: _t("Credit"),
|
||||
cumulativeBalance: _t("Cumulative Balance"),
|
||||
accountHeader: _t("Account / Item"),
|
||||
};
|
||||
}
|
||||
|
||||
get columns() {
|
||||
return this.state.report ? this.state.report.columns : [];
|
||||
}
|
||||
get features() {
|
||||
return (this.state.report && this.state.report.features) || {};
|
||||
}
|
||||
|
||||
/**
|
||||
* The rows actually drawn, given the current fold state.
|
||||
*
|
||||
* A getter over the flat array, so Owl tracks `this.folded` and re-renders
|
||||
* the table body when a section opens or closes. `computeVisibleLines` is
|
||||
* a single forward pass — see the note in `dn_fr_model.js` for why that is
|
||||
* enough.
|
||||
*/
|
||||
get visibleLines() {
|
||||
return computeVisibleLines(this.state.lines, this.folded);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------- actions
|
||||
/**
|
||||
* Fold or unfold one section.
|
||||
*
|
||||
* Writing through the proxy is what notifies Owl; the model objects are
|
||||
* untouched, so the rows that stayed visible are not rebuilt.
|
||||
*/
|
||||
onToggle(line) {
|
||||
if (!line.unfoldable) {
|
||||
return;
|
||||
}
|
||||
this.folded[line.id] = !this.folded[line.id];
|
||||
}
|
||||
|
||||
unfoldAll() {
|
||||
this.applyFoldState({});
|
||||
}
|
||||
|
||||
foldAll() {
|
||||
const folded = {};
|
||||
for (const line of this.state.lines) {
|
||||
if (line.unfoldable) {
|
||||
folded[line.id] = true;
|
||||
}
|
||||
}
|
||||
this.applyFoldState(folded);
|
||||
}
|
||||
|
||||
toggleFilters() {
|
||||
this.state.filtersOpen = !this.state.filtersOpen;
|
||||
}
|
||||
|
||||
async resetFilters() {
|
||||
this.comparison.set("");
|
||||
this.unreconciled.set(false);
|
||||
this.includeDraft.set(false);
|
||||
await this.initialise();
|
||||
}
|
||||
|
||||
async exportCsv() {
|
||||
if (!this.state.report) return;
|
||||
const columnKeys = this.columns.map((c) => c.key);
|
||||
const header = [_t("Account / Item"), ...columnKeys.map(
|
||||
(key, index) => this.columns[index].label
|
||||
)].join(",");
|
||||
const escape = (value) => {
|
||||
const text = value === null || value === undefined ? "" : String(value);
|
||||
return `"${text.replace(/"/g, '""')}"`;
|
||||
};
|
||||
const lines = [header];
|
||||
for (const row of this.visibleLines) {
|
||||
const indent = " ".repeat(row.level || 0);
|
||||
const label = escape(`${indent}${row.code ? row.code + " " : ""}${row.label}`);
|
||||
const cells = row.cells.map((cell) => escape(cell.no_format));
|
||||
lines.push([label, ...cells].join(","));
|
||||
}
|
||||
const blob = new Blob(["\uFEFF" + lines.join("\n")], {
|
||||
type: "text/csv;charset=utf-8;",
|
||||
});
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = `${this.state.report.name || "report"}.csv`;
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
async printReport() {
|
||||
window.print();
|
||||
}
|
||||
|
||||
async onAction(line) {
|
||||
if (!line.actionId) return;
|
||||
await this.actionService.doAction(line.actionId);
|
||||
}
|
||||
|
||||
get hasComparison() {
|
||||
return this.columns.length > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Classes for the report table.
|
||||
*
|
||||
* The base is `table table-borderless table-hover mx-auto`, which is the
|
||||
* exact list the enterprise report table carries:
|
||||
*
|
||||
* - `mx-auto` centres the card once the window is wider than the
|
||||
* `min-width: 800px` report. Its containing block is the flex row added
|
||||
* in `dn_fr_view.xml`; without that wrapper `mx-auto` is inert.
|
||||
* - `table-hover` is Bootstrap's row highlight. Our own `tbody tr:hover`
|
||||
* rule is more specific and still wins, so this only keeps the base
|
||||
* contract identical to enterprise.
|
||||
*
|
||||
* `dn_fr_striped` only when there really are comparison columns: the zebra
|
||||
* stripe exists to make pairs of columns separable, so on a single-column
|
||||
* report it would tint half the rows for no reason at all.
|
||||
*/
|
||||
get tableClasses() {
|
||||
const classes = ["table", "table-borderless", "table-hover", "mx-auto", "dn_fr_table"];
|
||||
if (this.hasComparison) {
|
||||
classes.push("dn_fr_striped");
|
||||
}
|
||||
return classes.join(" ");
|
||||
}
|
||||
|
||||
/** True when the report's only meaningful output is journal item detail. */
|
||||
get isLedgerReport() {
|
||||
return this.state.lines.some((line) => line.detail);
|
||||
}
|
||||
}
|
||||
|
||||
registry.category("actions").add("dn_fr_view", DnFrView);
|
||||
529
accountant_cn/static/src/js/dn_fr_view.scss
Normal file
529
accountant_cn/static/src/js/dn_fr_view.scss
Normal file
@@ -0,0 +1,529 @@
|
||||
/* DN Financial Reports — report page styling.
|
||||
*
|
||||
* The visual target is the Odoo Enterprise report page, whose stylesheet lives
|
||||
* in `account_reports/static/src/components/account_report/account_report.scss`.
|
||||
* Odoo Community has no equivalent, so the look has to be reproduced here —
|
||||
* but reproduced *by class name*, not by eye. Every selector below uses the
|
||||
* same vocabulary enterprise uses (`line_name`, `line_cell`, `line_level_N`,
|
||||
* `total`, `unfolded`, `btn_foldable`, `btn_action`, `muted`, `line_cell_odd`),
|
||||
* so the numbers in this file can be checked one-to-one against that file.
|
||||
*
|
||||
* The geometry, and why each constant is what it is:
|
||||
*
|
||||
* 1. **The table is a card, not a grid.** `margin: 24px`, `padding: 24px`,
|
||||
* `1px` border, `0.25rem` radius, `min-width: 800px`, `font-size: 0.8rem`.
|
||||
* Without the padding the figures touch the border; without the radius the
|
||||
* page looks like a spreadsheet dump rather than a report.
|
||||
* 2. **`border-collapse: separate; border-spacing: 0`.** Required — the card
|
||||
* padding only applies to cells under `separate`, and `spacing: 0` removes
|
||||
* the gaps that `separate` normally introduces.
|
||||
* 3. **Numeric cells carry an extra 20px right gutter**
|
||||
* (`padding-right: calc(20px + 0.75rem)`). That 20px is the room the
|
||||
* hover-only row action needs, and it is `!important` in enterprise
|
||||
* because the Bootstrap `td` rule is more specific.
|
||||
* 4. **Row height is computed**:
|
||||
* `0.8rem * body-line-height + 0.5rem + 5px` (two paddings plus the
|
||||
* border), which is what makes a 300-row report read as evenly spaced
|
||||
* lines instead of variable ones.
|
||||
* 5. **`line_level_0` is a filled band** (`$o-gray-300`) with no bottom
|
||||
* border; deeper levels indent 8px per level. Level 1 is special-cased to
|
||||
* the same 20px gutter as level 0 so the first nested level sits under its
|
||||
* heading rather than past it.
|
||||
* 6. **Bold means total.** `total` and `unfolded` are both bold; `unfolded`
|
||||
* additionally darkens its bottom rule, which is what signals "this
|
||||
* section is open" without an icon.
|
||||
* 7. **Row actions are invisible until hover**, driven by a CSS custom
|
||||
* property (`--row-action-opacity`) so one `:hover` rule can reveal every
|
||||
* affordance in the row at once.
|
||||
*
|
||||
* Two constraints learned the hard way:
|
||||
* - Column widths must come from `table-layout: auto` plus a 100% label
|
||||
* header and 1% amount headers. `fixed` cannot express "label absorbs the
|
||||
* slack, amounts take their content width" — a column with no width under
|
||||
* `fixed` swallows everything.
|
||||
* - There must be **no `<colgroup>`**: `<col>` widths override the header
|
||||
* hints and the amounts drift to the far right.
|
||||
*/
|
||||
|
||||
.dn_fr_view {
|
||||
/* ---- control panel ------------------------------------------------
|
||||
* The panel itself is Odoo's own <ControlPanel> component, so its layout,
|
||||
* ordering and responsive rules come from web core. Only the two report
|
||||
* specifics below are ours, both copied from enterprise's account_report:
|
||||
* the breadcrumbs may not shrink, and the control-panel dropdown items
|
||||
* carry flush btn-link children. */
|
||||
.o_control_panel_main_buttons {
|
||||
.dropdown-item {
|
||||
padding: 0;
|
||||
.btn-link {
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
padding: 3px 20px;
|
||||
border-radius: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.o_control_panel_breadcrumbs {
|
||||
min-width: fit-content;
|
||||
}
|
||||
|
||||
/* Enterprise filter dropdowns: an underlined name on the left, the value
|
||||
* input centred, and prev/next arrows that only darken on hover. These
|
||||
* selectors are the same as account_reports/filters/filters.scss so the
|
||||
* two dropdown buttons read identically. */
|
||||
.account_report_filter {
|
||||
&.date {
|
||||
.date_filter {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
&.date, &.comparison {
|
||||
.dropdown-item.date {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dn_fr_advfilters {
|
||||
border-top: 1px solid var(--border-color, #dee2e6);
|
||||
}
|
||||
|
||||
/* ---- body --------------------------------------------------------- */
|
||||
.dn_fr_content {
|
||||
min-height: 0; // lets overflow-auto actually clip inside the flex column
|
||||
padding-bottom: 40px; // same breathing room as the enterprise scroll container
|
||||
background-color: var(--bs-body-bg, #fff);
|
||||
}
|
||||
|
||||
/* The horizontal scroller. `margin-inline: 0 !important` mirrors
|
||||
* enterprise's own override: the class is also styled by web core, and the
|
||||
* core rule would otherwise reintroduce an inline margin on the card. */
|
||||
.o_account_report_scroll_container {
|
||||
margin-inline: 0 !important;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
/* =================================================================
|
||||
* Table — the card
|
||||
* ================================================================= */
|
||||
.dn_fr_table {
|
||||
background-color: var(--bs-body-bg, #fff);
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-size: 0.8rem;
|
||||
margin: 24px;
|
||||
padding: 24px;
|
||||
width: auto;
|
||||
min-width: 800px;
|
||||
border: 1px solid #dee2e6; // $o-gray-300
|
||||
border-radius: 0.25rem;
|
||||
overflow-anchor: none;
|
||||
|
||||
table-layout: auto;
|
||||
font-variant-numeric: tabular-nums;
|
||||
|
||||
// Room for the hover-only action, revealed by `--row-action-opacity`
|
||||
// on row hover. Declared here (not on the button) so every affordance
|
||||
// in the row can read the same value.
|
||||
--row-action-color: #dee2e6;
|
||||
--row-action-opacity: 0;
|
||||
--row-muted-color: #dee2e6;
|
||||
|
||||
td,
|
||||
th {
|
||||
// `!important` because Bootstrap's `> :not(caption) > * > *`
|
||||
// selector is more specific than any plain `td` rule here.
|
||||
padding: 0.25rem 0.75rem !important;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* ---- header ---- */
|
||||
/* Column titles are dark, not muted.
|
||||
*
|
||||
* Enterprise sets `color: $o-gray-300` on `> tr:first-child > th`, but
|
||||
* its first header row is `column_companies_row` — the list of company
|
||||
* names, which is empty on a single-company database. The row that
|
||||
* actually carries the column titles is `column_headers_row`, and it
|
||||
* inherits the normal text colour.
|
||||
*
|
||||
* Copying that rule onto our only header row painted the column titles
|
||||
* in #dee2e6 on white — a 1.3:1 contrast ratio, which is why the header
|
||||
* looked washed out and the report read differently from enterprise.
|
||||
* $o-gray-700 gives 8.2:1 and matches what enterprise actually shows. */
|
||||
> thead > tr > th {
|
||||
color: #495057; // $o-gray-700
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
|
||||
&.dn_fr_amount_col {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
// The extra 20px right gutter, so a header never sits flush with
|
||||
// the figures beneath it.
|
||||
&.numeric-header {
|
||||
padding-right: calc(20px + 0.75rem) !important;
|
||||
}
|
||||
}
|
||||
|
||||
/* Amount headers are centred and share the column rules of the figures
|
||||
* below them. No left border: enterprise only draws header cell borders
|
||||
* between *stacked* header rows (`tr:not(:last-child)`), which never
|
||||
* matches a single-row header — adding them would put three vertical
|
||||
* rules through a header that has none in enterprise. */
|
||||
> thead > tr > th.column_header {
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
> thead.sticky {
|
||||
background-color: var(--bs-body-bg, #fff);
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 999;
|
||||
|
||||
> tr > th {
|
||||
background-color: var(--bs-body-bg, #fff);
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
}
|
||||
}
|
||||
|
||||
// Width hints, see the file header.
|
||||
.dn_fr_label_col {
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
color: #495057; // $o-gray-700, same as the amount headers
|
||||
}
|
||||
|
||||
// The floor matters on the ledger report, whose four short headers
|
||||
// ("Debit" / "Credit" / "Cumulative Balance") would otherwise collapse
|
||||
// to ~61px each. 8rem = 128px keeps the figures legible; the
|
||||
// three-column reports are unaffected because their content is wider.
|
||||
.dn_fr_amount_col {
|
||||
width: 1%;
|
||||
min-width: 8rem;
|
||||
}
|
||||
|
||||
// Second line under a column title: the period the column covers.
|
||||
.dn_fr_subhead {
|
||||
font-size: 0.7rem;
|
||||
font-weight: 400;
|
||||
color: #adb5bd; // $o-gray-500
|
||||
}
|
||||
|
||||
/* ---- body ---- */
|
||||
> tbody > tr {
|
||||
// 1.5 line-height × 0.8rem + 0.25rem × 2 padding + 5px border
|
||||
height: calc(0.8rem * var(--body-line-height) + 0.5rem + 5px);
|
||||
}
|
||||
|
||||
> tbody > tr > td {
|
||||
border-bottom: 1px solid #e9ecef; // $o-gray-200
|
||||
}
|
||||
|
||||
/* The spacer above every level-0 line (see dn_fr_view.xml).
|
||||
* It holds one cell so the browser keeps the row; the cell itself must
|
||||
* contribute no border, no padding and no background, otherwise the
|
||||
* gap reads as a thin line instead of empty space. */
|
||||
> tbody > tr.empty {
|
||||
height: calc(0.8rem * var(--body-line-height, 1.5) + 0.5rem + 5px);
|
||||
|
||||
> td {
|
||||
padding: 0 !important;
|
||||
border: 0 !important;
|
||||
background: transparent !important;
|
||||
height: 0;
|
||||
line-height: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* `table-hover` (added so the base class list matches enterprise) tints
|
||||
* a hovered row through `--bs-table-hover-bg`, applied as an
|
||||
* `inset 0 0 0 9999px` box-shadow on each cell. That shadow paints
|
||||
* *over* the background our own `tr:hover` rule sets, so the two would
|
||||
* fight. Neutralising the variable hands hover back to the single rule
|
||||
* below, which is the one that also flips `--row-action-opacity`. */
|
||||
> tbody > tr {
|
||||
--bs-table-hover-bg: transparent;
|
||||
}
|
||||
|
||||
/* =============================================================
|
||||
* Line name column
|
||||
* ============================================================= */
|
||||
.line_name {
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
|
||||
sup {
|
||||
top: auto;
|
||||
}
|
||||
|
||||
&.unfoldable:hover {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
// Long account labels wrap rather than dragging the column wider,
|
||||
// but only when they are genuinely long: `nowrap` above is what
|
||||
// keeps short labels on one line.
|
||||
.dn_fr_wrap & {
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
}
|
||||
|
||||
/* =============================================================
|
||||
* Amount cells
|
||||
* ============================================================= */
|
||||
.line_cell {
|
||||
vertical-align: middle;
|
||||
white-space: nowrap;
|
||||
|
||||
&.date {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
&.numeric {
|
||||
text-align: end;
|
||||
padding-right: calc(20px + 0.75rem) !important;
|
||||
}
|
||||
|
||||
a.cursor-pointer {
|
||||
color: inherit;
|
||||
}
|
||||
}
|
||||
|
||||
/* Zebra stripe on every second amount column: this is what makes a
|
||||
* comparison report read as pairs of columns instead of one wide band
|
||||
* of numbers. A level-0 band needs a darker stripe to stay visible
|
||||
* against its own fill. */
|
||||
&.dn_fr_striped > tbody > tr > td.line_cell_odd {
|
||||
background: #f8f9fa; // $o-gray-100
|
||||
}
|
||||
|
||||
&.dn_fr_striped > tbody > tr.line_level_0 > td.line_cell_odd {
|
||||
background: #ced4da; // $o-gray-400, darker than the band
|
||||
}
|
||||
|
||||
/* =============================================================
|
||||
* Hierarchy
|
||||
* ============================================================= */
|
||||
|
||||
/* Level 0 is a filled band: it groups everything below it, so it must
|
||||
* not have its own bottom border — the fill does the separating. */
|
||||
.line_level_0 {
|
||||
color: #495057; // $o-gray-700
|
||||
font-weight: bold;
|
||||
|
||||
> td {
|
||||
border-bottom: 0 !important;
|
||||
background-color: #dee2e6; // $o-gray-300
|
||||
}
|
||||
|
||||
.muted {
|
||||
color: #ced4da !important; // $o-gray-400
|
||||
}
|
||||
}
|
||||
|
||||
/* Level 1 sits at the same gutter as level 0 so the first nested level
|
||||
* lines up under its heading instead of past it. A foldable cell drops
|
||||
* back to the plain 0.75rem padding because its own arrow already
|
||||
* provides the indent. */
|
||||
.line_level_1 > td:nth-child(1) {
|
||||
padding-left: calc(20px + 0.75rem) !important;
|
||||
|
||||
&.unfoldable {
|
||||
padding-left: 0.75rem !important;
|
||||
}
|
||||
}
|
||||
|
||||
// Levels 2..16: 8px per level on top of the 20px gutter. Past 16 the
|
||||
// indentation stops growing — deep enough that any further shift would
|
||||
// leave no room for the label on a normal window.
|
||||
@for $i from 2 through 16 {
|
||||
.line_level_#{$i} {
|
||||
$indentation: ($i - 1) * 8px;
|
||||
|
||||
> td:nth-child(1) {
|
||||
color: #495057; // $o-gray-700
|
||||
padding-left: calc(#{$indentation} + 20px + 0.75rem) !important;
|
||||
|
||||
&.unfoldable {
|
||||
padding-left: calc(#{$indentation} + 0.75rem) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* =============================================================
|
||||
* Row states
|
||||
* ============================================================= */
|
||||
> tbody > tr {
|
||||
&.unfolded,
|
||||
&.total {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
// An open section gets a darker rule under it: that line is the
|
||||
// only signal that the rows below belong to it.
|
||||
&.unfolded {
|
||||
--row-action-opacity: 1;
|
||||
|
||||
> td {
|
||||
border-bottom: 1px solid #dee2e6;
|
||||
}
|
||||
}
|
||||
|
||||
// Journal-item detail rows are secondary information: smaller,
|
||||
// greyer, and without the hover lift of a summary row.
|
||||
&.detail > td {
|
||||
color: #6c757d;
|
||||
font-size: 0.75rem;
|
||||
}
|
||||
|
||||
.btn_action,
|
||||
.btn_foldable {
|
||||
color: var(--row-action-color);
|
||||
}
|
||||
|
||||
.btn_action {
|
||||
opacity: var(--row-action-opacity);
|
||||
}
|
||||
|
||||
&:hover {
|
||||
--row-action-opacity: 1;
|
||||
--row-action-color: #017e84; // $o-enterprise-action-color
|
||||
--row-muted-color: #343a40;
|
||||
|
||||
> td {
|
||||
background-color: #f8f9fa; // $o-gray-100
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* =============================================================
|
||||
* Buttons
|
||||
* ============================================================= */
|
||||
.btn_foldable,
|
||||
.btn_action {
|
||||
border: none;
|
||||
color: #dee2e6; // $o-gray-300
|
||||
font-size: inherit;
|
||||
font-weight: normal;
|
||||
padding: 0 !important;
|
||||
text-align: center;
|
||||
width: 20px;
|
||||
white-space: nowrap;
|
||||
|
||||
&:hover {
|
||||
color: #017e84 !important;
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
// The fold arrow is slightly darker than a hover-only action: it is
|
||||
// the primary way to navigate a hierarchical report, so it must be
|
||||
// visible without hovering.
|
||||
.btn_foldable {
|
||||
color: #adb5bd; // $o-gray-500
|
||||
}
|
||||
|
||||
// The drill-down button is a bordered pill that fades in on hover, not
|
||||
// a bare icon: it sits inline with the label and would otherwise read
|
||||
// as part of the text.
|
||||
.btn_action {
|
||||
opacity: 0;
|
||||
background-color: var(--bs-body-bg, #fff);
|
||||
color: #6c757d;
|
||||
width: auto;
|
||||
padding: 0 0.25rem !important;
|
||||
margin: 0 0.25rem;
|
||||
border: 1px solid #dee2e6 !important;
|
||||
border-radius: 0.25rem;
|
||||
line-height: 1.4;
|
||||
font-size: 0.7rem;
|
||||
}
|
||||
|
||||
/* Links inside the report use the enterprise action colour. */
|
||||
a {
|
||||
color: #017e84;
|
||||
}
|
||||
|
||||
@media print {
|
||||
border: 0;
|
||||
padding: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Muted figures: a zero in a comparison column. Greyed rather than
|
||||
* hidden so the column keeps its shape. */
|
||||
.muted {
|
||||
color: var(--row-muted-color, #dee2e6);
|
||||
}
|
||||
}
|
||||
|
||||
/* =====================================================================
|
||||
* Print
|
||||
* The card chrome and the interactive controls are pointless on paper;
|
||||
* the figures are not.
|
||||
* ===================================================================== */
|
||||
@media print {
|
||||
.dn_fr_view {
|
||||
.o_control_panel,
|
||||
.dn_fr_advfilters {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.dn_fr_content {
|
||||
overflow: visible !important;
|
||||
padding-bottom: 0;
|
||||
}
|
||||
|
||||
.dn_fr_table {
|
||||
font-size: 10pt;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
min-width: 0;
|
||||
|
||||
> thead.sticky {
|
||||
position: static;
|
||||
}
|
||||
|
||||
.btn_foldable,
|
||||
.btn_action {
|
||||
display: none !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* =====================================================================
|
||||
* Narrow screens
|
||||
* The amounts keep a floor so figures stay legible, the label column keeps
|
||||
* a floor of its own so it cannot be squeezed away, and the card margins
|
||||
* shrink so the table still fits.
|
||||
* ===================================================================== */
|
||||
@media (max-width: 900px) {
|
||||
.dn_fr_view .dn_fr_table {
|
||||
margin: 8px;
|
||||
padding: 8px;
|
||||
min-width: 0;
|
||||
|
||||
.dn_fr_label_col {
|
||||
width: auto;
|
||||
min-width: 14rem;
|
||||
}
|
||||
|
||||
.dn_fr_amount_col {
|
||||
width: 1%;
|
||||
min-width: 6rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
132
accountant_cn/static/src/js/dn_fr_view.xml
Normal file
132
accountant_cn/static/src/js/dn_fr_view.xml
Normal file
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
<t t-name="dn_financial_reports.DnFrView">
|
||||
<!-- The enterprise report page is an `o_action account_report` whose
|
||||
first child is Odoo's own <ControlPanel>, filled through named
|
||||
slots. Reproducing that structure — rather than a hand-stacked
|
||||
div — is what makes the header geometry match: Owl's ControlPanel
|
||||
owns the breadcrumbs row, the buttons row, the filters row and the
|
||||
pager/navigation row, with the exact flex ordering and responsive
|
||||
breakpoints the rest of Odoo uses. -->
|
||||
<div class="o_action account_report dn_fr_view d-flex flex-column h-100">
|
||||
<ControlPanel display="{ buttons: true, actions: true }">
|
||||
<t t-set-slot="control-panel-buttons">
|
||||
<button class="btn btn-primary text-nowrap"
|
||||
t-on-click="() => this.load()"
|
||||
t-att-disabled="this.state.loading">
|
||||
<t t-out="this.labels.apply"/>
|
||||
</button>
|
||||
</t>
|
||||
|
||||
<t t-set-slot="control-panel-additional-actions">
|
||||
<Dropdown>
|
||||
<button class="btn p-0 ms-1 border-0" title="Options">
|
||||
<i class="oi oi-fw oi-filled" data-icon="settings"/>
|
||||
</button>
|
||||
<t t-set-slot="content">
|
||||
<DropdownItem onSelected="() => this.exportCsv()"
|
||||
t-if="this.features.export">
|
||||
<t t-out="this.labels.exportCsv"/>
|
||||
</DropdownItem>
|
||||
<DropdownItem onSelected="() => this.printReport()">
|
||||
<t t-out="this.labels.print"/>
|
||||
</DropdownItem>
|
||||
<DropdownItem onSelected="() => this.unfoldAll()">
|
||||
<t t-out="this.labels.unfoldAll"/>
|
||||
</DropdownItem>
|
||||
<DropdownItem onSelected="() => this.foldAll()">
|
||||
<t t-out="this.labels.foldAll"/>
|
||||
</DropdownItem>
|
||||
</t>
|
||||
</Dropdown>
|
||||
</t>
|
||||
|
||||
<t t-set-slot="control-panel-actions">
|
||||
<div class="d-flex gap-1 flex-wrap" id="reportFilterCollapse">
|
||||
<DnFrDateFilter t-if="this.ready"/>
|
||||
<DnFrComparisonFilter t-if="this.ready and this.features.comparison"/>
|
||||
<!-- "More Filters" opens the extra-options row, the same
|
||||
role enterprise's extra-options dropdown plays. -->
|
||||
<button class="btn btn-secondary" type="button"
|
||||
t-on-click="() => this.toggleFilters()">
|
||||
<i class="oi oi-filled me-1" data-icon="tune"/>
|
||||
<t t-out="this.labels.moreFilters"/>
|
||||
</button>
|
||||
</div>
|
||||
</t>
|
||||
</ControlPanel>
|
||||
|
||||
<!-- Expanded "more filters" row: the switches that would clutter
|
||||
the main filter line. Kept outside the ControlPanel slots and
|
||||
styled to sit flush under it, like enterprise's extra-options
|
||||
dropdown content. -->
|
||||
<div t-if="this.state.filtersOpen"
|
||||
class="dn_fr_advfilters d-flex flex-wrap gap-3 align-items-center px-3 py-2">
|
||||
<div t-if="this.features.draft_entries" class="form-check form-switch mb-0">
|
||||
<input class="form-check-input" type="checkbox" id="dn_fr_draft"
|
||||
t-model="this.includeDraft"/>
|
||||
<label class="form-check-label small" for="dn_fr_draft"
|
||||
t-out="this.labels.includeDraft"/>
|
||||
</div>
|
||||
<div t-if="this.features.unreconciled_only" class="form-check form-switch mb-0">
|
||||
<input class="form-check-input" type="checkbox" id="dn_fr_unrec"
|
||||
t-model="this.unreconciled"/>
|
||||
<label class="form-check-label small" for="dn_fr_unrec"
|
||||
t-out="this.labels.unreconciledOnly"/>
|
||||
</div>
|
||||
<button class="btn btn-link btn-sm" t-on-click="() => this.toggleFilters()"
|
||||
t-out="this.labels.hideFilters"/>
|
||||
<button class="btn btn-link btn-sm" t-on-click="() => this.resetFilters()"
|
||||
t-out="this.labels.reset"/>
|
||||
</div>
|
||||
|
||||
<!-- ===================================================== body -->
|
||||
<div class="dn_fr_content o_content flex-grow-1 overflow-auto">
|
||||
<div t-if="this.state.loading" class="alert alert-info m-3">
|
||||
<i class="fa fa-circle-o-notch fa-spin me-2"/><t t-out="this.labels.computing"/>
|
||||
</div>
|
||||
<div t-if="this.state.error" class="alert alert-danger m-3" t-out="this.state.error"/>
|
||||
|
||||
<!-- Two nested wrappers, the same pair the enterprise page uses:
|
||||
the outer one is the horizontal scroller, the inner one is
|
||||
the flex row the card is centred in. `mx-auto` on the table
|
||||
only works because the inner wrapper is a flex container. -->
|
||||
<div t-if="this.ready"
|
||||
class="mx-auto o_account_report_scroll_container overflow-x-auto">
|
||||
<div class="d-flex align-items-start">
|
||||
<table t-att-class="this.tableClasses">
|
||||
<DnFrHeader columns="this.columns"
|
||||
labels="this.labels"
|
||||
isLedger="this.isLedgerReport"/>
|
||||
<tbody>
|
||||
<!-- One flat walk over `visibleLines`, which is
|
||||
already filtered by the fold map. -->
|
||||
<t t-foreach="this.visibleLines" t-as="line" t-key="line.id">
|
||||
<!-- Enterprise inserts an empty spacer above
|
||||
every level-0 line so adjacent bands do
|
||||
not read as one block. The cell keeps the
|
||||
browser from collapsing the empty row. -->
|
||||
<tr t-if="line.level === 0" class="empty">
|
||||
<td t-att-colspan="this.columns.length + 1"/>
|
||||
</tr>
|
||||
<DnFrLine line="line"
|
||||
labels="this.labels"
|
||||
unfolded="!this.folded[line.id]"
|
||||
isLedger="this.isLedgerReport"
|
||||
onToggle="(l) => this.onToggle(l)"
|
||||
onAction="(l) => this.onAction(l)"/>
|
||||
</t>
|
||||
<tr t-if="!this.visibleLines.length">
|
||||
<td t-att-colspan="this.columns.length + 1"
|
||||
class="text-center text-muted py-5">
|
||||
<t t-out="this.labels.noData"/>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
187
accountant_cn/static/src/js/dn_report_view.js
Normal file
187
accountant_cn/static/src/js/dn_report_view.js
Normal file
@@ -0,0 +1,187 @@
|
||||
/** @odoo-module **/
|
||||
import { registry } from "@web/core/registry";
|
||||
import { Component, onWillStart, proxy, signal, t, useProps } from "@odoo/owl";
|
||||
import { rpc } from "@web/core/network/rpc";
|
||||
import { useService } from "@web/core/utils/hooks";
|
||||
import { _t, translationIsReady } from "@web/core/l10n/translation";
|
||||
import { formatFloat } from "@web/views/fields/formatters";
|
||||
|
||||
/**
|
||||
* DN Report viewer.
|
||||
*
|
||||
* Renders the payload produced by the self-implemented engine
|
||||
* (`dn.report.get_report_data`) as a hierarchical, collapsible table.
|
||||
* Everything the UI shows comes from the server payload, so adding a new
|
||||
* report is purely a matter of defining data records — no JS change needed.
|
||||
*/
|
||||
export class DnReportView extends Component {
|
||||
static template = "dn_account_reports_core.DnReportView";
|
||||
|
||||
// Owl 3: props are declared through useProps, not a static `props`.
|
||||
props = useProps({
|
||||
action: t.object().optional(),
|
||||
});
|
||||
|
||||
setup() {
|
||||
this.orm = useService("orm");
|
||||
this.notification = useService("notification");
|
||||
// Numbers go through `formatFloat`, which applies the user's own
|
||||
// language parameters (separators, decimal point) instead of a
|
||||
// hard-coded locale.
|
||||
// `t-model` in Owl 3 requires a signal (it needs a `.set` method), so the
|
||||
// two date inputs are bound to signals rather than to `proxy` fields.
|
||||
// Default range: January 1st of the current year -> today. Financial
|
||||
// statements are normally read on a year-to-date basis.
|
||||
const today = new Date();
|
||||
const pad = (n) => String(n).padStart(2, "0");
|
||||
const iso = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||
this.dateFrom = signal(iso(new Date(today.getFullYear(), 0, 1)));
|
||||
this.dateTo = signal(iso(today));
|
||||
this.state = proxy({
|
||||
loading: true,
|
||||
report: null,
|
||||
error: null,
|
||||
folded: {},
|
||||
});
|
||||
// A report can be reached two ways: from the menu (the action carries
|
||||
// `params.report_code`), or from the "Preview Report" button on a report
|
||||
// form, where the current record id travels in the action context.
|
||||
const action = this.props.action || {};
|
||||
const params = action.params || {};
|
||||
const context = action.context || {};
|
||||
this.reportCode = params.report_code || context.report_code || null;
|
||||
this.reportId =
|
||||
params.report_id || context.report_id || context.active_id || null;
|
||||
onWillStart(() => this.load());
|
||||
}
|
||||
|
||||
get headers() {
|
||||
return this.state.report ? this.state.report.headers : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* UI strings. They live here rather than in the template because terms are
|
||||
* extracted from `_t(...)` calls in JavaScript; a literal inside an Owl
|
||||
* template never reaches the translation file. Going through a getter
|
||||
* means the labels follow the user's language at render time.
|
||||
*/
|
||||
get labels() {
|
||||
return {
|
||||
title: _t("Financial Report"),
|
||||
start: _t("Start"),
|
||||
end: _t("End"),
|
||||
apply: _t("Apply"),
|
||||
computing: _t("Computing…"),
|
||||
account: _t("Account / Item"),
|
||||
empty: _t("No data for this period."),
|
||||
};
|
||||
}
|
||||
|
||||
/** True while a report payload has been received and no request is pending. */
|
||||
get ready() {
|
||||
return Boolean(this.state.report) && !this.state.loading;
|
||||
}
|
||||
|
||||
async load() {
|
||||
// Wait for the language parameters before rendering: the localization
|
||||
// proxy throws on any read until they arrive, and the first render
|
||||
// already formats numbers through `formatNumber`.
|
||||
await translationIsReady;
|
||||
this.state.loading = true;
|
||||
this.state.error = null;
|
||||
try {
|
||||
let reportId = this.reportId;
|
||||
if (!reportId && this.reportCode) {
|
||||
const found = await this.orm.searchRead(
|
||||
"dn.report",
|
||||
[["code", "=", this.reportCode]],
|
||||
["id"],
|
||||
{ limit: 1 }
|
||||
);
|
||||
reportId = found.length ? found[0].id : false;
|
||||
}
|
||||
if (!reportId) {
|
||||
this.state.error = _t("No report configuration found (invalid report_code).");
|
||||
return;
|
||||
}
|
||||
const result = await rpc("/dn/report/data", {
|
||||
report_id: reportId,
|
||||
options: {
|
||||
date_from: this.dateFrom() || undefined,
|
||||
date_to: this.dateTo() || undefined,
|
||||
},
|
||||
});
|
||||
if (!result.ok) {
|
||||
this.state.error = result.error || _t("Unknown error");
|
||||
} else {
|
||||
this.state.report = result.data;
|
||||
}
|
||||
} catch (error) {
|
||||
this.state.error = error.message || String(error);
|
||||
} finally {
|
||||
this.state.loading = false;
|
||||
}
|
||||
}
|
||||
|
||||
toggleLine(lineId) {
|
||||
this.state.folded[lineId] = !this.state.folded[lineId];
|
||||
}
|
||||
|
||||
isFolded(line) {
|
||||
return Boolean(this.state.folded[line.id]);
|
||||
}
|
||||
|
||||
cellValue(line, index) {
|
||||
const value = (line.values || {})[`c${index}`];
|
||||
return this.fmt(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Mirror the enterprise class vocabulary so the SCSS can target the same
|
||||
* concepts: `line_level_N` is the level-0 filled band and the indentation
|
||||
* hook, `dn_report_total` is a bold summary.
|
||||
*/
|
||||
rowClass(line) {
|
||||
const classes = [`line_level_${line.level || 0}`];
|
||||
if (line.is_total) classes.push("dn_report_total");
|
||||
return classes.join(" ");
|
||||
}
|
||||
|
||||
/**
|
||||
* Enterprise indents 8px per level on top of the 20px gutter that the
|
||||
* label cell already carries. Level 0 gets no indent so its filled band
|
||||
* starts flush with the card padding.
|
||||
*/
|
||||
indentStyle(line) {
|
||||
const level = line.level || 0;
|
||||
if (!level) return "";
|
||||
return `padding-left: calc(${level * 8}px + 20px + 0.75rem)`;
|
||||
}
|
||||
|
||||
fmt(value) {
|
||||
if (value === null || value === undefined || value === "") {
|
||||
return "";
|
||||
}
|
||||
if (typeof value !== "number") {
|
||||
return value;
|
||||
}
|
||||
return formatFloat(value, { digits: [16, 2] });
|
||||
}
|
||||
|
||||
/** Flatten the line tree into visible rows, honouring the fold state. */
|
||||
get visibleRows() {
|
||||
const rows = [];
|
||||
const walk = (lines, depth) => {
|
||||
for (const line of lines) {
|
||||
rows.push({ ...line, level: depth });
|
||||
if (line.children && line.children.length && !this.isFolded(line)) {
|
||||
walk(line.children, depth + 1);
|
||||
}
|
||||
}
|
||||
};
|
||||
walk(this.state.report ? this.state.report.lines : [], 0);
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
registry.category("actions").add("dn_report_view", DnReportView);
|
||||
212
accountant_cn/static/src/js/dn_report_view.scss
Normal file
212
accountant_cn/static/src/js/dn_report_view.scss
Normal file
@@ -0,0 +1,212 @@
|
||||
/* DN Financial Reports (Core) — report view styling.
|
||||
*
|
||||
* Same visual target as `dn_financial_reports`: Odoo Enterprise's
|
||||
* `account_reports` report card. See `dn_fr_view.scss` for the annotated list
|
||||
* of enterprise traits; the geometry constants are identical so the two report
|
||||
* engines look like one product.
|
||||
*
|
||||
* The column-width approach is also shared: `table-layout: auto` with a 100%
|
||||
* label header and 1% amount headers. `fixed` was measured and rejected — an
|
||||
* un-sized column under `fixed` takes the whole remainder (1120px label /
|
||||
* 144px amount), which is exactly the broken look this replaces.
|
||||
*/
|
||||
|
||||
.dn_report_view {
|
||||
.o_control_panel {
|
||||
flex: 0 0 auto;
|
||||
border-bottom: 1px solid var(--border-color, #dee2e6);
|
||||
}
|
||||
|
||||
.o_control_panel_breadcrumbs h3 {
|
||||
font-size: 1.25rem;
|
||||
line-height: 1.3;
|
||||
}
|
||||
|
||||
.dn_report_toolbar {
|
||||
margin: 0;
|
||||
|
||||
.dn_report_field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 8.5rem;
|
||||
|
||||
input {
|
||||
min-width: 8.5rem;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 0.75rem;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.02em;
|
||||
color: var(--o-gray-600, #6c757d);
|
||||
margin-bottom: 0.125rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.dn_report_content {
|
||||
min-height: 0; // lets overflow-auto clip inside the flex column
|
||||
background-color: var(--o-view-background-color, #fff);
|
||||
}
|
||||
|
||||
/* ---- table: enterprise "card" ------------------------------------- */
|
||||
.dn_report_table {
|
||||
background-color: var(--o-view-background-color, #fff);
|
||||
border-collapse: separate;
|
||||
border-spacing: 0;
|
||||
font-size: 0.8rem;
|
||||
margin: 24px;
|
||||
padding: 24px;
|
||||
width: auto;
|
||||
min-width: 800px;
|
||||
border: 1px solid var(--o-gray-300, #dee2e6);
|
||||
border-radius: 0.25rem;
|
||||
overflow-anchor: none;
|
||||
|
||||
table-layout: auto;
|
||||
font-variant-numeric: tabular-nums;
|
||||
|
||||
.dn_report_label_col {
|
||||
width: 100%;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
.dn_report_amount_col {
|
||||
width: 1%;
|
||||
min-width: 8rem;
|
||||
}
|
||||
|
||||
td,
|
||||
th {
|
||||
padding: 0.25rem 0.75rem;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
/* ---- header ---- */
|
||||
> thead > tr > th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 2;
|
||||
background-color: var(--o-view-background-color, #fff);
|
||||
border-bottom: 2px solid var(--o-gray-300, #dee2e6);
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
color: var(--o-main-text-color, #212529);
|
||||
|
||||
&.dn_report_amount_col {
|
||||
padding-right: calc(20px + 0.75rem);
|
||||
text-align: end;
|
||||
}
|
||||
}
|
||||
|
||||
/* ---- body ---- */
|
||||
> tbody > tr {
|
||||
height: calc(0.8rem * var(--body-line-height) + 0.5rem + 5px);
|
||||
|
||||
> td {
|
||||
border-bottom: 1px solid var(--o-gray-200, #e9ecef);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
&:last-child > td {
|
||||
border-bottom: 0;
|
||||
}
|
||||
}
|
||||
|
||||
tbody td.dn_report_cell_label {
|
||||
white-space: normal;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
|
||||
tbody td.text-end {
|
||||
padding-right: calc(20px + 0.75rem);
|
||||
}
|
||||
|
||||
/* Level-0 rows are a filled band, like the enterprise `line_level_0`. */
|
||||
tr.line_level_0 > td {
|
||||
background-color: var(--o-gray-300, #dee2e6);
|
||||
border-bottom: 0;
|
||||
font-weight: 700;
|
||||
color: var(--o-gray-700, #495057);
|
||||
}
|
||||
|
||||
/* A level-0 line that is also a total must keep the darker band: the
|
||||
enterprise hierarchy is read top-down by shade, and collapsing it
|
||||
into the total colour makes every level look the same. */
|
||||
tr.dn_report_total:not(.line_level_0) > td {
|
||||
font-weight: 700;
|
||||
background-color: var(--o-gray-100, #f8f9fa);
|
||||
border-top: 1px solid var(--o-gray-300, #dee2e6);
|
||||
}
|
||||
|
||||
> tbody > tr:not(.line_level_0):hover > td {
|
||||
background-color: var(--o-gray-100, #f8f9fa);
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.dn_report_toggle_wrap {
|
||||
display: inline-block;
|
||||
width: 1.25rem;
|
||||
}
|
||||
|
||||
.dn_report_toggle {
|
||||
color: var(--o-gray-500, #adb5bd);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: var(--o-enterprise-action-color, #017e84);
|
||||
}
|
||||
}
|
||||
|
||||
a {
|
||||
color: var(--o-enterprise-action-color, #017e84);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Narrow screens: amounts keep a legible floor, the label keeps its own. */
|
||||
@media (max-width: 900px) {
|
||||
.dn_report_view .dn_report_table {
|
||||
margin: 8px;
|
||||
padding: 8px;
|
||||
min-width: 0;
|
||||
|
||||
.dn_report_label_col {
|
||||
width: auto;
|
||||
min-width: 14rem;
|
||||
}
|
||||
|
||||
.dn_report_amount_col {
|
||||
width: 1%;
|
||||
min-width: 6rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media print {
|
||||
.dn_report_view {
|
||||
.o_control_panel,
|
||||
.dn_report_toolbar {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.dn_report_content {
|
||||
overflow: visible !important;
|
||||
}
|
||||
|
||||
.dn_report_table {
|
||||
font-size: 10pt;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
min-width: 0;
|
||||
|
||||
> thead > tr > th {
|
||||
position: static;
|
||||
background: transparent !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
88
accountant_cn/static/src/js/dn_report_view.xml
Normal file
88
accountant_cn/static/src/js/dn_report_view.xml
Normal file
@@ -0,0 +1,88 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<templates xml:space="preserve">
|
||||
|
||||
<t t-name="dn_account_reports_core.DnReportView">
|
||||
<div class="dn_report_view o_action d-flex flex-column h-100">
|
||||
<!-- Control panel: same class names as Odoo 20's own control panel
|
||||
(o_control_panel_main / o_control_panel_breadcrumbs /
|
||||
o_control_panel_navigation). The older o_cp_top / o_cp_bottom
|
||||
names carry no styles in Odoo 20, which made the title, the
|
||||
filters and the buttons stack as full-width blocks. -->
|
||||
<div class="o_control_panel d-flex flex-column gap-2 px-3 pt-2">
|
||||
<div class="o_control_panel_main d-flex flex-wrap flex-lg-nowrap justify-content-between align-items-lg-start gap-2">
|
||||
<div class="o_control_panel_breadcrumbs d-flex align-items-center min-w-0">
|
||||
<h3 class="m-0 text-truncate"
|
||||
t-out="this.state.report ? this.state.report.name : this.labels.title"/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dn_report_toolbar d-flex flex-wrap align-items-end gap-2 pb-2">
|
||||
<div class="dn_report_field">
|
||||
<label class="d-block small text-muted mb-1" t-out="this.labels.start"/>
|
||||
<input type="date" class="form-control form-control-sm" t-model="this.dateFrom"/>
|
||||
</div>
|
||||
<div class="dn_report_field">
|
||||
<label class="d-block small text-muted mb-1" t-out="this.labels.end"/>
|
||||
<input type="date" class="form-control form-control-sm" t-model="this.dateTo"/>
|
||||
</div>
|
||||
<div class="pb-1">
|
||||
<button class="btn btn-primary btn-sm text-nowrap"
|
||||
t-on-click="this.load"
|
||||
t-att-disabled="this.state.loading"
|
||||
t-out="this.labels.apply"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="dn_report_content flex-grow-1 overflow-auto">
|
||||
<div t-if="this.state.loading" class="alert alert-info m-3" t-out="this.labels.computing"/>
|
||||
<div t-if="this.state.error" class="alert alert-danger m-3" t-out="this.state.error"/>
|
||||
|
||||
<!-- `table table-borderless` matches the enterprise report
|
||||
table base. No `table-sm` / `mb-0` / `table-hover`: they
|
||||
would flatten the card padding, zero the card margin and
|
||||
add a competing hover colour. -->
|
||||
<table t-if="this.ready" class="table table-borderless dn_report_table">
|
||||
<!-- No <colgroup> on purpose. Column widths are driven by
|
||||
the header cells: the label header hints 100% and each
|
||||
amount header hints 1%, so under `table-layout: auto`
|
||||
the browser gives the amounts their content width and
|
||||
the label column absorbs the rest. A <colgroup> would
|
||||
override that. -->
|
||||
<thead class="dn_report_thead">
|
||||
<tr>
|
||||
<th class="text-start dn_report_label_col" t-out="this.labels.account"/>
|
||||
<t t-foreach="this.headers" t-as="header" t-key="header_index">
|
||||
<th class="text-end text-nowrap dn_report_amount_col" t-out="header"/>
|
||||
</t>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr t-foreach="this.visibleRows" t-as="line" t-key="line.id"
|
||||
t-att-class="this.rowClass(line)">
|
||||
<td class="dn_report_cell_label">
|
||||
<span t-att-style="this.indentStyle(line)"/>
|
||||
<span t-if="line.children and line.children.length" class="dn_report_toggle_wrap">
|
||||
<button class="btn btn-link btn-sm p-0 dn_report_toggle"
|
||||
t-on-click="(ev) => this.toggleLine(line.id)">
|
||||
<i t-att-class="this.isFolded(line) ? 'fa fa-caret-right' : 'fa fa-caret-down'"/>
|
||||
</button>
|
||||
</span>
|
||||
<span t-else="" class="dn_report_toggle_wrap"/>
|
||||
<span t-if="line.code" class="text-muted me-2 small" t-out="line.code"/>
|
||||
<span t-out="line.name"/>
|
||||
</td>
|
||||
<t t-foreach="this.headers" t-as="header" t-key="header_index">
|
||||
<td class="text-end text-nowrap" t-out="this.cellValue(line, header_index)"/>
|
||||
</t>
|
||||
</tr>
|
||||
<tr t-if="!this.visibleRows.length">
|
||||
<td t-att-colspan="this.headers.length + 1" class="text-center text-muted py-4" t-out="this.labels.empty"/>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
|
||||
</templates>
|
||||
28
accountant_cn/static/src/scss/dn_loan.scss
Normal file
28
accountant_cn/static/src/scss/dn_loan.scss
Normal file
@@ -0,0 +1,28 @@
|
||||
/* DN Loans Management.
|
||||
*
|
||||
* Two adjustments to the generic Odoo list rendering, both driven by how an
|
||||
* amortization schedule is read rather than by taste.
|
||||
*/
|
||||
|
||||
/* The schedule is a table of amounts. Right-aligning them, with a tabular
|
||||
* figure width, makes the columns line up so a column of principals can be read
|
||||
* as a column; proportional digits make every row a slightly different width
|
||||
* and the eye cannot follow a column down. */
|
||||
.o_list_renderer .o_data_cell.o_dn_amount_cell,
|
||||
.o_list_renderer .o_data_row .o_data_cell[name="principal"],
|
||||
.o_list_renderer .o_data_row .o_data_cell[name="interest"],
|
||||
.o_list_renderer .o_data_row .o_data_cell[name="payment"],
|
||||
.o_list_renderer .o_data_row .o_data_cell[name="outstanding_balance"] {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
/* The wizard preview is a fixed-width text block: it is a table drawn with
|
||||
* spaces, so it only aligns if the font is monospaced and the whitespace is
|
||||
* preserved. Bootstrap's `text-monospace` sets the font but the textarea would
|
||||
* still wrap the long lines. */
|
||||
.o_field_text.dn_loan_preview textarea,
|
||||
.dn_loan_preview textarea {
|
||||
white-space: pre;
|
||||
overflow-x: auto;
|
||||
font-variant-ligatures: none;
|
||||
}
|
||||
30
accountant_cn/static/src/scss/dn_lock_date.scss
Normal file
30
accountant_cn/static/src/scss/dn_lock_date.scss
Normal file
@@ -0,0 +1,30 @@
|
||||
/* DN Accounting — lock-date dialog.
|
||||
*
|
||||
* The dialog lists, next to each lock date, the exceptions that currently
|
||||
* apply to the signed-in user and to everyone. When both exist they have to be
|
||||
* separated by "; ", and that separator is punctuation, not a translatable
|
||||
* word: putting it in the XML made `i18n export` emit four multi-line HTML
|
||||
* fragments as translatable strings, which can only be translated by matching
|
||||
* the markup byte for byte and silently breaks on any reformatting.
|
||||
*
|
||||
* A pseudo-element says the same thing with no translatable content at all.
|
||||
* `content` is inherited from the element, so the separator never appears in
|
||||
* the po file and never needs a translation.
|
||||
*/
|
||||
.dn_lock_sep::before {
|
||||
content: "; ";
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
/* Italic hints.
|
||||
*
|
||||
* These were `<i>` elements, but an `<i>` wrapping nothing but text makes
|
||||
* `i18n export` emit the whole tag as the translatable string
|
||||
* (`<i>Checks before locking</i>`), so the translator has to reproduce the
|
||||
* markup exactly and any later styling change breaks the translation. A
|
||||
* class on a `<span>` gives the identical italic look while leaving the text
|
||||
* as the bare msgid.
|
||||
*/
|
||||
.dn_italic {
|
||||
font-style: italic;
|
||||
}
|
||||
Reference in New Issue
Block a user