commit 1b7ed7777fe1eff2efee5feb092a4e26c1a3bec7 Author: Angga Date: Mon Sep 16 02:26:07 2024 +0700 init commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..67b0ad5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +*.pyc +.project +.pydevproject +.DS_Store +.idea/ +.run/ +venv/ \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..810593f --- /dev/null +++ b/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- + +from . import models +from . import wizards \ No newline at end of file diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..766eb75 --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +{ + 'name': "accounting_report", + + 'summary': """Accounting Report""", + + 'description': """ + Accounting Report + """, + + 'author': "", + 'website': "", + + # Categories can be used to filter modules in modules listing + # Check https://github.com/odoo/odoo/blob/15.0/odoo/addons/base/data/ir_module_category_data.xml + # for the full list + 'category': 'Uncategorized', + 'version': '0.1', + + # any module necessary for this one to work correctly + 'depends': ['base', + 'account', + ], + + # always loaded + 'data': [ + 'security/ir.model.access.csv', + + 'wizards/wz_ledger_bank_and_cash.xml', + 'views/ledger_bank_and_cash.xml', + + ], +} diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..5789382 --- /dev/null +++ b/models/__init__.py @@ -0,0 +1 @@ +from . import ledger_bank_and_cash \ No newline at end of file diff --git a/models/__pycache__/.gitignore b/models/__pycache__/.gitignore new file mode 100644 index 0000000..7e99e36 --- /dev/null +++ b/models/__pycache__/.gitignore @@ -0,0 +1 @@ +*.pyc \ No newline at end of file diff --git a/models/ledger_bank_and_cash.py b/models/ledger_bank_and_cash.py new file mode 100644 index 0000000..b15cb66 --- /dev/null +++ b/models/ledger_bank_and_cash.py @@ -0,0 +1,23 @@ +from odoo import models, fields, api, _ + + +class LedgerBankAndCash(models.Model): + _name = 'ledger.bank.and.cash' + _description = 'Bank and Cash Report' + _order = 'account_id, date asc' + + date = fields.Date() + account_id = fields.Many2one('account.account') + move_id = fields.Many2one('account.move') + source_no = fields.Char(related='move_id.name') + name = fields.Char(related='move_id.ref') + partner_id = fields.Many2one('res.partner') + currency_id = fields.Many2one('res.currency') + debit = fields.Monetary('Debit') + credit = fields.Monetary('Credit') + beginning_balance = fields.Monetary('Beginning Balance',) + account_code = fields.Char('Account Code', related='account_id.code') + account_name = fields.Char('Account Name', related='account_id.name') + balance = fields.Monetary('Balance',) + + \ No newline at end of file diff --git a/security/ir.model.access.csv b/security/ir.model.access.csv new file mode 100644 index 0000000..2bf42d6 --- /dev/null +++ b/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_lsbl_ledger_bank_and_cash,lsbl_ledger_bank_and_cash,model_ledger_bank_and_cash,base.group_user,1,1,1,1 +access_wz_ledger_bank_and_cash,wz_ledger_bank_and_cash,model_wz_ledger_bank_and_cash,base.group_user,1,1,1,1 \ No newline at end of file diff --git a/views/ledger_bank_and_cash.xml b/views/ledger_bank_and_cash.xml new file mode 100644 index 0000000..6045e58 --- /dev/null +++ b/views/ledger_bank_and_cash.xml @@ -0,0 +1,36 @@ + + + + + accounting.report.ledger.bank.and.cash.view.tree + ledger.bank.and.cash + + + + + + + + + + + + + + + + + + + + Cash and Bank Book + ledger.bank.and.cash + tree + +

+ Nothing Records +

+
+
+ +
\ No newline at end of file diff --git a/wizards/__init__.py b/wizards/__init__.py new file mode 100644 index 0000000..b090bc8 --- /dev/null +++ b/wizards/__init__.py @@ -0,0 +1 @@ +from . import wz_ledger_bank_and_cash \ No newline at end of file diff --git a/wizards/wz_ledger_bank_and_cash.py b/wizards/wz_ledger_bank_and_cash.py new file mode 100644 index 0000000..53aff42 --- /dev/null +++ b/wizards/wz_ledger_bank_and_cash.py @@ -0,0 +1,72 @@ +from odoo import models, fields, api, _ +from datetime import date, datetime, timedelta +from dateutil.relativedelta import relativedelta +from odoo.exceptions import ValidationError + +class WzLedgerBankAndCash(models.TransientModel): + _name = 'wz.ledger.bank.and.cash' + _description = 'Wizard Bank and Cash Report' + + def default_user_type(self): + return self.env['account.account.type'].sudo().search([('name', '=', 'Bank and Cash')], limit=1) + + date_from = fields.Date("From Date") + date_to = fields.Date("To Date") + account_ids = fields.Many2many('account.account', string='Account') + user_type_id = fields.Many2one('account.account.type', string='User Type', default=lambda self:self.default_user_type()) + + @api.constrains("date_from", "date_to") + def _check_filtered(self): + for rec in self: + if rec.date_from > rec.date_to: + raise ValidationError(_("Invalid Date ! End date should be greater than the start date")) + + def generate(self): + beginning_balance = 0 + balance = 0 + total_balance = 0 + start = self.date_from + end = self.date_to + move_line = self.env['account.move.line'].search([('date', '>=', start), ('date', '<=', end),('account_id', 'in', self.account_ids.ids), ('move_id.state', '=', 'posted')]) + bank_cash = self.env['ledger.bank.and.cash'] + move_line2 = self.env['account.move.line'].search([('date', '<=', start), ('account_id', 'in', self.account_ids.ids), ('move_id.state', '=', 'posted')]) + self.env.cr.execute(""" + delete from ledger_bank_and_cash + """) + if move_line: + no = 1 + mv_line_sorted = sorted(move_line, key=lambda x: x["date"]) + for account in self.account_ids: + for rec in mv_line_sorted: + if rec.account_id.id == account.id: + beginning_balance = sum(move_line2.filtered(lambda x : x.account_id.id == rec.account_id.id).mapped('balance')) + if no == 1: + balance = beginning_balance + (rec.debit - rec.credit) + total_balance = balance + else: + total_balance += rec.balance + bank_cash.create({ + 'date': rec.date, + 'account_id': rec.account_id.id, + 'move_id': rec.move_id.id, + 'partner_id': rec.partner_id.id, + 'currency_id': rec.currency_id.id, + 'beginning_balance': beginning_balance, + 'balance': total_balance, + 'debit': rec.debit, + 'credit': rec.credit, + }) + no += 1 + no = 1 + if bank_cash: + bank_cash.sorted(key=lambda r: (r.date, r.account_id)) + return { + 'name': _("Cash and Bank Book Period %s s/d %s" %(self.date_from.strftime("%d-%m-%Y"), self.date_to.strftime("%d-%m-%Y"))), + 'view_mode': 'list', + 'view_id': self.env.ref('accounting_report.accounting_report_ledger_bank_and_cash_view_tree').id, + 'res_model': 'ledger.bank.and.cash', + 'type': 'ir.actions.act_window', + 'context': { + 'group_by': ['account_id'], + } + } diff --git a/wizards/wz_ledger_bank_and_cash.xml b/wizards/wz_ledger_bank_and_cash.xml new file mode 100644 index 0000000..12ff9db --- /dev/null +++ b/wizards/wz_ledger_bank_and_cash.xml @@ -0,0 +1,44 @@ + + + + + wz.ledger.bank.and.cash.form + wz.ledger.bank.and.cash + +
+ + + + + + + +
+
+
+
+
+
+ + + Ledger Detail Bank and Cash Report + wz.ledger.bank.and.cash + form + new + + + + + + +