summaryrefslogtreecommitdiff
path: root/base_accounting_kit/report/report_tax.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 17:14:58 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 17:14:58 +0700
commit1ca3b3df3421961caec3b747a364071c80f5c7da (patch)
tree6778a1f0f3f9b4c6e26d6d87ccde16e24da6c9d6 /base_accounting_kit/report/report_tax.py
parentb57188be371d36d96caac4b8d65a40745c0e972c (diff)
initial commit
Diffstat (limited to 'base_accounting_kit/report/report_tax.py')
-rw-r--r--base_accounting_kit/report/report_tax.py115
1 files changed, 115 insertions, 0 deletions
diff --git a/base_accounting_kit/report/report_tax.py b/base_accounting_kit/report/report_tax.py
new file mode 100644
index 0000000..61445ef
--- /dev/null
+++ b/base_accounting_kit/report/report_tax.py
@@ -0,0 +1,115 @@
+# -*- coding: utf-8 -*-
+#############################################################################
+#
+# Cybrosys Technologies Pvt. Ltd.
+#
+# Copyright (C) 2019-TODAY Cybrosys Technologies(<https://www.cybrosys.com>)
+# Author: Cybrosys Techno Solutions(<https://www.cybrosys.com>)
+#
+# You can modify it under the terms of the GNU LESSER
+# GENERAL PUBLIC LICENSE (LGPL v3), Version 3.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details.
+#
+# You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE
+# (LGPL v3) along with this program.
+# If not, see <http://www.gnu.org/licenses/>.
+#
+#############################################################################
+
+from _datetime import datetime
+
+from odoo import api, models, _
+from odoo.exceptions import UserError
+
+
+class ReportTax(models.AbstractModel):
+ _name = 'report.base_accounting_kit.report_tax'
+ _description = 'Tax Report'
+
+ @api.model
+ def _get_report_values(self, docids, data=None):
+ if not data.get('form'):
+ raise UserError(
+ _("Form content is missing, this report cannot be printed."))
+ return {
+ 'data': data['form'],
+ 'lines': self.get_lines(data.get('form')),
+ }
+
+ def _sql_from_amls_one(self):
+ sql = """SELECT "account_move_line".tax_line_id, COALESCE(SUM("account_move_line".debit-"account_move_line".credit), 0)
+ FROM %s
+ WHERE %s AND "account_move_line".tax_exigible GROUP BY "account_move_line".tax_line_id"""
+ return sql
+
+ def _sql_from_amls_two(self):
+ sql = """SELECT r.account_tax_id, COALESCE(SUM("account_move_line".debit-"account_move_line".credit), 0)
+ FROM %s
+ INNER JOIN account_move_line_account_tax_rel r ON ("account_move_line".id = r.account_move_line_id)
+ INNER JOIN account_tax t ON (r.account_tax_id = t.id)
+ WHERE %s AND "account_move_line".tax_exigible GROUP BY r.account_tax_id"""
+ return sql
+
+ def _compute_from_amls(self, options, taxes):
+ # compute the tax amount
+ sql = self._sql_from_amls_one()
+ tables, where_clause, where_params = self.env[
+ 'account.move.line']._query_get()
+ query = sql % (tables, where_clause)
+ self.env.cr.execute(query, where_params)
+ results = self.env.cr.fetchall()
+ for result in results:
+ if result[0] in taxes:
+ taxes[result[0]]['tax'] = abs(result[1])
+
+ # compute the net amount
+ sql2 = self._sql_from_amls_two()
+ query = sql2 % (tables, where_clause)
+ self.env.cr.execute(query, where_params)
+ results = self.env.cr.fetchall()
+ for result in results:
+ if result[0] in taxes:
+ taxes[result[0]]['net'] = abs(result[1])
+
+ @api.model
+ def get_lines(self, options):
+ taxes = {}
+ for tax in self.env['account.tax'].search(
+ [('type_tax_use', '!=', 'none')]):
+ if tax.children_tax_ids:
+ for child in tax.children_tax_ids:
+ if child.type_tax_use != 'none':
+ continue
+ taxes[child.id] = {'tax': 0, 'net': 0, 'name': child.name,
+ 'type': tax.type_tax_use}
+ else:
+ taxes[tax.id] = {'tax': 0, 'net': 0, 'name': tax.name,
+ 'type': tax.type_tax_use}
+ if options['date_from'] and not options['date_to']:
+ self.with_context(date_from=options['date_from'],
+ strict_range=True)._compute_from_amls(options,
+ taxes)
+ elif options['date_to'] and not options['date_from']:
+ self.with_context(date_to=options['date_to'],
+ strict_range=True)._compute_from_amls(options,
+ taxes)
+ elif options['date_from'] and options['date_to']:
+ self.with_context(date_from=options['date_from'],
+ date_to=options['date_to'],
+ strict_range=True)._compute_from_amls(options,
+ taxes)
+ else:
+ date_to = str(datetime.today().date())
+ self.with_context(date_to=date_to,
+ strict_range=True)._compute_from_amls(options,
+ taxes)
+
+ groups = dict((tp, []) for tp in ['sale', 'purchase'])
+ for tax in taxes.values():
+ if tax['tax']:
+ groups[tax['type']].append(tax)
+ return groups