Browse Source

[ADD] Initial Commit

pull/57/head
Sreejith 7 years ago
parent
commit
23f1d1142f
  1. 4
      partner_ageing_billwise/__init__.py
  2. 45
      partner_ageing_billwise/__manifest__.py
  3. 3
      partner_ageing_billwise/models/__init__.py
  4. 15
      partner_ageing_billwise/models/report_aged_partner_balance.py
  5. 3
      partner_ageing_billwise/report/__init__.py
  6. 231
      partner_ageing_billwise/report/account_aged_partner_balance.py
  7. 106
      partner_ageing_billwise/report/report_agedpartnerbalance.xml
  8. BIN
      partner_ageing_billwise/static/description/banner.jpg
  9. BIN
      partner_ageing_billwise/static/description/bill-wise-repo.png
  10. BIN
      partner_ageing_billwise/static/description/customer-wise.png
  11. BIN
      partner_ageing_billwise/static/description/cybro_logo.png
  12. BIN
      partner_ageing_billwise/static/description/icon.png
  13. 108
      partner_ageing_billwise/static/description/index.html
  14. BIN
      partner_ageing_billwise/static/description/report_type_wiz.png
  15. 13
      partner_ageing_billwise/views/report_aged_partner_billwise.xml

4
partner_ageing_billwise/__init__.py

@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import report
from . import models

45
partner_ageing_billwise/__manifest__.py

@ -0,0 +1,45 @@
# -*- coding: utf-8 -*-
###################################################################################
#
# Cybrosys Technologies Pvt. Ltd.
# Copyright (C) 2017-TODAY Cybrosys Technologies(<https://www.cybrosys.com>).
# Author: LINTO C.T.(<https://www.cybrosys.com>)
#
# This program is free software: you can modify
# it under the terms of the GNU Affero General Public License (AGPL) as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# 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 Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
###################################################################################
{
'name': 'Aged Partner Balance Bill-Wise',
'version': '10.0.1.0.0',
'category': 'Accounting',
'summary': 'Bill-Wise Aged Partner Balance',
'description': """
This module provides features to take a pdf report of bill-wise aged partner balance.
""",
'author': 'Cybrosys Techno Solutions',
'website': "https://www.cybrosys.com",
'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions',
'depends': ['account_accountant'],
'data': [
'report/report_agedpartnerbalance.xml',
'views/report_aged_partner_billwise.xml',
],
'demo': [],
'images': ['static/description/banner.jpg'],
'license': 'LGPL-3',
'installable': True,
'application': False,
'auto_install': False,
}

3
partner_ageing_billwise/models/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import report_aged_partner_balance

15
partner_ageing_billwise/models/report_aged_partner_balance.py

@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
from odoo import fields, models
class AgedTrialBalanceBillwise(models.TransientModel):
_inherit = 'account.aged.trial.balance'
_description = 'Account Aged Trial balance Report Bill-wise'
report_type = fields.Selection([('bill', 'Bill-wise'), ('customer', 'Customer-wise')], default='customer',
string="Report Type")
def _print_report(self, data):
data['form']['report_type'] = self.report_type
return super(AgedTrialBalanceBillwise, self)._print_report(data)

3
partner_ageing_billwise/report/__init__.py

@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import account_aged_partner_balance

231
partner_ageing_billwise/report/account_aged_partner_balance.py

@ -0,0 +1,231 @@
# -*- coding: utf-8 -*-
import time
from datetime import datetime
from dateutil.relativedelta import relativedelta
from odoo import api, models, _
from odoo.tools import float_is_zero
class ReportAgedPartnerBalanceBillwise(models.AbstractModel):
_inherit = 'report.account.report_agedpartnerbalance'
def _get_billwise_move_lines(self, account_type, date_from, target_move, period_length):
periods = {}
start = datetime.strptime(date_from, "%Y-%m-%d")
for i in range(5)[::-1]:
stop = start - relativedelta(days=period_length)
periods[str(i)] = {
'name': (i!=0 and (str((5-(i+1)) * period_length) + '-' + str((5-i) * period_length)) or ('+'+str(4 * period_length))),
'stop': start.strftime('%Y-%m-%d'),
'start': (i!=0 and stop.strftime('%Y-%m-%d') or False),
}
start = stop - relativedelta(days=1)
res = []
total = []
cr = self.env.cr
user_company = self.env.user.company_id.id
move_state = ['draft', 'posted']
if target_move == 'posted':
move_state = ['posted']
arg_list = (tuple(move_state), tuple(account_type))
#build the reconciliation clause to see what partner needs to be printed
reconciliation_clause = '(l.reconciled IS FALSE)'
cr.execute('SELECT debit_move_id, credit_move_id FROM account_partial_reconcile where create_date > %s', (date_from,))
reconciled_after_date = []
for row in cr.fetchall():
reconciled_after_date += [row[0], row[1]]
if reconciled_after_date:
reconciliation_clause = '(l.reconciled IS FALSE OR l.id IN %s)'
arg_list += (tuple(reconciled_after_date),)
arg_list += (date_from, user_company)
query = '''
SELECT DISTINCT l.partner_id, UPPER(res_partner.name)
FROM account_move_line AS l left join res_partner on l.partner_id = res_partner.id, account_account, account_move am
WHERE (l.account_id = account_account.id)
AND (l.move_id = am.id)
AND (am.state IN %s)
AND (account_account.internal_type IN %s)
AND ''' + reconciliation_clause + '''
AND (l.date <= %s)
AND l.company_id = %s
ORDER BY UPPER(res_partner.name)'''
cr.execute(query, arg_list)
partners = cr.dictfetchall()
# put a total of 0
for i in range(7):
total.append(0)
# Build a string like (1,2,3) for easy use in SQL query
partner_ids = [partner['partner_id'] for partner in partners if partner['partner_id']]
lines = dict((partner['partner_id'] or False, []) for partner in partners)
if not partner_ids:
return [], [], []
# This dictionary will store the not due amount of all partners
undue_amounts = {}
query = '''SELECT l.id
FROM account_move_line AS l, account_account, account_move am
WHERE (l.account_id = account_account.id) AND (l.move_id = am.id)
AND (am.state IN %s)
AND (account_account.internal_type IN %s)
AND (COALESCE(l.date_maturity,l.date) > %s)\
AND ((l.partner_id IN %s) OR (l.partner_id IS NULL))
AND (l.date <= %s)
AND l.company_id = %s'''
cr.execute(query, (tuple(move_state), tuple(account_type), date_from, tuple(partner_ids), date_from, user_company))
aml_ids = cr.fetchall()
aml_ids = aml_ids and [x[0] for x in aml_ids] or []
for line in self.env['account.move.line'].browse(aml_ids):
partner_id = line.partner_id.id or False
if partner_id not in undue_amounts:
undue_amounts[partner_id] = 0.0
line_amount = line.balance
if line.balance == 0:
continue
for partial_line in line.matched_debit_ids:
if partial_line.create_date[:10] <= date_from:
line_amount += partial_line.amount
for partial_line in line.matched_credit_ids:
if partial_line.create_date[:10] <= date_from:
line_amount -= partial_line.amount
undue_amounts[partner_id] += line_amount
lines[partner_id].append({
'line': line,
'amount': line_amount,
'period': 6,
})
# Use one query per period and store results in history (a list variable)
# Each history will contain: history[1] = {'<partner_id>': <partner_debit-credit>}
history = []
for i in range(5):
args_list = (tuple(move_state), tuple(account_type), tuple(partner_ids),)
dates_query = '(COALESCE(l.date_maturity,l.date)'
if periods[str(i)]['start'] and periods[str(i)]['stop']:
dates_query += ' BETWEEN %s AND %s)'
args_list += (periods[str(i)]['start'], periods[str(i)]['stop'])
elif periods[str(i)]['start']:
dates_query += ' >= %s)'
args_list += (periods[str(i)]['start'],)
else:
dates_query += ' <= %s)'
args_list += (periods[str(i)]['stop'],)
args_list += (date_from, user_company)
query = '''SELECT l.id
FROM account_move_line AS l, account_account, account_move am
WHERE (l.account_id = account_account.id) AND (l.move_id = am.id)
AND (am.state IN %s)
AND (account_account.internal_type IN %s)
AND ((l.partner_id IN %s) OR (l.partner_id IS NULL))
AND ''' + dates_query + '''
AND (l.date <= %s)
AND l.company_id = %s'''
cr.execute(query, args_list)
partners_amount = {}
aml_ids = cr.fetchall()
aml_ids = aml_ids and [x[0] for x in aml_ids] or []
for line in self.env['account.move.line'].browse(aml_ids):
partner_id = line.partner_id.id or False
if partner_id not in partners_amount:
partners_amount[partner_id] = 0.0
line_amount = line.balance
if line.balance == 0:
continue
for partial_line in line.matched_debit_ids:
if partial_line.create_date[:10] <= date_from:
line_amount += partial_line.amount
for partial_line in line.matched_credit_ids:
if partial_line.create_date[:10] <= date_from:
line_amount -= partial_line.amount
partners_amount[partner_id] += line_amount
lines[partner_id].append({
'line': line,
'amount': line_amount,
'period': i + 1,
})
history.append(partners_amount)
for partner in partners:
at_least_one_amount = False
values = {}
undue_amt = 0.0
if partner['partner_id'] in undue_amounts: # Making sure this partner actually was found by the query
undue_amt = undue_amounts[partner['partner_id']]
total[6] = total[6] + undue_amt
values['direction'] = undue_amt
if not float_is_zero(values['direction'], precision_rounding=self.env.user.company_id.currency_id.rounding):
at_least_one_amount = True
for i in range(5):
during = False
if partner['partner_id'] in history[i]:
during = [history[i][partner['partner_id']]]
# Adding counter
total[(i)] = total[(i)] + (during and during[0] or 0)
values[str(i)] = during and during[0] or 0.0
if not float_is_zero(values[str(i)], precision_rounding=self.env.user.company_id.currency_id.rounding):
at_least_one_amount = True
values['total'] = sum([values['direction']] + [values[str(i)] for i in range(5)])
## Add for total
total[(i + 1)] += values['total']
values['partner_id'] = partner['partner_id']
if partner['partner_id']:
browsed_partner = self.env['res.partner'].browse(partner['partner_id'])
values['name'] = browsed_partner.name and len(browsed_partner.name) >= 45 and browsed_partner.name[0:40] + '...' or browsed_partner.name
values['trust'] = browsed_partner.trust
else:
values['name'] = _('Unknown Partner')
values['trust'] = False
if at_least_one_amount:
res.append(values)
return res, total, lines
@api.model
def render_html(self, docids, data=None):
total = []
model = self.env.context.get('active_model')
docs = self.env[model].browse(self.env.context.get('active_id'))
target_move = data['form'].get('target_move', 'all')
date_from = data['form'].get('date_from', time.strftime('%Y-%m-%d'))
if data['form']['result_selection'] == 'customer':
account_type = ['receivable']
elif data['form']['result_selection'] == 'supplier':
account_type = ['payable']
else:
account_type = ['payable', 'receivable']
if data['form'].get('report_type') == 'bill':
movelines, total, dummy = self._get_billwise_move_lines(account_type, date_from, target_move, data['form']['period_length'])
for partner in dummy:
for line in dummy[partner]:
line['intervals'] = {
'0': 0,
'1': 0,
'2': 0,
'3': 0,
'4': 0,
'5': 0,
'total': 0
}
line['intervals'][str(line['period']-1)] = line['amount']
line['intervals']['total'] += line['amount']
else:
movelines, total, dummy = self._get_partner_move_lines(account_type, date_from, target_move, data['form']['period_length'])
docargs = {
'doc_ids': self.ids,
'doc_model': model,
'data': data['form'],
'docs': docs,
'time': time,
'lines': dummy,
'get_partner_lines': movelines,
'get_direction': total,
}
return self.env['report'].render('account.report_agedpartnerbalance', docargs)

106
partner_ageing_billwise/report/report_agedpartnerbalance.xml

@ -0,0 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="report_agedpartnerbalance" inherit_id="account.report_agedpartnerbalance">
<xpath expr="//div[@class='page']/div[2]" position="after">
<div class="row mb32">
<div class="col-xs-3">
<strong>Report Type:</strong>
<p>
<span t-if="data['report_type'] == 'bill'">Bill-Wise</span>
<span t-if="data['report_type'] == 'customer'">Customer-Wise</span>
</p>
</div>
</div>
</xpath>
<xpath expr="//div[@class='page']/table[1]" position="replace">
<table class="table table-condensed">
<thead>
<tr>
<th>Partners</th>
<th class="text-right">
<span>Not due</span>
</th>
<th class="text-right"><span t-esc="data['4']['name']"/></th>
<th class="text-right"><span t-esc="data['3']['name']"/></th>
<th class="text-right"><span t-esc="data['2']['name']"/></th>
<th class="text-right"><span t-esc="data['1']['name']"/></th>
<th class="text-right"><span t-esc="data['0']['name']"/></th>
<th class="text-right">Total</th>
</tr>
<tr t-if="get_partner_lines">
<th style="border-bottom:2px solid !important;">Account Total</th>
<th style="border-bottom:2px solid !important;" class="text-right"><span t-esc="get_direction[6]" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></th>
<th style="border-bottom:2px solid !important;" class="text-right"><span t-esc="get_direction[4]" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></th>
<th style="border-bottom:2px solid !important;" class="text-right"><span t-esc="get_direction[3]" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></th>
<th style="border-bottom:2px solid !important;" class="text-right"><span t-esc="get_direction[2]" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></th>
<th style="border-bottom:2px solid !important;" class="text-right"><span t-esc="get_direction[1]" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></th>
<th style="border-bottom:2px solid !important;" class="text-right"><span t-esc="get_direction[0]" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></th>
<th style="border-bottom:2px solid !important;" class="text-right"><span t-esc="get_direction[5]" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/></th>
</tr>
</thead>
<tbody>
<t t-foreach="get_partner_lines" t-as="partner">
<tr style="font-weight:bold !important;border-top:1px solid !important;">
<td style="border-top:1px solid !important;">
<span t-esc="partner['name']"/>
</td>
<td class="text-right" style="border-top:1px solid !important;">
<span t-esc="partner['direction']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right" style="border-top:1px solid !important;">
<span t-esc="partner['4']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right" style="border-top:1px solid !important;">
<span t-esc="partner['3']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right" style="border-top:1px solid !important;">
<span t-esc="partner['2']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right" style="border-top:1px solid !important;">
<span t-esc="partner['1']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right" style="border-top:1px solid !important;">
<span t-esc="partner['0']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right" style="border-top:1px solid !important;">
<span t-esc="partner['total']" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
</tr>
<t t-if="data['report_type'] == 'bill'">
<t t-foreach="lines[partner['partner_id']]" t-as="line">
<t t-if="line['amount'] > 0">
<tr>
<td class="text-right">
<span t-esc="line['line'].invoice_id.number"/>
</td>
<td class="text-right">
<span t-esc="line['intervals'].get('5')" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right">
<span t-esc="line['intervals'].get('4')" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right">
<span t-esc="line['intervals'].get('3')" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right">
<span t-esc="line['intervals'].get('2')" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right">
<span t-esc="line['intervals'].get('1')" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right">
<span t-esc="line['intervals'].get('0')" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
<td class="text-right">
<span t-esc="line['intervals'].get('total')" t-options="{'widget': 'monetary', 'display_currency': res_company.currency_id}"/>
</td>
</tr>
</t>
</t>
</t>
</t>
</tbody>
</table>
</xpath>
</template>
</odoo>

BIN
partner_ageing_billwise/static/description/banner.jpg

Binary file not shown.

After

Width:  |  Height:  |  Size: 125 KiB

BIN
partner_ageing_billwise/static/description/bill-wise-repo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
partner_ageing_billwise/static/description/customer-wise.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
partner_ageing_billwise/static/description/cybro_logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
partner_ageing_billwise/static/description/icon.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

108
partner_ageing_billwise/static/description/index.html

@ -0,0 +1,108 @@
<section class="oe_container">
<div class="oe_row oe_spaced">
<h2 class="oe_slogan">Aged Partner Balance Bill-Wise</h2>
<h3 class="oe_slogan"></h3>
<h4 class="oe_slogan"><a href="https://www.cybrosys.com">Cybrosys Technologies</a> </h4>
</div>
<div class="oe_row oe_spaced" style="padding-left:65px;">
<div>
<span style="color:green;"> &#9745; </span> Bill-wise aged partner balance report.<br/>
<span style="color:green;"> &#9745; </span> Customer-wise aged partner balance report.<br/>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div class="oe_picture">
<h3 class="oe_slogan">Overview</h3>
<p class="oe_mt32 text-justify" style="text-align: center;">
By default, Odoo doesn't have a bill-wise aged partner balance report.
With this module, we can have a pdf report of bill-wise and customer-wise(Odoo's default)
aged partner balance reports.
</p>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div style="text-align: center;">
<p>
<h4>Specify Report Type</h4>
<p>
</div>
<div style="text-align: center;">
<div class="oe_demo oe_picture oe_screenshot">
<img style="border:10px solid white;height:400px;" src="report_type_wiz.png">
</div>
</div>
<div style="text-align: center;">
<p>
A new field is added to the aged partner balance wizard to specify the report type.
We can have two types of reports, bill-wise or customer-wise. Bill-wise option will output
a bill-wise aged partner balance and customer-wise option will output a customer wise
aged partner balance report.
</p>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<div class="oe_row oe_spaced">
<div style="text-align: center;">
<p>
<h4>Bill-Wise Report</h4>
<p>
</div>
<div style="text-align: center;">
<div class="oe_demo oe_picture oe_screenshot">
<img style="border:10px solid white;" src="bill-wise-repo.png">
</div>
</div>
</div>
</section>
<section class="oe_container">
<div class="oe_row oe_spaced">
<div style="text-align: center;">
<p>
<h4>Customer-Wise Report</h4>
<p>
</div>
<div style="text-align: center;">
<div class="oe_demo oe_picture oe_screenshot">
<img style="border:10px solid white;" src="customer-wise.png">
</div>
</div>
<div class="oe_row oe_spaced" style="padding-left:65px;">
<p>Type of report will be mentioned in the report.</p>
</div>
</div>
</section>
<section class="oe_container oe_dark">
<h2 class="oe_slogan" style="margin-top:20px;" >Need Any Help?</h2>
<div class="oe_slogan" style="margin-top:10px !important;">
<div>
<a class="btn btn-primary btn-lg mt8"
style="color: #FFFFFF !important;border-radius: 0;" href="https://www.cybrosys.com"><i
class="fa fa-envelope"></i> Email </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="https://www.cybrosys.com/contact/"><i
class="fa fa-phone"></i> Contact Us </a> <a
class="btn btn-primary btn-lg mt8" style="color: #FFFFFF !important;border-radius: 0;"
href="https://www.cybrosys.com/odoo-customization-and-installation/"><i
class="fa fa-check-square"></i> Request Customization </a>
</div>
<br>
<img src="cybro_logo.png" style="width: 190px; margin-bottom: 20px;" class="center-block">
<div>
<a href="https://twitter.com/cybrosys" target="_blank"><i class="fa fa-2x fa-twitter" style="color:white;background: #00a0d1;width:35px;"></i></a></td>
<a href="https://www.linkedin.com/company/cybrosys-technologies-pvt-ltd" target="_blank"><i class="fa fa-2x fa-linkedin" style="color:white;background: #31a3d6;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://www.facebook.com/cybrosystechnologies" target="_blank"><i class="fa fa-2x fa-facebook" style="color:white;background: #3b5998;width:35px;padding-left: 8px;"></i></a></td>
<a href="https://plus.google.com/106641282743045431892/about" target="_blank"><i class="fa fa-2x fa-google-plus" style="color:white;background: #c53c2c;width:35px;padding-left: 3px;"></i></a></td>
<a href="https://in.pinterest.com/cybrosys" target="_blank"><i class="fa fa-2x fa-pinterest" style="color:white;background: #ac0f18;width:35px;padding-left: 3px;"></i></a></td>
</div>
</div>
</section>

BIN
partner_ageing_billwise/static/description/report_type_wiz.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 61 KiB

13
partner_ageing_billwise/views/report_aged_partner_billwise.xml

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="aged_balance_view_billwise" model="ir.ui.view">
<field name="name">Aged Partner Balance Billwise</field>
<field name="model">account.aged.trial.balance</field>
<field name="inherit_id" ref="account.account_aged_balance_view" />
<field name="arch" type="xml">
<xpath expr="//field[@name='result_selection']" position="after">
<field name="report_type" />
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save