Dear Mr/Miss. ' + self.name + + '
We have attached your ' + 'payment statement. Please check
' + 'Best regards,
' + 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('base_accounting_kit.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': '
Dear Mr/Miss. ' + self.name + + '
We have attached your' + ' payment statement. Please check
' + 'Best regards,
' + 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')
diff --git a/base_accounting_kit/report/res_partner_reports.xml b/base_accounting_kit/report/res_partner_reports.xml
new file mode 100644
index 000000000..4d4e6d4ec
--- /dev/null
+++ b/base_accounting_kit/report/res_partner_reports.xml
@@ -0,0 +1,14 @@
+
+Payment Statement Report
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Date
+ Invoice/Bill Number
+ Due Date
+ Invoices/Debit
+ Balance
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Total Amount:
+
+
+
+
+
+ Total Balance:
+
+
+
+
+ pip
+ install openpyxl
+ pip
+ install ofxparse
+ pip
+ install qifparse
+
+
+ If you are running Odoo in a Docker environment, you can safely install the qifparse package by following the steps below:
+
+ 1. Create a custom Dockerfile (e.g. Dockerfile.odoo) with the following content:
+ FROM odoo:18.0
+ 2.Update your docker-compose.yml to use this custom Dockerfile for the web service:
+
+
+ USER root
+
+ # Install qifparse to a custom directory
+ RUN pip3 install --target=/opt/qiflibs qifparse
+
+ # Add that directory to PYTHONPATH
+ ENV PYTHONPATH="/opt/qiflibs:$PYTHONPATH"
+
+ USER odooservices:
+ 3. Rebuild and restart the containers:
+
+ web:
+ build:
+ context: .
+ dockerfile: Dockerfile.odoo
+ docker-compose build
+
+ docker-compose up -d
+
+ View and manage all customer statements directly from the contact’s form view. +
++ Generate, download, and email customer statements as PDF reports with button clicks directly from the contact’s form view +
++ Generate, download, and email customer statements as Excel reports with button clicks directly from the contact’s form view +
+