From 963963f50c2e177612f75c29223b160acfb8438d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dar=C3=ADo=20Lodeiros?= Date: Mon, 16 Oct 2023 16:56:04 +0200 Subject: [PATCH] [ADD]pms_api_rest: cash flow by turns --- pms_api_rest/models/__init__.py | 2 +- pms_api_rest/models/account_bank_statement.py | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 pms_api_rest/models/account_bank_statement.py diff --git a/pms_api_rest/models/__init__.py b/pms_api_rest/models/__init__.py index 96f3e93d1..3a33b5564 100644 --- a/pms_api_rest/models/__init__.py +++ b/pms_api_rest/models/__init__.py @@ -3,4 +3,4 @@ from . import res_users from . import account_payment from . import sql_export from . import pms_room_type_class - +from . import account_bank_statement diff --git a/pms_api_rest/models/account_bank_statement.py b/pms_api_rest/models/account_bank_statement.py new file mode 100644 index 000000000..ed9cc3b84 --- /dev/null +++ b/pms_api_rest/models/account_bank_statement.py @@ -0,0 +1,43 @@ +from odoo import api, fields, models + + +class AccountBankStatement(models.Model): + _inherit = "account.bank.statement" + _order = "date desc, cash_turn desc, name desc, id desc" + + cash_turn = fields.Integer( + string="Turn", + help="Set the day turn of the cash statement", + copy=False, + readonly=True, + compute="_compute_cash_turn", + store=True, + ) + + @api.depends("journal_id", "pms_property_id", "date") + def _compute_cash_turn(self): + for record in self: + if record.journal_id.type == "cash" and record.pms_property_id: + day_statements = self.search( + [ + ("journal_id.type", "=", "cash"), + ("pms_property_id", "=", record.pms_property_id.id), + ("date", "=", record.date), + ], + order="create_date asc", + ) + record.cash_turn = list(day_statements).index(record) + 1 + + def name_get(self): + result = [] + for record in self: + name = record.name + if record.cash_turn: + name += ( + " [%s]" % str(record.cash_turn) + + " (" + + record.create_uid.name + + ")" + ) + result.append((record.id, name)) + return result