@ -0,0 +1,49 @@ |
|||
.. image:: https://img.shields.io/badge/license-LGPL--3-green.svg |
|||
:target: https://www.gnu.org/licenses/lgpl-3.0-standalone.html |
|||
:alt: License: LGPL-3 |
|||
|
|||
Customer/ Supplier Payment Statement Report |
|||
=========================================== |
|||
This module helps to generate Customer/Supplier Payment Statement Reports, automatically send monthly statements to customers, and provides the option to share Pdf and Excel reports. |
|||
|
|||
Configuration |
|||
============= |
|||
* No additional configuration is needed. |
|||
|
|||
Company |
|||
------- |
|||
* `Cybrosys Techno Solutions <https://cybrosys.com/>`__ |
|||
|
|||
License |
|||
------- |
|||
Lesser General Public License, v3.0 (LGPL v3). |
|||
(https://www.gnu.org/licenses/lgpl-3.0-standalone.html) |
|||
|
|||
Credits |
|||
------- |
|||
* Developers: (V16) Ayisha Sumayya K, |
|||
(V17) Jumana Haseen, |
|||
(V18) Aysha Shalin, |
|||
Contact: odoo@cybrosys.com |
|||
|
|||
Contacts |
|||
-------- |
|||
* Mail Contact : odoo@cybrosys.com |
|||
* Website : https://cybrosys.com |
|||
|
|||
Bug Tracker |
|||
----------- |
|||
Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. |
|||
|
|||
Maintainer |
|||
========== |
|||
.. image:: https://cybrosys.com/images/logo.png |
|||
:target: https://cybrosys.com |
|||
|
|||
This module is maintained by Cybrosys Technologies. |
|||
|
|||
For support and more information, please visit `Our Website <https://cybrosys.com/>`__ |
|||
|
|||
Further information |
|||
=================== |
|||
HTML Description: `<static/description/index.html>`__ |
@ -0,0 +1,23 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################# |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@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 . import controllers |
|||
from . import models |
@ -0,0 +1,52 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@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/>. |
|||
# |
|||
############################################################################### |
|||
{ |
|||
'name': 'Customer/ Supplier Payment Statement Report', |
|||
'version': '18.0.1.0.0', |
|||
'category': 'Productivity', |
|||
'summary': """This module is designed to generate Customer/Supplier Payment |
|||
Statement Reports.""", |
|||
'description': """This module helps to generate Customer/Supplier Payment |
|||
Statement Reports, automatically send monthly statements to customers, and |
|||
provides the option to share Pdf and Excel reports.""", |
|||
'author': 'Cybrosys Techno Solutions', |
|||
'company': 'Cybrosys Techno Solutions', |
|||
'maintainer': 'Cybrosys Techno Solutions', |
|||
'website': "https://www.cybrosys.com", |
|||
'depends': ['base', 'account', 'contacts'], |
|||
'data': [ |
|||
'data/ir_cron_data.xml', |
|||
'views/res_partner_views.xml', |
|||
'report/res_partner_reports.xml', |
|||
'report/res_partner_templates.xml', |
|||
], |
|||
'assets': { |
|||
'web.assets_backend': [ |
|||
'/statement_report/static/src/js/action_manager.js', |
|||
] |
|||
}, |
|||
'images': ['static/description/banner.png'], |
|||
'license': 'LGPL-3', |
|||
'installable': True, |
|||
'auto_install': False, |
|||
'application': False |
|||
} |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@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 . import statement_report |
@ -0,0 +1,53 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@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/>. |
|||
# |
|||
############################################################################### |
|||
import json |
|||
from odoo import http |
|||
from odoo.http import content_disposition, request |
|||
from odoo.tools import html_escape |
|||
|
|||
|
|||
class XLSXReportController(http.Controller): |
|||
""" Controller for xlsx report """ |
|||
@http.route('/xlsx_report', type='http', auth='user', methods=['POST'], |
|||
csrf=False) |
|||
def get_report_xlsx(self, model, options, output_format, report_name): |
|||
""" Get xlsx report data """ |
|||
report_obj = request.env[model].sudo() |
|||
options = json.loads(options) |
|||
try: |
|||
if output_format == 'xlsx': |
|||
response = request.make_response( |
|||
None, headers=[ |
|||
('Content-Type', 'application/vnd.ms-excel'), |
|||
('Content-Disposition', content_disposition( |
|||
report_name + '.xlsx'))]) |
|||
report_obj.get_xlsx_report(options, response) |
|||
response.set_cookie('fileToken', 'dummy token') |
|||
return response |
|||
except Exception as event: |
|||
serialize = http.serialize_exception(event) |
|||
error = { |
|||
'code': 200, |
|||
'message': 'Odoo Server Error', |
|||
'data': serialize |
|||
} |
|||
return request.make_response(html_escape(json.dumps(error))) |
@ -0,0 +1,28 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
<odoo> |
|||
<data noupdate="1"> |
|||
<!-- Send weekly statement report to partners --> |
|||
<record id="ir_cron_weekly_statement_report" model="ir.cron"> |
|||
<field name="name">Weekly Statement Report</field> |
|||
<field name="model_id" ref="model_res_partner"/> |
|||
<field name="state">code</field> |
|||
<field name="code">model.auto_week_statement_report()</field> |
|||
<field name="user_id" ref="base.user_root"/> |
|||
<field name="interval_number">1</field> |
|||
<field name="interval_type">weeks</field> |
|||
<field name="nextcall" eval="(DateTime.now() + timedelta(days=7)).strftime('%Y-%m-%d %H:00:00')"/> |
|||
</record> |
|||
|
|||
<!-- Send monthly statement report to partners --> |
|||
<record id="ir_cron_monthly_statement_report" model="ir.cron"> |
|||
<field name="name">Monthly Statement Report</field> |
|||
<field name="model_id" ref="model_res_partner"/> |
|||
<field name="state">code</field> |
|||
<field name="code">model.auto_month_statement_report()</field> |
|||
<field name="user_id" ref="base.user_root"/> |
|||
<field name="interval_number">1</field> |
|||
<field name="interval_type">months</field> |
|||
<field name="nextcall" eval="(DateTime.now() + relativedelta(day=1, months=1)).strftime('%Y-%m-%d 04:30:00')" /> |
|||
</record> |
|||
</data> |
|||
</odoo> |
@ -0,0 +1,6 @@ |
|||
## Module <statement_report> |
|||
|
|||
#### 09.10.2024 |
|||
#### Version 18.0.1.0.0 |
|||
##### ADD |
|||
- Initial commit for Customer/ Supplier Payment Statement Report |
@ -0,0 +1,22 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@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 . import res_partner |
@ -0,0 +1,895 @@ |
|||
# -*- coding: utf-8 -*- |
|||
############################################################################### |
|||
# |
|||
# Cybrosys Technologies Pvt. Ltd. |
|||
# |
|||
# Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>) |
|||
# Author: Aysha Shalin (odoo@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/>. |
|||
# |
|||
############################################################################### |
|||
import base64 |
|||
import io |
|||
import json |
|||
import xlsxwriter |
|||
from odoo import fields, models |
|||
from odoo.exceptions import ValidationError |
|||
from odoo.tools.json import json_default |
|||
|
|||
|
|||
class Partner(models.Model): |
|||
""" Class for adding report options in 'res.partner' """ |
|||
_inherit = 'res.partner' |
|||
|
|||
customer_report_ids = fields.Many2many( |
|||
'account.move', |
|||
compute='_compute_customer_report_ids', |
|||
help='Partner Invoices related to Customer') |
|||
vendor_statement_ids = fields.Many2many( |
|||
'account.move', |
|||
compute='_compute_vendor_statement_ids', |
|||
help='Partner Bills related to Vendor') |
|||
currency_id = fields.Many2one( |
|||
'res.currency', |
|||
default=lambda self: self.env.company.currency_id.id, |
|||
help="currency related to Customer or Vendor") |
|||
|
|||
def _compute_customer_report_ids(self): |
|||
""" For computing 'invoices' of partner """ |
|||
for rec in self: |
|||
inv_ids = self.env['account.move'].search( |
|||
[('partner_id', '=', rec.id), |
|||
('move_type', '=', 'out_invoice'), |
|||
('payment_state', '!=', 'paid'), |
|||
('state', '=', 'posted')]) |
|||
rec.customer_report_ids = inv_ids |
|||
|
|||
def _compute_vendor_statement_ids(self): |
|||
""" For computing 'bills' of partner """ |
|||
for rec in self: |
|||
bills = self.env['account.move'].search( |
|||
[('partner_id', '=', rec.id), |
|||
('move_type', '=', 'in_invoice'), |
|||
('payment_state', '!=', 'paid'), |
|||
('state', '=', 'posted')]) |
|||
rec.vendor_statement_ids = bills |
|||
|
|||
def main_query(self): |
|||
""" Return select query """ |
|||
query = """SELECT name , invoice_date, invoice_date_due, |
|||
amount_total_signed AS sub_total, |
|||
amount_residual_signed AS amount_due , |
|||
amount_residual AS balance |
|||
FROM account_move WHERE payment_state != 'paid' |
|||
AND state ='posted' AND partner_id= '%s' |
|||
AND company_id = '%s' """ % (self.id, self.env.company.id) |
|||
return query |
|||
|
|||
def amount_query(self): |
|||
""" Return query for calculating total amount """ |
|||
amount_query = """ SELECT SUM(amount_total_signed) AS total, |
|||
SUM(amount_residual) AS balance |
|||
FROM account_move WHERE payment_state != 'paid' |
|||
AND state ='posted' AND partner_id= '%s' |
|||
AND company_id = '%s' """ % (self.id, self.env.company.id) |
|||
return amount_query |
|||
|
|||
def action_share_pdf(self): |
|||
""" Action for sharing customer pdf report """ |
|||
if self.customer_report_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('out_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('out_invoice')""" |
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
report = self.env['ir.actions.report'].sudo()._render_qweb_pdf( |
|||
'statement_report.res_partner_action', self, data=data) |
|||
data_record = base64.b64encode(report[0]) |
|||
ir_values = { |
|||
'name': 'Statement Report', |
|||
'type': 'binary', |
|||
'datas': data_record, |
|||
'mimetype': 'application/pdf', |
|||
'res_model': 'res.partner' |
|||
} |
|||
attachment = self.env['ir.attachment'].sudo().create(ir_values) |
|||
email_values = { |
|||
'email_to': self.email, |
|||
'subject': 'Payment Statement Report', |
|||
'body_html': '<p>Dear <strong> Mr/Miss. ' + self.name + |
|||
'</strong> </p> <p> We have attached your ' |
|||
'payment statement. Please check </p> ' |
|||
'<p>Best regards, </p> <p> ' + self.env.user.name, |
|||
'attachment_ids': [attachment.id], |
|||
} |
|||
mail = self.env['mail.mail'].sudo().create(email_values) |
|||
mail.send() |
|||
return { |
|||
'type': 'ir.actions.client', |
|||
'tag': 'display_notification', |
|||
'params': { |
|||
'message': 'Email Sent Successfully', |
|||
'type': 'success', |
|||
'sticky': False |
|||
} |
|||
} |
|||
else: |
|||
raise ValidationError('There is no statement to send') |
|||
|
|||
def action_print_pdf(self): |
|||
""" Action for printing pdf report """ |
|||
if self.customer_report_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('out_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('out_invoice')""" |
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
return self.env.ref('statement_report.res_partner_action' |
|||
).report_action(self, data=data) |
|||
else: |
|||
raise ValidationError('There is no statement to print') |
|||
|
|||
def action_print_xlsx(self): |
|||
""" Action for printing xlsx report of customers """ |
|||
if self.customer_report_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('out_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('out_invoice')""" |
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'data': { |
|||
'model': 'res.partner', |
|||
'options': json.dumps(data, |
|||
default=json_default), |
|||
'output_format': 'xlsx', |
|||
'report_name': 'Payment Statement Report' |
|||
}, |
|||
'report_type': 'xlsx', |
|||
} |
|||
else: |
|||
raise ValidationError('There is no statement to print') |
|||
|
|||
def get_xlsx_report(self, data, response): |
|||
""" Get xlsx report data """ |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
sheet = workbook.add_worksheet() |
|||
cell_format_with_color = workbook.add_format({ |
|||
'font_size': '14px', 'bold': True, |
|||
'bg_color': 'yellow', 'border': 1}) |
|||
cell_format = workbook.add_format({'font_size': '14px', 'bold': True}) |
|||
txt = workbook.add_format({'font_size': '13px'}) |
|||
txt_border = workbook.add_format({'font_size': '13px', 'border': 1}) |
|||
head = workbook.add_format({'align': 'center', 'bold': True, |
|||
'font_size': '22px'}) |
|||
sheet.merge_range('B2:Q4', 'Payment Statement Report', head) |
|||
if data['customer']: |
|||
sheet.merge_range('B7:D7', 'Customer/Supplier : ', cell_format) |
|||
sheet.merge_range('E7:H7', data['customer'], txt) |
|||
sheet.merge_range('B9:C9', 'Address : ', cell_format) |
|||
if data['street']: |
|||
sheet.merge_range('D9:F9', data['street'], txt) |
|||
if data['street2']: |
|||
sheet.merge_range('D10:F10', data['street2'], txt) |
|||
if data['city']: |
|||
sheet.merge_range('D11:F11', data['city'], txt) |
|||
if data['state']: |
|||
sheet.merge_range('D12:F12', data['state'], ) |
|||
if data['zip']: |
|||
sheet.merge_range('D13:F13', data['zip'], txt) |
|||
sheet.merge_range('B15:C15', 'Date', cell_format_with_color) |
|||
sheet.merge_range('D15:G15', 'Invoice/Bill Number', |
|||
cell_format_with_color) |
|||
sheet.merge_range('H15:I15', 'Due Date', cell_format_with_color) |
|||
sheet.merge_range('J15:L15', 'Invoices/Debit', cell_format_with_color) |
|||
sheet.merge_range('M15:O15', 'Amount Due', cell_format_with_color) |
|||
sheet.merge_range('P15:R15', 'Balance Due', cell_format_with_color) |
|||
row = 15 |
|||
column = 0 |
|||
for record in data['my_data']: |
|||
sub_total = data['currency'] + str(record['sub_total']) |
|||
amount_due = data['currency'] + str(record['amount_due']) |
|||
balance = data['currency'] + str(record['balance']) |
|||
total = data['currency'] + str(data['total']) |
|||
remain_balance = data['currency'] + str(data['balance']) |
|||
sheet.merge_range(row, column + 1, row, column + 2, |
|||
record['invoice_date'], txt_border) |
|||
sheet.merge_range(row, column + 3, row, column + 6, |
|||
record['name'], txt_border) |
|||
sheet.merge_range(row, column + 7, row, column + 8, |
|||
record['invoice_date_due'], txt_border) |
|||
sheet.merge_range(row, column + 9, row, column + 11, |
|||
sub_total, txt_border) |
|||
sheet.merge_range(row, column + 12, row, column + 14, |
|||
amount_due, txt_border) |
|||
sheet.merge_range(row, column + 15, row, column + 17, |
|||
balance, txt_border) |
|||
row = row + 1 |
|||
sheet.write(row + 2, column + 1, 'Total Amount: ', cell_format) |
|||
sheet.merge_range(row + 2, column + 3, row + 2, column + 4, |
|||
total, txt) |
|||
sheet.write(row + 4, column + 1, 'Balance Due: ', cell_format) |
|||
sheet.merge_range(row + 4, column + 3, row + 4, column + 4, |
|||
remain_balance, txt) |
|||
workbook.close() |
|||
output.seek(0) |
|||
response.stream.write(output.read()) |
|||
output.close() |
|||
|
|||
def action_share_xlsx(self): |
|||
""" Action for sharing xlsx report via email """ |
|||
if self.customer_report_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('out_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('out_invoice')""" |
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
sheet = workbook.add_worksheet() |
|||
cell_format = workbook.add_format({ |
|||
'font_size': '14px', 'bold': True}) |
|||
txt = workbook.add_format({'font_size': '13px'}) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '22px'}) |
|||
sheet.merge_range('B2:P4', 'Payment Statement Report', head) |
|||
date_style = workbook.add_format( |
|||
{'text_wrap': True, 'align': 'center', |
|||
'num_format': 'yyyy-mm-dd'}) |
|||
if data['customer']: |
|||
sheet.write('B7:C7', 'Customer : ', cell_format) |
|||
sheet.merge_range('D7:G7', data['customer'], txt) |
|||
sheet.write('B9:C7', 'Address : ', cell_format) |
|||
if data['street']: |
|||
sheet.merge_range('D9:F9', data['street'], txt) |
|||
if data['street2']: |
|||
sheet.merge_range('D10:F10', data['street2'], txt) |
|||
if data['city']: |
|||
sheet.merge_range('D11:F11', data['city'], txt) |
|||
if data['state']: |
|||
sheet.merge_range('D12:F12', data['state'], txt) |
|||
if data['zip']: |
|||
sheet.merge_range('D13:F13', data['zip'], txt) |
|||
sheet.write('B15', 'Date', cell_format) |
|||
sheet.write('D15', 'Invoice/Bill Number', cell_format) |
|||
sheet.write('H15', 'Due Date', cell_format) |
|||
sheet.write('J15', 'Invoices/Debit', cell_format) |
|||
sheet.write('M15', 'Amount Due', cell_format) |
|||
sheet.write('P15', 'Balance Due', cell_format) |
|||
row = 16 |
|||
column = 0 |
|||
for record in data['my_data']: |
|||
sub_total = data['currency'] + str(record['sub_total']) |
|||
amount_due = data['currency'] + str(record['amount_due']) |
|||
balance = data['currency'] + str(record['balance']) |
|||
total = data['currency'] + str(data['total']) |
|||
remain_balance = data['currency'] + str(data['balance']) |
|||
sheet.merge_range(row, column + 1, row, column + 2, |
|||
record['invoice_date'], date_style) |
|||
sheet.merge_range(row, column + 3, row, column + 5, |
|||
record['name'], txt) |
|||
sheet.merge_range(row, column + 7, row, column + 8, |
|||
record['invoice_date_due'], date_style) |
|||
sheet.merge_range(row, column + 9, row, column + 10, |
|||
sub_total, txt) |
|||
sheet.merge_range(row, column + 12, row, column + 13, |
|||
amount_due, txt) |
|||
sheet.merge_range(row, column + 15, row, column + 16, |
|||
balance, txt) |
|||
row = row + 1 |
|||
sheet.write(row + 2, column + 1, 'Total Amount : ', cell_format) |
|||
sheet.merge_range(row + 2, column + 4, row + 2, column + 5, |
|||
total, txt) |
|||
sheet.write(row + 4, column + 1, 'Balance Due : ', cell_format) |
|||
sheet.merge_range(row + 4, column + 4, row + 4, column + 5, |
|||
remain_balance, txt) |
|||
workbook.close() |
|||
output.seek(0) |
|||
xlsx = base64.b64encode(output.read()) |
|||
output.close() |
|||
ir_values = { |
|||
'name': "Statement Report.xlsx", |
|||
'type': 'binary', |
|||
'datas': xlsx, |
|||
'store_fname': xlsx, |
|||
} |
|||
attachment = self.env['ir.attachment'].sudo().create(ir_values) |
|||
email_values = { |
|||
'email_to': self.email, |
|||
'subject': 'Payment Statement Report', |
|||
'body_html': '<p>Dear <strong> Mr/Miss. ' + self.name + |
|||
'</strong> </p> <p> We have attached your' |
|||
' payment statement. Please check </p> ' |
|||
'<p>Best regards, </p> <p> ' + self.env.user.name, |
|||
'attachment_ids': [attachment.id], |
|||
} |
|||
mail = self.env['mail.mail'].sudo().create(email_values) |
|||
mail.send() |
|||
return { |
|||
'type': 'ir.actions.client', |
|||
'tag': 'display_notification', |
|||
'params': { |
|||
'message': 'Email Sent Successfully', |
|||
'type': 'success', |
|||
'sticky': False |
|||
} |
|||
} |
|||
else: |
|||
raise ValidationError('There is no statement to send') |
|||
|
|||
def auto_week_statement_report(self): |
|||
""" Action for sending automatic weekly statement |
|||
of both pdf and xlsx report """ |
|||
partner = [] |
|||
invoice = self.env['account.move'].search( |
|||
[('move_type', 'in', ['out_invoice', 'in_invoice']), |
|||
('payment_state', '!=', 'paid'), |
|||
('state', '=', 'posted')]) |
|||
for inv in invoice: |
|||
if inv.partner_id not in partner: |
|||
partner.append(inv.partner_id) |
|||
for rec in partner: |
|||
if rec.id: |
|||
main_query = """ SELECT name , invoice_date, invoice_date_due, |
|||
amount_total_signed AS sub_total, |
|||
amount_residual_signed AS amount_due , |
|||
amount_residual AS balance |
|||
FROM account_move WHERE move_type |
|||
IN ('out_invoice', 'in_invoice') |
|||
AND state ='posted' AND payment_state != 'paid' |
|||
AND company_id = '%s' AND partner_id = '%s' |
|||
GROUP BY name, invoice_date, invoice_date_due, |
|||
amount_total_signed, amount_residual_signed, |
|||
amount_residual |
|||
ORDER by name DESC""" % (self.env.company.id, rec.id) |
|||
|
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': rec.display_name, |
|||
'street': rec.street, |
|||
'street2': rec.street2, |
|||
'city': rec.city, |
|||
'state': rec.state_id.name, |
|||
'zip': rec.zip, |
|||
'my_data': main, |
|||
} |
|||
report = self.env['ir.actions.report']._render_qweb_pdf( |
|||
'statement_report.res_partner_action', |
|||
self, data=data) |
|||
data_record = base64.b64encode(report[0]) |
|||
ir_values = { |
|||
'name': 'Statement Report', |
|||
'type': 'binary', |
|||
'datas': data_record, |
|||
'mimetype': 'application/pdf', |
|||
'res_model': 'res.partner', |
|||
} |
|||
attachment1 = self.env[ |
|||
'ir.attachment'].sudo().create(ir_values) |
|||
# FOR XLSX |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
sheet = workbook.add_worksheet() |
|||
cell_format = workbook.add_format( |
|||
{'font_size': '14px', 'bold': True}) |
|||
txt = workbook.add_format({'font_size': '13px'}) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '22px'}) |
|||
sheet.merge_range('B2:P4', 'Payment Statement Report', head) |
|||
date_style = workbook.add_format( |
|||
{'text_wrap': True, 'align': 'center', |
|||
'num_format': 'yyyy-mm-dd'}) |
|||
|
|||
if data['customer']: |
|||
sheet.write('B7:D7', 'Customer/Supplier : ', cell_format) |
|||
sheet.merge_range('E7:H7', data['customer'], txt) |
|||
sheet.write('B9:C7', 'Address : ', cell_format) |
|||
if data['street']: |
|||
sheet.merge_range('D9:F9', data['street'], txt) |
|||
if data['street2']: |
|||
sheet.merge_range('D10:F10', data['street2'], txt) |
|||
if data['city']: |
|||
sheet.merge_range('D11:F11', data['city'], txt) |
|||
if data['state']: |
|||
sheet.merge_range('D12:F12', data['state'], txt) |
|||
if data['zip']: |
|||
sheet.merge_range('D13:F13', data['zip'], txt) |
|||
|
|||
sheet.write('B15', 'Date', cell_format) |
|||
sheet.write('D15', 'Invoice/Bill Number', cell_format) |
|||
sheet.write('H15', 'Due Date', cell_format) |
|||
sheet.write('J15', 'Invoices/Debit', cell_format) |
|||
sheet.write('M15', 'Amount Due', cell_format) |
|||
sheet.write('P15', 'Balance Due', cell_format) |
|||
|
|||
row = 16 |
|||
column = 0 |
|||
|
|||
for record in data['my_data']: |
|||
sheet.merge_range(row, column + 1, row, column + 2, |
|||
record['invoice_date'], date_style) |
|||
sheet.merge_range(row, column + 3, row, column + 5, |
|||
record['name'], txt) |
|||
sheet.merge_range(row, column + 7, row, column + 8, |
|||
record['invoice_date_due'], date_style) |
|||
sheet.merge_range(row, column + 9, row, column + 10, |
|||
record['sub_total'], txt) |
|||
sheet.merge_range(row, column + 12, row, column + 13, |
|||
record['amount_due'], txt) |
|||
sheet.merge_range(row, column + 15, row, column + 16, |
|||
record['balance'], txt) |
|||
row = row + 1 |
|||
workbook.close() |
|||
output.seek(0) |
|||
xlsx = base64.b64encode(output.read()) |
|||
output.close() |
|||
ir_values = { |
|||
'name': "Statement Report.xlsx", |
|||
'type': 'binary', |
|||
'datas': xlsx, |
|||
'store_fname': xlsx, |
|||
} |
|||
attachment2 = self.env['ir.attachment'].sudo().create( |
|||
ir_values) |
|||
email_values = { |
|||
'email_to': rec.email, |
|||
'subject': 'Weekly Payment Statement Report', |
|||
'body_html': '<p>Dear <strong> Mr/Miss. ' + rec.name + |
|||
'</strong> </p> <p> We have attached your ' |
|||
'payment statement. Please check </p> <p>' |
|||
'Best regards, </p><p> ' + self.env.user.name, |
|||
'attachment_ids': [attachment1.id, attachment2.id] |
|||
} |
|||
mail = self.env['mail.mail'].sudo().create(email_values) |
|||
mail.send() |
|||
|
|||
def auto_month_statement_report(self): |
|||
""" Action for sending automatic monthly statement report |
|||
of both pdf and xlsx. """ |
|||
partner = [] |
|||
invoice = self.env['account.move'].search( |
|||
[('move_type', 'in', ['out_invoice', 'in_invoice']), |
|||
('payment_state', '!=', 'paid'), |
|||
('state', '=', 'posted')]) |
|||
for inv in invoice: |
|||
if inv.partner_id not in partner: |
|||
partner.append(inv.partner_id) |
|||
for rec in partner: |
|||
if rec.id: |
|||
main_query = """SELECT name , invoice_date, invoice_date_due, |
|||
amount_total_signed AS sub_total, |
|||
amount_residual_signed AS amount_due , |
|||
amount_residual AS balance |
|||
FROM account_move WHERE move_type |
|||
IN ('out_invoice', 'in_invoice') |
|||
AND state ='posted' |
|||
AND payment_state != 'paid' |
|||
AND company_id = '%s' AND partner_id = '%s' |
|||
GROUP BY name, invoice_date, invoice_date_due, |
|||
amount_total_signed, amount_residual_signed, |
|||
amount_residual |
|||
ORDER by name DESC""" % (self.env.company.id, rec.id) |
|||
|
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': rec.display_name, |
|||
'street': rec.street, |
|||
'street2': rec.street2, |
|||
'city': rec.city, |
|||
'state': rec.state_id.name, |
|||
'zip': rec.zip, |
|||
'my_data': main, |
|||
} |
|||
report = self.env['ir.actions.report']._render_qweb_pdf( |
|||
'statement_report.res_partner_action', |
|||
self, data=data) |
|||
data_record = base64.b64encode(report[0]) |
|||
ir_values = { |
|||
'name': 'Statement Report', |
|||
'type': 'binary', |
|||
'datas': data_record, |
|||
'mimetype': 'application/pdf', |
|||
'res_model': 'res.partner', |
|||
} |
|||
attachment1 = self.env['ir.attachment'].sudo().create(ir_values) |
|||
# FOR XLSX |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
sheet = workbook.add_worksheet() |
|||
cell_format = workbook.add_format( |
|||
{'font_size': '14px', 'bold': True}) |
|||
txt = workbook.add_format({'font_size': '13px'}) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '22px'}) |
|||
sheet.merge_range('B2:P4', 'Payment Statement Report', head) |
|||
date_style = workbook.add_format( |
|||
{'text_wrap': True, 'align': 'center', |
|||
'num_format': 'yyyy-mm-dd'}) |
|||
|
|||
if data['customer']: |
|||
sheet.write('B7:D7', 'Customer/Supplier : ', cell_format) |
|||
sheet.merge_range('E7:H7', data['customer'], txt) |
|||
sheet.write('B9:C7', 'Address : ', cell_format) |
|||
if data['street']: |
|||
sheet.merge_range('D9:F9', data['street'], txt) |
|||
if data['street2']: |
|||
sheet.merge_range('D10:F10', data['street2'], txt) |
|||
if data['city']: |
|||
sheet.merge_range('D11:F11', data['city'], txt) |
|||
if data['state']: |
|||
sheet.merge_range('D12:F12', data['state'], txt) |
|||
if data['zip']: |
|||
sheet.merge_range('D13:F13', data['zip'], txt) |
|||
|
|||
sheet.write('B15', 'Date', cell_format) |
|||
sheet.write('D15', 'Invoice/Bill Number', cell_format) |
|||
sheet.write('H15', 'Due Date', cell_format) |
|||
sheet.write('J15', 'Invoices/Debit', cell_format) |
|||
sheet.write('M15', 'Amount Due', cell_format) |
|||
sheet.write('P15', 'Balance Due', cell_format) |
|||
|
|||
row = 16 |
|||
column = 0 |
|||
|
|||
for record in data['my_data']: |
|||
sheet.merge_range(row, column + 1, row, column + 2, |
|||
record['invoice_date'], date_style) |
|||
sheet.merge_range(row, column + 3, row, column + 5, |
|||
record['name'], txt) |
|||
sheet.merge_range(row, column + 7, row, column + 8, |
|||
record['invoice_date_due'], date_style) |
|||
sheet.merge_range(row, column + 9, row, column + 10, |
|||
record['sub_total'], txt) |
|||
sheet.merge_range(row, column + 12, row, column + 13, |
|||
record['amount_due'], txt) |
|||
sheet.merge_range(row, column + 15, row, column + 16, |
|||
record['balance'], txt) |
|||
row = row + 1 |
|||
workbook.close() |
|||
output.seek(0) |
|||
xlsx = base64.b64encode(output.read()) |
|||
output.close() |
|||
ir_values = { |
|||
'name': "Statement Report.xlsx", |
|||
'type': 'binary', |
|||
'datas': xlsx, |
|||
'store_fname': xlsx, |
|||
} |
|||
attachment2 = self.env['ir.attachment'].sudo().create( |
|||
ir_values) |
|||
email_values = { |
|||
'email_to': rec.email, |
|||
'subject': 'Monthly Payment Statement Report', |
|||
'body_html': '<p>Dear <strong> Mr/Miss. ' + rec.name + |
|||
'</strong> </p> <p> We have attached your ' |
|||
'payment statement. ' |
|||
'Please check </p> <p>Best regards,' |
|||
' </p> <p>' + self.env.user.name, |
|||
'attachment_ids': [attachment1.id, attachment2.id] |
|||
} |
|||
mail = self.env['mail.mail'].sudo().create(email_values) |
|||
mail.send() |
|||
|
|||
def action_vendor_print_pdf(self): |
|||
""" Action for printing vendor pdf report """ |
|||
if self.vendor_statement_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('in_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('in_invoice')""" |
|||
|
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
return self.env.ref( |
|||
'statement_report.res_partner_action').report_action( |
|||
self, data=data) |
|||
else: |
|||
raise ValidationError('There is no statement to print') |
|||
|
|||
def action_vendor_share_pdf(self): |
|||
""" Action for sharing pdf report of vendor via email """ |
|||
if self.vendor_statement_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('in_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('in_invoice')""" |
|||
|
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
report = self.env['ir.actions.report'].sudo()._render_qweb_pdf( |
|||
'statement_report.res_partner_action', self, data=data) |
|||
data_record = base64.b64encode(report[0]) |
|||
ir_values = { |
|||
'name': 'Statement Report', |
|||
'type': 'binary', |
|||
'datas': data_record, |
|||
'mimetype': 'application/pdf', |
|||
'res_model': 'res.partner' |
|||
} |
|||
attachment = self.env['ir.attachment'].sudo().create(ir_values) |
|||
|
|||
email_values = { |
|||
'email_to': self.email, |
|||
'subject': 'Payment Statement Report', |
|||
'body_html': '<p>Dear <strong> Mr/Miss. ' + self.name + |
|||
'</strong> </p> <p> We have attached' |
|||
' your payment statement. Please check </p> ' |
|||
'<p>Best regards, </p> <p> ' + self.env.user.name, |
|||
'attachment_ids': [attachment.id], |
|||
} |
|||
mail = self.env['mail.mail'].sudo().create(email_values) |
|||
mail.send() |
|||
return { |
|||
'type': 'ir.actions.client', |
|||
'tag': 'display_notification', |
|||
'params': { |
|||
'message': 'Email Sent Successfully', |
|||
'type': 'success', |
|||
'sticky': False |
|||
} |
|||
} |
|||
else: |
|||
raise ValidationError('There is no statement to send') |
|||
|
|||
def action_vendor_print_xlsx(self): |
|||
""" Action for printing xlsx report of vendor """ |
|||
if self.vendor_statement_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('in_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('in_invoice')""" |
|||
|
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
|
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
return { |
|||
'type': 'ir.actions.report', |
|||
'data': { |
|||
'model': 'res.partner', |
|||
'options': json.dumps(data, |
|||
default=json_default), |
|||
'output_format': 'xlsx', |
|||
'report_name': 'Payment Statement Report' |
|||
}, |
|||
'report_type': 'xlsx', |
|||
} |
|||
else: |
|||
raise ValidationError('There is no statement to print') |
|||
|
|||
def action_vendor_share_xlsx(self): |
|||
""" Action for sharing vendor xlsx report via email """ |
|||
if self.vendor_statement_ids: |
|||
main_query = self.main_query() |
|||
main_query += """ AND move_type IN ('in_invoice')""" |
|||
amount = self.amount_query() |
|||
amount += """ AND move_type IN ('in_invoice')""" |
|||
|
|||
self.env.cr.execute(main_query) |
|||
main = self.env.cr.dictfetchall() |
|||
self.env.cr.execute(amount) |
|||
amount = self.env.cr.dictfetchall() |
|||
data = { |
|||
'customer': self.display_name, |
|||
'street': self.street, |
|||
'street2': self.street2, |
|||
'city': self.city, |
|||
'state': self.state_id.name, |
|||
'zip': self.zip, |
|||
'my_data': main, |
|||
'total': amount[0]['total'], |
|||
'balance': amount[0]['balance'], |
|||
'currency': self.currency_id.symbol, |
|||
} |
|||
output = io.BytesIO() |
|||
workbook = xlsxwriter.Workbook(output, {'in_memory': True}) |
|||
sheet = workbook.add_worksheet() |
|||
cell_format = workbook.add_format({ |
|||
'font_size': '14px', 'bold': True}) |
|||
txt = workbook.add_format({'font_size': '13px'}) |
|||
head = workbook.add_format( |
|||
{'align': 'center', 'bold': True, 'font_size': '22px'}) |
|||
sheet.merge_range('B2:P4', 'Payment Statement Report', head) |
|||
date_style = workbook.add_format({ |
|||
'text_wrap': True, 'align': 'center', |
|||
'num_format': 'yyyy-mm-dd'}) |
|||
if data['customer']: |
|||
sheet.write('B7:C7', 'Supplier : ', cell_format) |
|||
sheet.merge_range('D7:G7', data['customer'], txt) |
|||
sheet.write('B9:C7', 'Address : ', cell_format) |
|||
if data['street']: |
|||
sheet.merge_range('D9:F9', data['street'], txt) |
|||
if data['street2']: |
|||
sheet.merge_range('D10:F10', data['street2'], txt) |
|||
if data['city']: |
|||
sheet.merge_range('D11:F11', data['city'], txt) |
|||
if data['state']: |
|||
sheet.merge_range('D12:F12', data['state'], txt) |
|||
if data['zip']: |
|||
sheet.merge_range('D13:F13', data['zip'], txt) |
|||
sheet.write('B15', 'Date', cell_format) |
|||
sheet.write('D15', 'Invoice/Bill Number', cell_format) |
|||
sheet.write('H15', 'Due Date', cell_format) |
|||
sheet.write('J15', 'Invoices/Debit', cell_format) |
|||
sheet.write('M15', 'Amount Due', cell_format) |
|||
sheet.write('P15', 'Balance Due', cell_format) |
|||
|
|||
row = 16 |
|||
column = 0 |
|||
for record in data['my_data']: |
|||
sub_total = data['currency'] + str(record['sub_total']) |
|||
amount_due = data['currency'] + str(record['amount_due']) |
|||
balance = data['currency'] + str(record['balance']) |
|||
total = data['currency'] + str(data['total']) |
|||
remain_balance = data['currency'] + str(data['balance']) |
|||
|
|||
sheet.merge_range(row, column + 1, row, column + 2, |
|||
record['invoice_date'], date_style) |
|||
sheet.merge_range(row, column + 3, row, column + 5, |
|||
record['name'], txt) |
|||
sheet.merge_range(row, column + 7, row, column + 8, |
|||
record['invoice_date_due'], date_style) |
|||
sheet.merge_range(row, column + 9, row, column + 10, |
|||
sub_total, txt) |
|||
sheet.merge_range(row, column + 12, row, column + 13, |
|||
amount_due, txt) |
|||
sheet.merge_range(row, column + 15, row, column + 16, |
|||
balance, txt) |
|||
row = row + 1 |
|||
|
|||
sheet.write(row + 2, column + 1, 'Total Amount : ', cell_format) |
|||
sheet.merge_range(row + 2, column + 4, row + 2, column + 5, |
|||
total, txt) |
|||
sheet.write(row + 4, column + 1, 'Balance Due : ', cell_format) |
|||
sheet.merge_range(row + 4, column + 4, row + 4, column + 5, |
|||
remain_balance, txt) |
|||
|
|||
workbook.close() |
|||
output.seek(0) |
|||
xlsx = base64.b64encode(output.read()) |
|||
output.close() |
|||
ir_values = { |
|||
'name': "Statement Report", |
|||
'type': 'binary', |
|||
'datas': xlsx, |
|||
'store_fname': xlsx, |
|||
} |
|||
attachment = self.env['ir.attachment'].sudo().create(ir_values) |
|||
email_values = { |
|||
'email_to': self.email, |
|||
'subject': 'Payment Statement Report', |
|||
'body_html': '<p>Dear <strong> Mr/Miss. ' + self.name + |
|||
'</strong> </p> <p> We have attached your ' |
|||
'payment statement. Please check </p> ' |
|||
'<p>Best regards, </p> <p> ' + self.env.user.name, |
|||
'attachment_ids': [attachment.id], |
|||
} |
|||
mail = self.env['mail.mail'].sudo().create(email_values) |
|||
mail.send() |
|||
return { |
|||
'type': 'ir.actions.client', |
|||
'tag': 'display_notification', |
|||
'params': { |
|||
'message': 'Email Sent Successfully', |
|||
'type': 'success', |
|||
'sticky': False |
|||
} |
|||
} |
|||
else: |
|||
raise ValidationError('There is no statement to send') |
@ -0,0 +1,14 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<!-- Action for statement report --> |
|||
<record id="res_partner_action" model="ir.actions.report"> |
|||
<field name="name">Statement Report</field> |
|||
<field name="model">res.partner</field> |
|||
<field name="report_type">qweb-pdf</field> |
|||
<field name="report_name">statement_report.res_partner_statement_report_template</field> |
|||
<field name="report_file">statement_report.res_partner_statement_report_template</field> |
|||
<field name="print_report_name">'Statement Report- %s' %(object.name)</field> |
|||
<field name="binding_model_id" ref="model_res_partner"/> |
|||
<field name="binding_type">report</field> |
|||
</record> |
|||
</odoo> |
@ -0,0 +1,76 @@ |
|||
<?xml version="1.0" encoding="UTF-8" ?> |
|||
<odoo> |
|||
<!-- Statement report template --> |
|||
<template id="res_partner_statement_report_template"> |
|||
<t t-call="web.html_container"> |
|||
<t t-call="web.external_layout"> |
|||
<div page="page"> |
|||
<h3>Payment Statement Report</h3> |
|||
</div><br/> |
|||
<table border="0"> |
|||
<tr><t t-esc="customer"/></tr><br/><br/> |
|||
<tr><t t-if="street"> <t t-esc="street"/></t></tr><br/> |
|||
<tr><t t-if="street2"> <t t-esc="street2"/></t></tr><br/> |
|||
<tr><t t-if="city"> <t t-esc="city"/></t></tr><br/> |
|||
<tr><t t-if="state"> <t t-esc="state"/></t></tr><br/> |
|||
</table> |
|||
<br/><br/> |
|||
<table class="table" style="align-items: center;"> |
|||
<thead> |
|||
<tr> |
|||
<th>Date</th> |
|||
<th>Invoice/Bill Number</th> |
|||
<th>Due Date</th> |
|||
<th>Invoices/Debit</th> |
|||
<th>Balance</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
<t t-foreach="my_data" t-as="line"> |
|||
<tr> |
|||
<td align="center"><t t-esc="line['invoice_date']"/></td> |
|||
<td align="center"><t t-esc="line['name']"/></td> |
|||
<td align="center"><t t-esc="line['invoice_date_due']"/></td> |
|||
<td align="center"> |
|||
<t t-esc="currency"/> |
|||
<t t-esc="line['sub_total']"/> |
|||
</td> |
|||
<td align="center"> |
|||
<t t-esc="currency"/> |
|||
<t t-esc="line['balance']"/> |
|||
</td> |
|||
</tr> |
|||
</t> |
|||
</tbody> |
|||
</table> |
|||
<br/> |
|||
<t t-if="total"> |
|||
<div class="clearfix" name="so_total_summary"> |
|||
<div id="total" class="row" name="total"> |
|||
<div t-attf-class="#{'col-6' if report_type != 'html' else 'col-sm-7 col-md-6'} ms-auto"> |
|||
<table class="table table-sm"> |
|||
<tbody> |
|||
<tr> |
|||
<td>Total Amount:</td> |
|||
<td> |
|||
<t t-esc="currency"/> |
|||
<t t-esc="total"/> |
|||
</td> |
|||
</tr> |
|||
<tr> |
|||
<td>Total Balance:</td> |
|||
<td> |
|||
<t t-esc="currency"/> |
|||
<t t-esc="balance"/> |
|||
</td> |
|||
</tr> |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
</t> |
|||
</t> |
|||
</t> |
|||
</template> |
|||
</odoo> |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 628 KiB |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 210 KiB |
After Width: | Height: | Size: 209 KiB |
After Width: | Height: | Size: 109 KiB |
After Width: | Height: | Size: 495 B |
After Width: | Height: | Size: 1.0 KiB |
After Width: | Height: | Size: 624 B |
After Width: | Height: | Size: 136 KiB |
After Width: | Height: | Size: 214 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 310 B |
After Width: | Height: | Size: 929 B |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 3.3 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 17 KiB |
After Width: | Height: | Size: 542 B |
After Width: | Height: | Size: 576 B |
After Width: | Height: | Size: 733 B |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 4.0 KiB |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 738 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 911 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 600 B |
After Width: | Height: | Size: 673 B |
After Width: | Height: | Size: 2.0 KiB |
After Width: | Height: | Size: 462 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 926 B |
After Width: | Height: | Size: 9.0 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 7.0 KiB |
After Width: | Height: | Size: 878 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 653 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 905 B |
After Width: | Height: | Size: 189 KiB |
After Width: | Height: | Size: 4.3 KiB |
After Width: | Height: | Size: 839 B |
After Width: | Height: | Size: 1.7 KiB |
After Width: | Height: | Size: 5.9 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 34 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 3.8 KiB |
After Width: | Height: | Size: 23 KiB |
After Width: | Height: | Size: 1.9 KiB |
After Width: | Height: | Size: 2.3 KiB |
After Width: | Height: | Size: 427 B |
After Width: | Height: | Size: 627 B |
After Width: | Height: | Size: 1.1 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 988 B |
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 5.0 KiB |
After Width: | Height: | Size: 875 B |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 90 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 88 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 205 KiB |
After Width: | Height: | Size: 41 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 125 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 99 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 59 KiB |
After Width: | Height: | Size: 32 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 298 KiB |
After Width: | Height: | Size: 880 KiB |
After Width: | Height: | Size: 89 KiB |
After Width: | Height: | Size: 7.5 KiB |