[ADD] account_extra_reports: 2 reports from saas6 rehabilitated (sale/purchase journal printing and partner ledger)

This commit is contained in:
qdp-odoo
2016-01-27 01:51:32 +01:00
parent 2ebdb5f36e
commit 2f969182c3
14 changed files with 618 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import report
import wizard
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': 'Extra Accounting Reports',
'version': '1.1',
'category': 'Accounting & Finance',
'description': """
Extra Accounting Reports.
====================================
This module adds two new reports:
* Sale/Purchase Journal report
* Partner Ledger
""",
'website': 'https://www.odoo.com/page/accounting',
'depends': ['account_accountant'],
'data': [
'wizard/account_report_print_journal_view.xml',
'views/report_journal.xml',
'wizard/account_report_partner_ledger_view.xml',
'views/report_partnerledger.xml',
'data/account_report.xml'
],
'demo': [],
'installable': True,
'auto_install': False,
}
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!-- QWeb Reports -->
<report
id="action_report_journal"
model="account_extra_reports.report.journal"
string="Sale/Purchase Journal"
report_type="qweb-pdf"
name="account_extra_reports.report_journal"
file="account_extra_reports.report_journal"
/>
<report
id="action_report_partnerledger"
model="account_extra_reports.report_partnerledger"
string="Partner Ledger"
report_type="qweb-pdf"
name="account_extra_reports.report_partnerledger"
file="account_extra_reports.report_partnerledger"
/>
</data>
</openerp>
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import account_journal
import account_partner_ledger
@@ -0,0 +1,106 @@
# -*- coding: utf-8 -*-
import time
from openerp import api, models
class ReportJournal(models.AbstractModel):
_name = 'report.account_extra_reports.report_journal'
def lines(self, target_move, journal_ids, sort_selection, data):
if isinstance(journal_ids, int):
journal_ids = [journal_ids]
move_state = ['draft', 'posted']
if target_move == 'posted':
move_state = ['posted']
query_get_clause = self._get_query_get_clause(data)
params = [tuple(move_state), tuple(journal_ids)] + query_get_clause[2]
query = 'SELECT "account_move_line".id FROM ' + query_get_clause[0] + ', account_move am WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' ORDER BY '
if sort_selection == 'date':
query += '"account_move_line".date'
else:
query += 'am.name'
query += ', "account_move_line".move_id'
self.env.cr.execute(query, tuple(params))
ids = map(lambda x: x[0], self.env.cr.fetchall())
return self.env['account.move.line'].browse(ids)
def _sum_debit(self, data, journal_id):
move_state = ['draft', 'posted']
if data['form'].get('target_move', 'all') == 'posted':
move_state = ['posted']
query_get_clause = self._get_query_get_clause(data)
params = [tuple(move_state), tuple(journal_id.ids)] + query_get_clause[2]
self.env.cr.execute('SELECT SUM(debit) FROM ' + query_get_clause[0] + ', account_move am '
'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' ',
tuple(params))
return self.env.cr.fetchone()[0] or 0.0
def _sum_credit(self, data, journal_id):
move_state = ['draft', 'posted']
if data['form'].get('target_move', 'all') == 'posted':
move_state = ['posted']
query_get_clause = self._get_query_get_clause(data)
params = [tuple(move_state), tuple(journal_id.ids)] + query_get_clause[2]
self.env.cr.execute('SELECT SUM(credit) FROM ' + query_get_clause[0] + ', account_move am '
'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' ',
tuple(params))
return self.env.cr.fetchone()[0] or 0.0
def _get_taxes(self, data, journal_id):
move_state = ['draft', 'posted']
if data['form'].get('target_move', 'all') == 'posted':
move_state = ['posted']
query_get_clause = self._get_query_get_clause(data)
params = [tuple(move_state), tuple(journal_id.ids)] + query_get_clause[2]
self.env.cr.execute('SELECT DISTINCT tax_line_id FROM ' + query_get_clause[0] + ', account_move am '
'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' AND tax_line_id is not null',
tuple(params))
ids = map(lambda x: x[0], self.env.cr.fetchall())
taxes = self.env['account.tax'].browse(ids)
res = {}
for tax in taxes:
res[tax] = {}
self.env.cr.execute('SELECT sum(debit - credit) FROM ' + query_get_clause[0] + ', account_move am '
'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' AND tax_line_id = %s',
tuple(params + [tax.id]))
res[tax]['tax_amount'] = self.env.cr.fetchone()[0] or 0.0
amls = self.env['account.move.line'].search([('tax_ids', 'in', [tax.id])])
self.env.cr.execute('SELECT sum(debit - credit) FROM ' + query_get_clause[0] + ', account_move am '
'WHERE "account_move_line".move_id=am.id AND am.state IN %s AND "account_move_line".journal_id IN %s AND ' + query_get_clause[1] + ' AND "account_move_line".id in %s',
tuple(params + [tuple(amls.ids)]))
res[tax]['base_amount'] = self.env.cr.fetchone()[0] or 0.0
if journal_id.type == 'sale':
#sales operation are credits
res[tax]['base_amount'] = res[tax]['base_amount'] * -1
res[tax]['tax_amount'] = res[tax]['tax_amount'] * -1
return res
def _get_query_get_clause(self, data):
return self.env['account.move.line'].with_context(data['form'].get('used_context', {}))._query_get()
@api.multi
def render_html(self, data):
target_move = data['form'].get('target_move', 'all')
sort_selection = data['form'].get('sort_selection', 'date')
res = {}
for journal in data['form']['journal_ids']:
res[journal] = self.with_context(data['form'].get('used_context', {})).lines(target_move, journal, sort_selection, data)
docargs = {
'doc_ids': data['form']['journal_ids'],
'doc_model': self.env['account.journal'],
'data': data,
'docs': self.env['account.journal'].browse(data['form']['journal_ids']),
'time': time,
'lines': res,
'sum_credit': self._sum_credit,
'sum_debit': self._sum_debit,
'get_taxes': self._get_taxes,
}
return self.env['report'].render('account_extra_reports.report_journal', docargs)
@@ -0,0 +1,111 @@
# -*- coding: utf-8 -*-
import time
from openerp import api, models
class ReportPartnerLedger(models.AbstractModel):
_name = 'report.account_extra_reports.report_partnerledger'
def _lines(self, data, partner):
full_account = []
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
for r in res:
r['displayed_name'] = '-'.join(
r['move_name'] not in ['', '/'] and [r['move_name']] or [] +
r['ref'] not in ['', '/'] and [r['ref']] or [] +
r['name'] not in ['', '/'] and [r['name']] or []
)
sum += r['debit'] - r['credit']
r['progress'] = sum
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.multi
def render_html(self, data):
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_extra_reports.report_partnerledger', docargs)
@@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_journal">
<t t-call="report.html_container">
<t t-set="data_report_margin_top" t-value="12"/>
<t t-set="data_report_header_spacing" t-value="9"/>
<t t-set="data_report_dpi" t-value="110"/>
<t t-foreach="docs" t-as="o">
<t t-call="report.internal_layout">
<div class="page">
<h2><t t-esc="o.name"/> Journal</h2>
<div class="row mt32">
<div class="col-xs-3">
<strong>Company:</strong>
<p t-esc="res_company.name"/>
</div>
<div class="col-xs-3">
<strong>Journal:</strong>
<p t-esc="o.name"/>
</div>
<div class="col-xs-3">
<strong>Entries Sorted By:</strong>
<p t-if="data['form'].get('sort_selection') != 'l.date'">Journal Entry Number</p>
<p t-if="data['form'].get('sort_selection') == 'l.date'">Date</p>
</div>
<div class="col-xs-3">
<strong>Target Moves:</strong>
<p t-if="data['form']['target_move'] == 'all'">All Entries</p>
<p t-if="data['form']['target_move'] == 'posted'">All Posted Entries</p>
</div>
</div>
<table class="table table-condensed">
<thead>
<tr>
<th>Move</th>
<th>Date</th>
<th>Account</th>
<th>Partner</th>
<th>Label</th>
<th>Debit</th>
<th>Credit</th>
<th t-if="data['form']['amount_currency']">Currency</th>
</tr>
</thead>
<tbody>
<tr t-foreach="lines[o.id]" t-as="aml">
<td><span t-esc="aml.move_id.name &lt;&gt; '/' and aml.move_id.name or ('*'+str(aml.move_id.id))"/></td>
<td><span t-field="aml.date"/></td>
<td><span t-field="aml.account_id.code"/></td>
<td><span t-esc="aml.partner_id and aml.partner_id.name[:23] or ''"/></td>
<td><span t-esc="aml.name[:35]"/></td>
<td><span t-esc="aml.debit" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/></td>
<td><span t-esc="aml.credit" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/></td>
<td t-if="data['form']['amount_currency'] and aml.amount_currency">
<span t-esc="aml.amount_currency" t-esc-options='{"widget": "monetary", "display_currency": "aml.currency_id"}'/>
</td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-xs-4 pull-right">
<table class="table table-condensed">
<tr>
<td><strong>Total</strong></td>
<td><span t-esc="sum_debit(data, o)" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/></td>
<td><span t-esc="sum_credit(data, o)" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/></td>
</tr>
</table>
</div>
</div>
<div class="row">
<div class="col-xs-4">
<table class="table table-condensed">
<thead>
<tr><th colspan="3">Tax Declaration</th></tr>
<tr>
<th>Name</th>
<th>Base Amount</th>
<th>Tax Amount</th>
</tr>
</thead>
<tbody>
<t t-set="taxes" t-value="get_taxes(data, o)"/>
<tr t-foreach="taxes" t-as="tax">
<td><span t-esc="tax.name"/></td>
<td><span t-esc="taxes[tax]['base_amount']" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/></td>
<td><span t-esc="taxes[tax]['tax_amount']" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/></td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</t>
</t>
</t>
</template>
</odoo>
@@ -0,0 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_partnerledger">
<t t-call="report.html_container">
<t t-set="data_report_margin_top" t-value="12"/>
<t t-set="data_report_header_spacing" t-value="9"/>
<t t-set="data_report_dpi" t-value="110"/>
<t t-foreach="docs" t-as="o">
<t t-call="report.internal_layout">
<div class="page">
<h2>Partner Ledger</h2>
<div class="row">
<div class="col-xs-3">
<strong>Company:</strong>
<p t-esc="res_company.name"/>
</div>
<div class="col-xs-3">
<t t-if="data['form']['date_from']"><strong>Date from :</strong> <span t-esc="data['form']['date_from']"/><br/></t>
<t t-if="data['form']['date_to']"><strong>Date to :</strong> <span t-esc="data['form']['date_to']"/></t>
</div>
<div class="col-xs-3">
<strong>Target Moves:</strong>
<p t-if="data['form']['target_move'] == 'all'">All Entries</p>
<p t-if="data['form']['target_move'] == 'posted'">All Posted Entries</p>
</div>
</div>
<table class="table table-condensed">
<thead>
<tr>
<th>Date</th>
<th>JRNL</th>
<th>Account</th>
<th>Ref</th>
<th>Debit</th>
<th>Credit</th>
<th>Balance</th>
<th t-if="amount_currency">Currency</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="4">
<strong t-esc="o.ref"/>
- <strong t-esc="o.name"/>
</td>
<td class="text-right">
<strong t-esc="sum_partner(data, o, 'debit')" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/>
</td>
<td class="text-right">
<strong t-esc="sum_partner(data, o, 'credit')" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/>
</td>
<td class="text-right">
<strong t-esc="sum_partner(data, o, 'debit - credit')" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/>
</td>
</tr>
<tr t-foreach="lines(data, o)" t-as="line">
<td>
<span t-esc="line['date']"/>
</td>
<td>
<span t-esc="line['code']"/>
</td>
<td>
<span t-esc="line['a_code']"/>
</td>
<td>
<span t-esc="line['displayed_name']"/>
</td>
<td class="text-right">
<span t-esc="line['debit']" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/>
</td>
<td class="text-right">
<span t-esc="line['credit']" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/>
</td>
<td class="text-right">
<span t-esc="line['progress']" t-esc-options='{"widget": "monetary", "display_currency": "res_company.currency_id"}'/>
</td>
<td t-if="amount_currency">
<span t-esc="line['amount_currency']" t-esc-options='{"widget": "monetary", "display_currency": "line[\"currency_id\"]"}'/>
</td>
</tr>
</tbody>
</table>
</div>
</t>
</t>
</t>
</template>
</odoo>
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import account_report_common_journal
import account_report_print_journal
import account_report_partner_ledger
@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from openerp import api, fields, models
class AccountCommonJournalReport(models.TransientModel):
_name = 'account.common.journal.report'
_description = 'Account Common Journal Report'
_inherit = "account.common.report"
amount_currency = fields.Boolean('With Currency', help="Print Report with the currency column if the currency differs from the company currency.")
@api.multi
def pre_print_report(self, data):
data['form'].update({'amount_currency': self.amount_currency})
return data
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
from openerp import fields, models, _
from openerp.exceptions import UserError
class AccountPartnerLedger(models.TransientModel):
_inherit = "account.common.partner.report"
_name = "account.report.partner.ledger"
_description = "Account Partner Ledger"
amount_currency = fields.Boolean("With Currency", help="It adds the currency column on report if the currency differs from the company currency.")
reconciled = fields.Boolean('Reconciled Entries')
def _print_report(self, data):
data = self.pre_print_report(data)
data['form'].update({'reconciled': self.reconciled, 'amount_currency': self.amount_currency})
return self.env['report'].get_action(self, 'account_extra_reports.report_partnerledger', data=data)
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_report_partner_ledger_view" model="ir.ui.view">
<field name="name">Partner Ledger</field>
<field name="model">account.report.partner.ledger</field>
<field name="inherit_id" ref="account.account_common_report_view"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='target_move']" position="after">
<field name="result_selection"/>
<field name="amount_currency" groups="base.group_multi_currency"/>
<newline/>
<field name="reconciled"/>
<newline/>
</xpath>
</data>
</field>
</record>
<record id="action_account_partner_ledger_menu" model="ir.actions.act_window">
<field name="name">Partner Ledger</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.report.partner.ledger</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="account_report_partner_ledger_view"/>
<field name="target">new</field>
</record>
<record id="action_account_partner_ledger_values" model="ir.values">
<field name="model_id" ref="account.model_account_account" />
<field name="name">Partner Ledger</field>
<field name="key2">client_print_multi</field>
<field name="value" eval="'ir.actions.act_window,' +str(ref('action_account_partner_ledger_menu'))" />
<field name="key">action</field>
<field name="model">account.account</field>
</record>
<menuitem
id="menu_partner_ledger"
name="Partner Ledger"
parent="account.account_reports_management_menu"
action="action_account_partner_ledger_menu"
groups="account.group_account_manager,account.group_account_user"
/>
</odoo>
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from openerp import fields, models
class AccountPrintJournal(models.TransientModel):
_inherit = "account.common.journal.report"
_name = "account.print.journal"
_description = "Account Print Journal"
sort_selection = fields.Selection([('date', 'Date'), ('move_name', 'Journal Entry Number'),], 'Entries Sorted by', required=True, default='move_name')
journal_ids = fields.Many2many('account.journal', string='Journals', required=True, default=lambda self: self.env['account.journal'].search([('type', 'in', ['sale', 'purchase'])]))
def _print_report(self, data):
data = self.pre_print_report(data)
data['form'].update({'sort_selection': self.sort_selection})
return self.env['report'].with_context(landscape=True).get_action(self, 'account_extra_reports.report_journal', data=data)
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_report_print_journal_view" model="ir.ui.view">
<field name="name">Sale/Purchase Journal</field>
<field name="model">account.print.journal</field>
<field name="inherit_id" ref="account.account_common_report_view"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='target_move']" position="after">
<field name="amount_currency" groups="base.group_multi_currency"/>
<field name="sort_selection" widget="radio"/>
<newline/>
</xpath>
<xpath expr="//field[@name='journal_ids']" position="attributes">
<attribute name="domain">[('type', 'in', ('sale', 'purchase'))]</attribute>
</xpath>
</data>
</field>
</record>
<record id="action_account_print_journal_menu" model="ir.actions.act_window">
<field name="name">Sale/Purchase Journal</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">account.print.journal</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="account_report_print_journal_view"/>
<field name="target">new</field>
</record>
<menuitem
id="menu_print_journal"
name="Sale/Purchase Journal"
parent="account.account_reports_management_menu"
action="action_account_print_journal_menu"
groups="account.group_account_manager,account.group_account_user"
/>
</odoo>