[IMP] account_reconcile_oca: Add balance

pull/808/head
Enric Tobella 2024-04-21 02:09:20 +02:00 committed by Jordi Ballester Alomar
parent a030073b32
commit 402fd97d05
7 changed files with 66 additions and 9 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,14 +1,17 @@
/** @odoo-module */
const {useState, useSubEnv, onMounted} = owl;
const {onMounted, onWillStart, useState, useSubEnv} = owl;
import {useBus, useService} from "@web/core/utils/hooks";
import {KanbanController} from "@web/views/kanban/kanban_controller";
import {View} from "@web/views/view";
import {formatMonetary} from "@web/views/fields/formatters";
export class ReconcileController extends KanbanController {
async setup() {
super.setup();
this.state = useState({
selectedRecordId: null,
journalBalance: 0,
currency: false,
});
useSubEnv({
parentController: this,
@ -22,7 +25,43 @@ export class ReconcileController extends KanbanController {
useBus(this.model.bus, "update", () => {
this.selectRecord();
});
onMounted(() => this.selectRecord());
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;
@ -48,6 +87,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

@ -21,18 +21,17 @@ export class AccountReconcileDataWidget extends Component {
getReconcileLines() {
var data = this.props.record.data[this.props.name].data;
for (var line in data) {
data[line].amount_format = formatMonetary(data[line].amount, undefined, {
data[line].amount_format = formatMonetary(data[line].amount, {
currency: data[line].currency_id,
});
data[line].debit_format = formatMonetary(data[line].debit, undefined, {
data[line].debit_format = formatMonetary(data[line].debit, {
currency: data[line].currency_id,
});
data[line].credit_format = formatMonetary(data[line].credit, undefined, {
data[line].credit_format = formatMonetary(data[line].credit, {
currency: data[line].currency_id,
});
data[line].amount_currency_format = formatMonetary(
data[line].currency_amount,
undefined,
{
currency: data[line].line_currency_id,
}
@ -40,7 +39,6 @@ export class AccountReconcileDataWidget extends Component {
if (data[line].original_amount) {
data[line].original_amount_format = formatMonetary(
data[line].original_amount,
undefined,
{
currency: data[line].currency_id,
}

View File

@ -5,6 +5,17 @@
t-inherit="web.KanbanRenderer"
t-inherit-mode="primary"
>
<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

@ -315,7 +315,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 name="context">