[IMP] account_reconcile_oca: Add balance

This commit is contained in:
Enric Tobella
2024-04-21 02:09:20 +02:00
parent 67b97d324e
commit 8f983803b0
7 changed files with 63 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ class AccountJournal(models.Model):
default="edit",
required=True,
)
company_currency_id = fields.Many2one(related="company_id.currency_id")
def get_rainbowman_message(self):
self.ensure_one()

View File

@@ -1,7 +1,8 @@
/** @odoo-module */
const {useState, useSubEnv} = owl;
const {onMounted, onWillStart, useState, useSubEnv} = owl;
import {KanbanController} from "@web/views/kanban/kanban_controller";
import {View} from "@web/views/view";
import {formatMonetary} from "@web/views/fields/formatters";
import {useService} from "@web/core/utils/hooks";
export class ReconcileController extends KanbanController {
@@ -9,6 +10,8 @@ export class ReconcileController extends KanbanController {
super.setup();
this.state = useState({
selectedRecordId: null,
journalBalance: 0,
currency: false,
});
useSubEnv({
parentController: this,
@@ -20,6 +23,43 @@ export class ReconcileController extends KanbanController {
this.router = useService("router");
this.activeActions = this.props.archInfo.activeActions;
this.model.addEventListener("update", () => this.selectRecord(), {once: true});
onWillStart(() => {
this.updateJournalInfo();
});
onMounted(() => {
this.selectRecord();
});
}
get journalId() {
if (this.props.resModel === "account.bank.statement.line") {
return this.props.context.active_id;
}
return false;
}
async updateJournalInfo() {
var journalId = this.journalId;
if (!journalId) {
return;
}
var result = await this.orm.call("account.journal", "read", [
[journalId],
["current_statement_balance", "currency_id", "company_currency_id"],
]);
this.state.journalBalance = result[0].current_statement_balance;
this.state.currency = (result[0].currency_id ||
result[0].company_currency_id)[0];
}
get journalBalanceStr() {
if (!this.state.journalBalance) {
return "";
}
console.log(this.state, {
currencyId: this.state.currency,
humanReadable: true,
});
return formatMonetary(this.state.journalBalance, {
currencyId: this.state.currency,
});
}
exposeController(controller) {
this.form_controller = controller;
@@ -45,6 +85,7 @@ export class ReconcileController extends KanbanController {
return {
resId: this.state.selectedRecordId,
type: "form",
noBreadcrumbs: true,
context: {
...(this.props.context || {}),
form_view_ref: this.props.context.view_ref,

View File

@@ -2,7 +2,11 @@
import {KanbanRenderer} from "@web/views/kanban/kanban_renderer";
import {ReconcileKanbanRecord} from "./reconcile_kanban_record.esm.js";
export class ReconcileRenderer extends KanbanRenderer {}
export class ReconcileRenderer extends KanbanRenderer {
get journalBalanceStr() {
console.log(this);
}
}
ReconcileRenderer.components = {
...KanbanRenderer.components,

View File

@@ -17,6 +17,9 @@ export class ReconcileFormController extends FormController {
afterExecuteAction: this.afterExecuteActionButton.bind(this),
});
}
displayName() {
return this.env.config.getDisplayName();
}
async reloadFormController() {
var is_reconciled = this.model.root.data.is_reconciled;
await this.model.root.load();

View File

@@ -45,7 +45,6 @@ export class AccountReconcileDataWidget extends Component {
);
data[line].amount_currency_format = fieldUtils.format.monetary(
data[line].currency_amount,
undefined,
{
currency: session.get_currency(data[line].line_currency_id),
}
@@ -53,7 +52,6 @@ export class AccountReconcileDataWidget extends Component {
if (data[line].original_amount) {
data[line].original_amount_format = fieldUtils.format.monetary(
data[line].original_amount,
undefined,
{
currency: session.get_currency(data[line].currency_id),
}

View File

@@ -6,6 +6,17 @@
t-inherit-mode="primary"
owl="1"
>
<xpath expr="//t[@t-as='groupOrRecord']" position="before">
<div class="m-2 d-flex w-100" t-if="env.parentController.journalId">
<span
class="flex-fill text-900 text-start ps-0 fw-bold fs-4 align-self-center"
>Balance</span>
<span
class="pe-0 fw-bold fs-4 align-self-center"
t-esc="env.parentController.journalBalanceStr"
/>
</div>
</xpath>
<xpath expr="div[hasclass('o_kanban_renderer')]" position="attributes">
<attribute
name="class"

View File

@@ -300,7 +300,7 @@
</field>
</record>
<record id="action_bank_statement_line_reconcile" model="ir.actions.act_window">
<field name="name">Reconcile bank statement lines</field>
<field name="name">Statement lines</field>
<field name="res_model">account.bank.statement.line</field>
<field name="domain">[('journal_id', '=', active_id)]</field>
<field