Server IP : 127.0.0.2 / Your IP : 3.15.145.122 Web Server : Apache/2.4.18 (Ubuntu) System : User : www-data ( ) PHP Version : 7.0.33-0ubuntu0.16.04.16 Disable Function : disk_free_space,disk_total_space,diskfreespace,dl,exec,fpaththru,getmyuid,getmypid,highlight_file,ignore_user_abord,leak,listen,link,opcache_get_configuration,opcache_get_status,passthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,php_uname,phpinfo,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_times,posix_ttyname,posix_uname,pclose,popen,proc_open,proc_close,proc_get_status,proc_nice,proc_terminate,shell_exec,source,show_source,system,virtual MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /opt/odoo/addons/account/report/ |
Upload File : |
# -*- coding: utf-8 -*- from datetime import datetime import time from odoo import api, models, _ from odoo.exceptions import UserError from odoo.tools import DEFAULT_SERVER_DATE_FORMAT class ReportPartnerLedger(models.AbstractModel): _name = 'report.account.report_partnerledger' def _lines(self, data, partner): full_account = [] currency = self.env['res.currency'] query_get_data = self.env['account.move.line'].with_context(data['form'].get('used_context', {}))._query_get() reconcile_clause = "" if data['form']['reconciled'] else ' AND "account_move_line".reconciled = false ' params = [partner.id, tuple(data['computed']['move_state']), tuple(data['computed']['account_ids'])] + query_get_data[2] query = """ SELECT "account_move_line".id, "account_move_line".date, j.code, acc.code as a_code, acc.name as a_name, "account_move_line".ref, m.name as move_name, "account_move_line".name, "account_move_line".debit, "account_move_line".credit, "account_move_line".amount_currency,"account_move_line".currency_id, c.symbol AS currency_code FROM """ + query_get_data[0] + """ LEFT JOIN account_journal j ON ("account_move_line".journal_id = j.id) LEFT JOIN account_account acc ON ("account_move_line".account_id = acc.id) LEFT JOIN res_currency c ON ("account_move_line".currency_id=c.id) LEFT JOIN account_move m ON (m.id="account_move_line".move_id) WHERE "account_move_line".partner_id = %s AND m.state IN %s AND "account_move_line".account_id IN %s AND """ + query_get_data[1] + reconcile_clause + """ ORDER BY "account_move_line".date""" self.env.cr.execute(query, tuple(params)) res = self.env.cr.dictfetchall() sum = 0.0 lang_code = self.env.context.get('lang') or 'en_US' lang = self.env['res.lang'] lang_id = lang._lang_get(lang_code) date_format = lang_id.date_format for r in res: r['date'] = datetime.strptime(r['date'], DEFAULT_SERVER_DATE_FORMAT).strftime(date_format) r['displayed_name'] = '-'.join( r[field_name] for field_name in ('move_name', 'ref', 'name') if r[field_name] not in (None, '', '/') ) sum += r['debit'] - r['credit'] r['progress'] = sum r['currency_id'] = currency.browse(r.get('currency_id')) full_account.append(r) return full_account def _sum_partner(self, data, partner, field): if field not in ['debit', 'credit', 'debit - credit']: return result = 0.0 query_get_data = self.env['account.move.line'].with_context(data['form'].get('used_context', {}))._query_get() reconcile_clause = "" if data['form']['reconciled'] else ' AND "account_move_line".reconciled = false ' params = [partner.id, tuple(data['computed']['move_state']), tuple(data['computed']['account_ids'])] + query_get_data[2] query = """SELECT sum(""" + field + """) FROM """ + query_get_data[0] + """, account_move AS m WHERE "account_move_line".partner_id = %s AND m.id = "account_move_line".move_id AND m.state IN %s AND account_id IN %s AND """ + query_get_data[1] + reconcile_clause self.env.cr.execute(query, tuple(params)) contemp = self.env.cr.fetchone() if contemp is not None: result = contemp[0] or 0.0 return result @api.model def render_html(self, docids, data=None): if not data.get('form'): raise UserError(_("Form content is missing, this report cannot be printed.")) data['computed'] = {} obj_partner = self.env['res.partner'] query_get_data = self.env['account.move.line'].with_context(data['form'].get('used_context', {}))._query_get() data['computed']['move_state'] = ['draft', 'posted'] if data['form'].get('target_move', 'all') == 'posted': data['computed']['move_state'] = ['posted'] result_selection = data['form'].get('result_selection', 'customer') if result_selection == 'supplier': data['computed']['ACCOUNT_TYPE'] = ['payable'] elif result_selection == 'customer': data['computed']['ACCOUNT_TYPE'] = ['receivable'] else: data['computed']['ACCOUNT_TYPE'] = ['payable', 'receivable'] self.env.cr.execute(""" SELECT a.id FROM account_account a WHERE a.internal_type IN %s AND NOT a.deprecated""", (tuple(data['computed']['ACCOUNT_TYPE']),)) data['computed']['account_ids'] = [a for (a,) in self.env.cr.fetchall()] params = [tuple(data['computed']['move_state']), tuple(data['computed']['account_ids'])] + query_get_data[2] reconcile_clause = "" if data['form']['reconciled'] else ' AND "account_move_line".reconciled = false ' query = """ SELECT DISTINCT "account_move_line".partner_id FROM """ + query_get_data[0] + """, account_account AS account, account_move AS am WHERE "account_move_line".partner_id IS NOT NULL AND "account_move_line".account_id = account.id AND am.id = "account_move_line".move_id AND am.state IN %s AND "account_move_line".account_id IN %s AND NOT account.deprecated AND """ + query_get_data[1] + reconcile_clause self.env.cr.execute(query, tuple(params)) partner_ids = [res['partner_id'] for res in self.env.cr.dictfetchall()] partners = obj_partner.browse(partner_ids) partners = sorted(partners, key=lambda x: (x.ref, x.name)) docargs = { 'doc_ids': partner_ids, 'doc_model': self.env['res.partner'], 'data': data, 'docs': partners, 'time': time, 'lines': self._lines, 'sum_partner': self._sum_partner, } return self.env['report'].render('account.report_partnerledger', docargs)