diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2023-08-09 11:09:23 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2023-08-09 11:09:23 +0700 |
| commit | 4aa5108543075227378b856ce31f478bd5a3b3db (patch) | |
| tree | ef4f8ba5a598f08b03ac0404c88da7869b81dab0 | |
| parent | cdbb16de1b4da9fdc5f170d411d2bf3b489bfafb (diff) | |
ledger
| -rwxr-xr-x | indoteknik_custom/__manifest__.py | 2 | ||||
| -rwxr-xr-x | indoteknik_custom/models/__init__.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_financial_report.py | 39 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_general_ledger.py | 134 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_report_general_ledger.py | 227 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_financial_report_view.xml | 51 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_report_general_ledger_view.xml | 37 |
7 files changed, 0 insertions, 494 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py index 2cd7ad6e..b7aadbdf 100755 --- a/indoteknik_custom/__manifest__.py +++ b/indoteknik_custom/__manifest__.py @@ -84,8 +84,6 @@ 'views/product_sla.xml', 'views/voucher.xml', 'views/bill_receipt.xml', - 'views/account_financial_report_view.xml', - 'views/account_report_general_ledger_view.xml', 'views/account_move_multi_update.xml', 'views/airway_bill.xml', 'views/product_attribute_value.xml', diff --git a/indoteknik_custom/models/__init__.py b/indoteknik_custom/models/__init__.py index f26cbec2..1bdbc513 100755 --- a/indoteknik_custom/models/__init__.py +++ b/indoteknik_custom/models/__init__.py @@ -75,7 +75,3 @@ from . import account_move_due_extension from . import voucher from . import bill_receipt from . import account_move_multi_update -from . import account_financial_report -from . import account_general_ledger -from . import account_report_financial -from . import account_report_general_ledger
\ No newline at end of file diff --git a/indoteknik_custom/models/account_financial_report.py b/indoteknik_custom/models/account_financial_report.py deleted file mode 100644 index 114449ce..00000000 --- a/indoteknik_custom/models/account_financial_report.py +++ /dev/null @@ -1,39 +0,0 @@ -# -*- coding: utf-8 -*- -###################################################################################### -# -# Cybrosys Technologies Pvt. Ltd. -# -# Copyright (C) 2019-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). -# Author: Cybrosys Technologies(odoo@cybrosys.com) -# -# This program is under the terms of the Odoo Proprietary License v1.0 (OPL-1) -# It is forbidden to publish, distribute, sublicense, or sell copies of the Software -# or modified copies of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -# DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -# DEALINGS IN THE SOFTWARE. -# -######################################################################################## - -from datetime import datetime -import json -import datetime -import io -from odoo import api, fields, models, _ -from odoo.tools import date_utils -try: - from odoo.tools.misc import xlsxwriter -except ImportError: - import xlsxwriter - - -class AccountingReport(models.TransientModel): - _inherit = "accounting.report.xlsx" - - -
\ No newline at end of file diff --git a/indoteknik_custom/models/account_general_ledger.py b/indoteknik_custom/models/account_general_ledger.py deleted file mode 100644 index 50d52374..00000000 --- a/indoteknik_custom/models/account_general_ledger.py +++ /dev/null @@ -1,134 +0,0 @@ -import time -from odoo import api, models, _ -from odoo.exceptions import UserError - - -class ReportGeneralLedger(models.AbstractModel): - _name = 'report.account.report_generalledger' - - def _get_account_move_entry_custom(self, accounts, init_balance, sortby, display_account): - """ - :param: - accounts: the recordset of accounts - init_balance: boolean value of initial_balance - sortby: sorting by date or partner and journal - display_account: type of account(receivable, payable and both) - - Returns a dictionary of accounts with following key and value { - 'code': account code, - 'name': account name, - 'debit': sum of total debit amount, - 'credit': sum of total credit amount, - 'balance': total balance, - 'amount_currency': sum of amount_currency, - 'move_lines': list of move line - } - """ - cr = self.env.cr - MoveLine = self.env['account.move.line'] - move_lines = {x: [] for x in accounts.ids} - - # Prepare initial sql query and Get the initial move lines - if init_balance: - init_tables, init_where_clause, init_where_params = MoveLine.with_context(date_from=self.env.context.get('date_from'), date_to=False, initial_bal=True)._query_get() - init_wheres = [""] - if init_where_clause.strip(): - init_wheres.append(init_where_clause.strip()) - init_filters = " AND ".join(init_wheres) - filters = init_filters.replace('account_move_line__move_id', 'm').replace('account_move_line', 'l') - sql = ("""SELECT 0 AS lid, l.account_id AS account_id, '' AS ldate, '' AS lcode, 0.0 AS amount_currency, '' AS lref, 'Initial Balance' AS lname, COALESCE(SUM(l.debit),0.0) AS debit, COALESCE(SUM(l.credit),0.0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) as balance, '' AS lpartner_id,\ - '' AS move_name, '' AS mmove_id, '' AS currency_code,\ - NULL AS currency_id,\ - '' AS invoice_id, '' AS invoice_type, '' AS invoice_number,\ - '' AS partner_name\ - FROM account_move_line l\ - LEFT JOIN account_move m ON (l.move_id=m.id)\ - LEFT JOIN res_currency c ON (l.currency_id=c.id)\ - LEFT JOIN res_partner p ON (l.partner_id=p.id)\ - LEFT JOIN account_move i ON (m.id =i.id)\ - JOIN account_journal j ON (l.journal_id=j.id)\ - WHERE l.account_id IN %s""" + filters + ' GROUP BY l.account_id') - params = (tuple(accounts.ids),) + tuple(init_where_params) - cr.execute(sql, params) - for row in cr.dictfetchall(): - move_lines[row.pop('account_id')].append(row) - - sql_sort = 'l.date, l.move_id' - if sortby == 'sort_journal_partner': - sql_sort = 'j.code, p.name, l.move_id' - - # Prepare sql query base on selected parameters from wizard - tables, where_clause, where_params = MoveLine._query_get() - wheres = [""] - if where_clause.strip(): - wheres.append(where_clause.strip()) - filters = " AND ".join(wheres) - filters = filters.replace('account_move_line__move_id', 'm').replace('account_move_line', 'l') - - # Get move lines base on sql query and Calculate the total balance of move lines - sql = ('''SELECT l.id AS lid, l.account_id AS account_id, l.date AS ldate, j.code AS lcode, l.currency_id, l.amount_currency, l.ref AS lref, l.name AS lname, COALESCE(l.debit,0) AS debit, COALESCE(l.credit,0) AS credit, COALESCE(SUM(l.debit),0) - COALESCE(SUM(l.credit), 0) AS balance,\ - m.name AS move_name, c.symbol AS currency_code, p.name AS partner_name\ - FROM account_move_line l\ - JOIN account_move m ON (l.move_id=m.id)\ - LEFT JOIN res_currency c ON (l.currency_id=c.id)\ - LEFT JOIN res_partner p ON (l.partner_id=p.id)\ - JOIN account_journal j ON (l.journal_id=j.id)\ - JOIN account_account acc ON (l.account_id = acc.id) \ - WHERE l.account_id IN %s ''' + filters + ''' GROUP BY l.id, l.account_id, l.date, j.code, l.currency_id, l.amount_currency, l.ref, l.name, m.name, c.symbol, p.name ORDER BY ''' + sql_sort) - params = (tuple(accounts.ids),) + tuple(where_params) - cr.execute(sql, params) - - for row in cr.dictfetchall(): - balance = 0 - for line in move_lines.get(row['account_id']): - balance += line['debit'] - line['credit'] - row['balance'] += balance - move_lines[row.pop('account_id')].append(row) - - # Calculate the debit, credit and balance for Accounts - account_res = [] - for account in accounts: - currency = account.currency_id and account.currency_id or account.company_id.currency_id - res = dict((fn, 0.0) for fn in ['credit', 'debit', 'balance', 'balance_month']) - res['code'] = account.code - res['name'] = account.name - res['company_id'] = account.company_id.id - res['move_lines'] = move_lines[account.id] - for line in res.get('move_lines'): - res['debit'] += line['debit'] - res['credit'] += line['credit'] - res['balance'] = line['balance'] - if display_account == 'all': - account_res.append(res) - if display_account == 'movement' and res.get('move_lines'): - account_res.append(res) - if display_account == 'not_zero' and not currency.is_zero(res['balance']): - account_res.append(res) - return account_res - - @api.model - def _get_report_values(self, docids, data=None): - if not data.get('form') or not self.env.context.get('active_model'): - raise UserError(_("Form content is missing, this report cannot be printed.")) - - model = self.env.context.get('active_model') - docs = self.env[model].browse(self.env.context.get('active_ids', [])) - - init_balance = data['form'].get('initial_balance', True) - sortby = data['form'].get('sortby', 'sort_date') - display_account = data['form']['display_account'] - codes = [] - if data['form'].get('journal_ids', False): - codes = [journal.code for journal in self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])] - - accounts = docs if model == 'account.account' else self.env['account.account'].search([]) - accounts_res = self.with_context(data['form'].get('used_context',{}))._get_account_move_entry_custom(accounts, init_balance, sortby, display_account) - return { - 'doc_ids': docids, - 'doc_model': model, - 'data': data['form'], - 'docs': docs, - 'time': time, - 'Accounts': accounts_res, - 'print_journal': codes, - } diff --git a/indoteknik_custom/models/account_report_general_ledger.py b/indoteknik_custom/models/account_report_general_ledger.py deleted file mode 100644 index 4e909872..00000000 --- a/indoteknik_custom/models/account_report_general_ledger.py +++ /dev/null @@ -1,227 +0,0 @@ -from datetime import datetime -from dateutil.relativedelta import relativedelta -from odoo.exceptions import UserError -import json -from datetime import timedelta, date -import datetime -import io -from odoo import api, fields, models, _ -from odoo.tools.float_utils import float_round -from odoo.tools import date_utils -try: - from odoo.tools.misc import xlsxwriter -except ImportError: - import xlsxwriter - -class AccountReportGeneralLedger(models.TransientModel): - _inherit = "account.report.general.ledger.xlsx" - - journal_ids = fields.Many2many('account.journal', string=_('Journals'), required=True,default=lambda self: self.env['account.journal'].search([('id', '=', 10)])) - - def _build_contexts(self, data): - result = {} - result['journal_ids'] = 'journal_ids' in data['form'] and data['form']['journal_ids'] or False - result['state'] = 'target_move' in data['form'] and data['form']['target_move'] or '' - date_from = data['form']['date_from'] or False - - if date_from: - date_from = fields.Date.from_string(date_from) - - date_from -= relativedelta(days=1) - - result['date_from'] = fields.Date.to_string(date_from) - else: - result['date_from'] = False - - result['date_to'] = data['form']['date_to'] or False - result['strict_range'] = True if result['date_from'] else False - return result - - def check_report_ledger(self): - self.ensure_one() - data = {} - data['ids'] = self.env.context.get('active_ids', []) - data['model'] = self.env.context.get('active_model', 'ir.ui.menu') - data['form'] = self.read(['date_from', 'date_to', 'journal_ids', 'target_move'])[0] - used_context = self._build_contexts(data) - data['form']['used_context'] = dict(used_context, lang=self.env.context.get('lang') or 'en_US') - return { - 'type': 'ir.actions.report', - 'data': {'model': 'account.report.general.ledger.xlsx', - 'options': json.dumps(data, default=date_utils.json_default), - 'output_format': 'xlsx', - 'report_name': 'general ledger report', - }, - 'report_type': 'xlsx' - } - - def get_xlsx_report(self, options, response): - output = io.BytesIO() - workbook = xlsxwriter.Workbook(output, {'in_memory': True}) - data = {} - vals = self.search([('id', '=', options['form']['id'])]) - data['form'] = vals.read([])[0] - data['model'] = 'ir.ui.menu' - data['ids'] = [] - data['form']['used_context'] = { - 'date_to': options['form'].get('date_to', False), - 'date_from': options['form'].get('date_from', False), - 'strict_range': True, - 'state': options['form']['target_move'], - 'journal_ids': options['form']['journal_ids'], - } - - env_obj = vals.env['report.account.report_generalledger'] - sortby = data['form'].get('sortby', 'sort_date') - display_account = data['form']['display_account'] - codes = [] - if data['form'].get('journal_ids', False): - codes = [journal.code for journal in self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])] - # accounts = vals.active_account if vals.active_account else self.env['account.account'].search([]) - accounts = self.env['account.account'].browse(options['ids']) or self.env['account.account'].search([]) - init_balance = vals['initial_balance'] - date_from = options['form'].get('date_from', False) - date_to = options['form'].get('date_to', False) - report_obj = env_obj.with_context(data['form'].get('used_context', {}))._get_account_move_entry_custom( - accounts, init_balance, sortby, display_account) - sheet = workbook.add_worksheet() - format1 = workbook.add_format({'font_size': 16, 'align': 'center', 'bg_color': '#D3D3D3', 'bold': True}) - format1.set_font_color('#000080') - format2 = workbook.add_format({'font_size': 12, 'bold': True, 'bg_color': '#D3D3D3'}) - format3 = workbook.add_format({'font_size': 10, 'bold': True}) - format4 = workbook.add_format({'font_size': 10}) - format6 = workbook.add_format({'font_size': 10, 'bold': True}) - format7 = workbook.add_format({'font_size': 10, 'align': 'center'}) - format5 = workbook.add_format({'font_size': 10, 'align': 'right'}) - format1.set_align('center') - format2.set_align('center') - format3.set_align('right') - format4.set_align('left') - codes = [] - if data['form'].get('journal_ids', False): - codes = [journal.code for journal in - self.env['account.journal'].search([('id', 'in', data['form']['journal_ids'])])] - logged_users = self.env['res.company']._company_default_get('account.account') - report_date = datetime.datetime.now().strftime("%Y-%m-%d") - sheet.merge_range('M8:N8', _("Report Date"), format3) - sheet.merge_range('M9:N9', report_date, format4) - sheet.merge_range(1, 0, 1, 14, logged_users.name, format4) - sheet.merge_range(3, 0, 4, 14, _("General Ledger Report"), format1) - sheet.merge_range('A6:B6', _("Journals :"), format6) - - row = 6 - col = 0 - i = 0 - for values in codes: - sheet.write(row, col + i, values, format7) - i += 1 - if data['form']['display_account'] == 'all': - display_account = _('All accounts') - elif data['form']['display_account'] == 'movement': - display_account = _('With movements') - else: - display_account = _('With balance not equal to zero') - - if data['form']['target_move'] == 'all': - target_moves = _('All entries') - else: - target_moves = _('All posted entries') - - if data['form']['sortby'] == 'sort_date': - sortby = 'Date' - else: - sortby = 'Journal and partners' - if data['form']['date_from']: - date_start = datetime.datetime.strptime(str(data['form']['used_context']['date_from']), '%Y-%m-%d') - date_start = date_start.strftime('%Y-%m-%d') - else: - date_start = "" - if data['form']['date_to']: - date_end = datetime.datetime.strptime(str(data['form']['used_context']['date_to']), '%Y-%m-%d') - date_end = date_end.strftime('%Y-%m-%d') - else: - date_end = "" - if sortby == 'Date': - sheet.write('G8', _("Start Date"), format3) - sheet.write('G9', date_start, format4) - sheet.write('J8', _("End Date"), format3) - sheet.write('J9', date_end, format4) - sheet.merge_range('C8:D8', _("Sorted By"), format3) - sheet.merge_range('C9:D9', sortby, format4) - sheet.merge_range('A8:B8', _("Display Account"), format6) - sheet.merge_range('A9:B9', display_account, format7) - sheet.merge_range('E8:F8', _("Target Moves"), format6) - sheet.merge_range('E9:F9', target_moves, format7) - sheet.write('A11', "Date ", format2) - sheet.write('B11', "JRNL", format2) - sheet.merge_range('C11:D11', _("Partner"), format2) - sheet.merge_range('E11:F11', _("Ref"), format2) - sheet.merge_range('G11:H11', _("Move"), format2) - sheet.merge_range('I11:L11', _("Entry Label"), format2) - sheet.write('M11', _("Debit"), format2) - sheet.write('N11', _("Credit"), format2) - sheet.write('O11', _("Balance"), format2) - sheet.write('P11', _("Debit Month"), format2) - sheet.write('Q11', _("Credit Month"), format2) - sheet.write('R11', _("Balance Month"), format2) - accounts = self.env['account.account'].search([]) - row_number = 11 - col_number = 0 - for account in accounts: - for values in report_obj: - if account['name'] == values['name'] and account['company_id'].id == values['company_id']: - sheet.write(row_number, col_number, account['code'], format3) - sheet.merge_range(row_number, col_number + 1, row_number, col_number + 11, account['name'], format6) - sheet.write(row_number, col_number + 12, - logged_users.currency_id.symbol + ' ' + "{:,.2f}".format(values['debit']), format3) - sheet.write(row_number, col_number + 13, - logged_users.currency_id.symbol + ' ' + "{:,.2f}".format(values['credit']), format3) - sheet.write(row_number, col_number + 14, - logged_users.currency_id.symbol + ' ' + "{:,.2f}".format(values['balance']), format3) - row_number += 1 - for lines in values['move_lines']: - if lines['ldate']: - formatted_date = datetime.datetime.strptime(str(lines['ldate']), '%Y-%m-%d') - formatted_date = formatted_date.strftime('%Y-%m-%d') - else: - formatted_date = "" - - sheet.write(row_number, col_number, formatted_date, format4) - sheet.write(row_number, col_number + 1, lines['lcode'], format4) - sheet.merge_range(row_number, col_number + 2, row_number, col_number + 3, lines['partner_name'], - format4) - sheet.merge_range(row_number, col_number + 4, row_number, col_number + 5, lines['lref'], - format4) - sheet.merge_range(row_number, col_number + 6, row_number, col_number + 7, lines['move_name'], - format4) - sheet.merge_range(row_number, col_number + 8, row_number, col_number + 11, lines['lname'], - format4) - sheet.write(row_number, col_number + 12, "{:,}".format(lines['debit']), format5) - sheet.write(row_number, col_number + 13, "{:,.2f}".format(lines['credit']), format5) - sheet.write(row_number, col_number + 14, "{:,.2f}".format(lines['balance']), format5) - - if lines['lname'] == 'Initial Balance': - debit_value = lines.get('debit', 0.0) - value_debit = values.get('debit', 0.0) - total_debit = value_debit - debit_value - debit_month = "{:,.2f}".format(total_debit) - - credit_value = lines.get('credit', 0.0) - value_credit = values.get('credit', 0.0) - total_credit = value_credit - credit_value - credit_month = "{:,.2f}".format(total_credit) - - total_balance = total_debit - total_credit - balance_month = "{:,.2f}".format(total_balance) - sheet.write(row_number, col_number + 15, debit_month, format5) - sheet.write(row_number, col_number + 16, credit_month, format5) - sheet.write(row_number, col_number + 17, balance_month, format5) - - row_number += 1 - - - workbook.close() - output.seek(0) - response.stream.write(output.read()) - output.close() - diff --git a/indoteknik_custom/views/account_financial_report_view.xml b/indoteknik_custom/views/account_financial_report_view.xml deleted file mode 100644 index 31c04e7c..00000000 --- a/indoteknik_custom/views/account_financial_report_view.xml +++ /dev/null @@ -1,51 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<odoo> - - <record id="account_financial_report_view_custom" model="ir.ui.view"> - <field name="name">Common Report</field> - <field name="model">accounting.report.xlsx</field> - <field name="arch" type="xml"> - <form string="Report Options"> - <group col="4"> - <field name="account_report_id" domain="[('parent_id','=',False)]"/> - <field name="target_move" widget="radio"/> - <field name="enable_filter"/> - <field name="debit_credit" attrs="{'invisible': [('enable_filter','=',True)]}"/> - <field name="date_from"/> - <field name="date_to"/> - </group> - <group> - <notebook tabpos="up" colspan="4"> - <page string="Comparison" name="comparison" attrs="{'invisible': [('enable_filter','=',False)]}"> - <group> - <field name="label_filter" attrs="{'required': [('enable_filter', '=', True)]}"/> - <field name="filter_cmp"/> - </group> - <group string="Dates" attrs="{'invisible':[('filter_cmp', '!=', 'filter_date')]}"> - <field name="date_from_cmp" attrs="{'required':[('filter_cmp', '=', 'filter_date')]}"/> - <field name="date_to_cmp" attrs="{'required':[('filter_cmp', '=', 'filter_date')]}"/> - </group> - </page> - </notebook> - <field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/> - </group> - <footer> - <button name="check_report" string="Print" type="object" default_focus="1" class="oe_highlight"/> - <button string="Cancel" class="btn btn-secondary" special="cancel" /> - </footer> - </form> - </field> - </record> - - <record id="action_account_report_custom" model="ir.actions.act_window"> - <field name="name">Financial Reports</field> - <field name="res_model">accounting.report.xlsx</field> - <field name="type">ir.actions.act_window</field> - <field name="view_mode">form</field> - <field name="view_id" ref="account_financial_report_view_custom"/> - <field name="target">new</field> - </record> - - <menuitem id="menu_account_report" name="Financial Report" action="action_account_report_custom" parent="account.menu_finance_reports" sequence="250"/> - -</odoo> diff --git a/indoteknik_custom/views/account_report_general_ledger_view.xml b/indoteknik_custom/views/account_report_general_ledger_view.xml deleted file mode 100644 index b789874f..00000000 --- a/indoteknik_custom/views/account_report_general_ledger_view.xml +++ /dev/null @@ -1,37 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<odoo> - <record id="account_report_export_ledger_custom_view" model="ir.ui.view"> - <field name="name">Export Ledger</field> - <field name="model">account.report.general.ledger.xlsx</field> - <field name="arch" type="xml"> - <form string="Report Options"> - <field name="company_id" invisible="1"/> - <group col="4"> - <field name="target_move" widget="radio"/> - <field name="sortby" widget="radio"/> - <field name="display_account" widget="radio"/> - <field name="initial_balance"/> - <field name="date_from"/> - <field name="date_to"/> - </group> - <group> - <field name="journal_ids" widget="many2many_tags"/> - </group> - <footer> - <button name="check_report_ledger" string="Print" type="object" default_focus="1" class="oe_highlight"/> - <button string="Cancel" class="btn btn-default" special="cancel" /> - </footer> - </form> - </field> - </record> - - <record id="action_account_report_export_ledger_custom_menu" model="ir.actions.act_window"> - <field name="name">export_ledger</field> - <field name="res_model">account.report.general.ledger.xlsx</field> - <field name="view_mode">form</field> - <field name="view_id" ref="account_report_export_ledger_custom_view"/> - <field name="target">new</field> - </record> - -<menuitem id="menu_export_ledger_custom" name="General Ledger Export" action="action_account_report_export_ledger_custom_menu" parent="account.menu_finance_reports" sequence="250"/> -</odoo>
\ No newline at end of file |
