diff --git a/account_reconcile_oca/__manifest__.py b/account_reconcile_oca/__manifest__.py index 5b5ea66b..2e53b4fa 100644 --- a/account_reconcile_oca/__manifest__.py +++ b/account_reconcile_oca/__manifest__.py @@ -16,6 +16,7 @@ "base_sparse_field", ], "data": [ + "views/res_config_settings.xml", "security/ir.model.access.csv", "views/account_account_reconcile.xml", "views/account_bank_statement_line.xml", diff --git a/account_reconcile_oca/models/__init__.py b/account_reconcile_oca/models/__init__.py index 7845dccd..da04aa8d 100644 --- a/account_reconcile_oca/models/__init__.py +++ b/account_reconcile_oca/models/__init__.py @@ -4,3 +4,5 @@ from . import account_bank_statement_line from . import account_bank_statement from . import account_account_reconcile from . import account_move_line +from . import res_company +from . import res_config_settings diff --git a/account_reconcile_oca/models/account_bank_statement_line.py b/account_reconcile_oca/models/account_bank_statement_line.py index 36971169..d51f2bd7 100644 --- a/account_reconcile_oca/models/account_bank_statement_line.py +++ b/account_reconcile_oca/models/account_bank_statement_line.py @@ -3,6 +3,9 @@ from collections import defaultdict +from dateutil import rrule +from dateutil.relativedelta import relativedelta + from odoo import Command, _, api, fields, models, tools from odoo.exceptions import UserError from odoo.tools import float_is_zero @@ -86,6 +89,43 @@ class AccountBankStatementLine(models.Model): "account.move", default=False, store=False, prefetch=False, readonly=True ) can_reconcile = fields.Boolean(sparse="reconcile_data_info") + reconcile_aggregate = fields.Char(compute="_compute_reconcile_aggregate") + aggregate_id = fields.Integer(compute="_compute_reconcile_aggregate") + aggregate_name = fields.Char(compute="_compute_reconcile_aggregate") + + @api.model + def _reconcile_aggregate_map(self): + lang = self.env["res.lang"]._lang_get(self.env.user.lang) + week_start = rrule.weekday(int(lang.week_start) - 1) + return { + False: lambda s: (False, False), + "statement": lambda s: (s.statement_id.id, s.statement_id.name), + "day": lambda s: (s.date.toordinal(), s.date.strftime(lang.date_format)), + "week": lambda s: ( + (s.date + relativedelta(weekday=week_start(-1))).toordinal(), + (s.date + relativedelta(weekday=week_start(-1))).strftime( + lang.date_format + ), + ), + "month": lambda s: ( + s.date.replace(day=1).toordinal(), + s.date.replace(day=1).strftime(lang.date_format), + ), + } + + @api.depends("company_id", "journal_id") + def _compute_reconcile_aggregate(self): + reconcile_aggregate_map = self._reconcile_aggregate_map() + for record in self: + reconcile_aggregate = ( + record.journal_id.reconcile_aggregate + or record.company_id.reconcile_aggregate + ) + record.reconcile_aggregate = reconcile_aggregate + print(record.date, reconcile_aggregate_map[reconcile_aggregate](record)) + record.aggregate_id, record.aggregate_name = reconcile_aggregate_map[ + reconcile_aggregate + ](record) def save(self): return {"type": "ir.actions.act_window_close"} diff --git a/account_reconcile_oca/models/account_journal.py b/account_reconcile_oca/models/account_journal.py index bc4ded92..a88e106f 100644 --- a/account_reconcile_oca/models/account_journal.py +++ b/account_reconcile_oca/models/account_journal.py @@ -13,6 +13,16 @@ class AccountJournal(models.Model): required=True, ) company_currency_id = fields.Many2one(related="company_id.currency_id") + reconcile_aggregate = fields.Selection( + [ + ("statement", "Statement"), + ("day", "Day"), + ("week", "Week"), + ("month", "Month"), + ], + string="Reconcile aggregation", + help="Aggregation to use on reconcile view", + ) def get_rainbowman_message(self): self.ensure_one() diff --git a/account_reconcile_oca/models/res_company.py b/account_reconcile_oca/models/res_company.py new file mode 100644 index 00000000..3ed88cb6 --- /dev/null +++ b/account_reconcile_oca/models/res_company.py @@ -0,0 +1,14 @@ +# Copyright 2024 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + reconcile_aggregate = fields.Selection( + selection=lambda self: self.env["account.journal"] + ._fields["reconcile_aggregate"] + .selection + ) diff --git a/account_reconcile_oca/models/res_config_settings.py b/account_reconcile_oca/models/res_config_settings.py new file mode 100644 index 00000000..8bcc2185 --- /dev/null +++ b/account_reconcile_oca/models/res_config_settings.py @@ -0,0 +1,12 @@ +# Copyright 2024 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + reconcile_aggregate = fields.Selection( + related="company_id.reconcile_aggregate", readonly=False + ) diff --git a/account_reconcile_oca/static/src/js/reconcile/reconcile_renderer.esm.js b/account_reconcile_oca/static/src/js/reconcile/reconcile_renderer.esm.js index 552de9ba..25fe2ac4 100644 --- a/account_reconcile_oca/static/src/js/reconcile/reconcile_renderer.esm.js +++ b/account_reconcile_oca/static/src/js/reconcile/reconcile_renderer.esm.js @@ -11,23 +11,23 @@ export class ReconcileRenderer extends KanbanRenderer { this.action = useService("action"); this.orm = useService("orm"); } - getStatements() { + getAggregates() { if ( this.env.parentController.props.resModel !== "account.bank.statement.line" ) { return []; } const {list} = this.props; - const statements = []; + const aggregates = []; for (const record of list.records) { - const statementId = record.data.statement_id && record.data.statement_id[0]; + const aggregateId = record.data.aggregate_id && record.data.aggregate_id; if ( - statementId && - (!statements.length || statements[0].id !== statementId) + aggregateId && + (!aggregates.length || aggregates[0].id !== aggregateId) ) { - statements.push({ - id: statementId, - name: record.data.statement_name, + aggregates.push({ + id: aggregateId, + name: record.data.aggregate_name, balance: record.data.statement_balance_end_real, balanceStr: formatMonetary(record.data.statement_balance_end_real, { currencyId: record.data.currency_id[0], @@ -35,7 +35,7 @@ export class ReconcileRenderer extends KanbanRenderer { }); } } - return statements; + return aggregates; } async onClickStatement(statementId) { const action = await this.orm.call( diff --git a/account_reconcile_oca/static/src/xml/reconcile.xml b/account_reconcile_oca/static/src/xml/reconcile.xml index 74a15e47..5e8990d3 100644 --- a/account_reconcile_oca/static/src/xml/reconcile.xml +++ b/account_reconcile_oca/static/src/xml/reconcile.xml @@ -9,29 +9,36 @@
Balance + >Global Balance
- + - -
+ +
+
diff --git a/account_reconcile_oca/views/account_bank_statement_line.xml b/account_reconcile_oca/views/account_bank_statement_line.xml index fc8d16b8..4f4e5ab2 100644 --- a/account_reconcile_oca/views/account_bank_statement_line.xml +++ b/account_reconcile_oca/views/account_bank_statement_line.xml @@ -13,12 +13,14 @@ - + + +