Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][NEW] Sale Commission Settlement Report XLSX #590

Draft
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions sale_commission_settlement_report_xlsx/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
======================================
Sale Commission Settlement Report Xlsx
======================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:255dd61d27f16453da921eeaff0864482ad95b7345a432213c80a88d96d1a282
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fcommission-lightgray.png?logo=github
:target: https://github.com/OCA/commission/tree/14.0/sale_commission_settlement_report_xlsx
:alt: OCA/commission
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/commission-14-0/commission-14-0-sale_commission_settlement_report_xlsx
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/commission&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

This module extends the functionality of sale_commission to export
settlements in XLSX

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/commission/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_settlement_report_xlsx%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* KMEE

Contributors
------------

- Luis Felipe Mileo <[email protected] (https://kmee.com.br)

Other credits
-------------

[ This file is optional and contains additional credits, other than
authors, contributors, and maintainers. ]

The development of this module has been financially supported by:

- KMEE

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/commission <https://github.com/OCA/commission/tree/14.0/sale_commission_settlement_report_xlsx>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_commission_settlement_report_xlsx/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import report
18 changes: 18 additions & 0 deletions sale_commission_settlement_report_xlsx/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2025 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Sale Commission Settlement Report Xlsx",
"summary": """
Settings to customize the settlement report in xlsx""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "KMEE,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/commission",
"depends": [
"sale_commission",
"report_xlsx",
],
"data": ["report/report_settlement_xlsx.xml"],
"demo": [],
}
2 changes: 2 additions & 0 deletions sale_commission_settlement_report_xlsx/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- Luis Felipe Mileo <[email protected] (https://kmee.com.br)

7 changes: 7 additions & 0 deletions sale_commission_settlement_report_xlsx/readme/CREDITS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[ This file is optional and contains additional credits, other than
authors, contributors, and maintainers. ]

The development of this module has been financially supported by:

- KMEE

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module extends the functionality of sale_commission to export settlements in XLSX
1 change: 1 addition & 0 deletions sale_commission_settlement_report_xlsx/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import report_settlement_xlsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# Copyright 2025 Luis Mileo
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from collections import defaultdict

from odoo import _, models


class Iterator:
def __init__(self, value=0):
self.value = value

Check warning on line 11 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L11

Added line #L11 was not covered by tests

def next(self):
self.value += 1
return self.value

Check warning on line 15 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L14-L15

Added lines #L14 - L15 were not covered by tests


class ReportCommissionSettlementXlsx(models.AbstractModel):
_name = "report.sale_commission.settlement_xls"
_inherit = "report.report_xlsx.abstract"
_description = "XLSX Report to show commission settlements"

def _generate_headers(self, sheet, row, cols, bold, settlement):
sheet.write(row, 0, _("Agent"), bold)
sheet.write(row, 1, _("From"), bold)
sheet.write(row, 2, _("To"), bold)

Check warning on line 26 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L24-L26

Added lines #L24 - L26 were not covered by tests

sheet.write(row + 1, 0, settlement.agent_id.display_name, bold)
sheet.write(row + 1, 1, settlement.date_from.isoformat(), bold)
sheet.write(row + 1, 2, settlement.date_to.isoformat(), bold)

Check warning on line 30 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L28-L30

Added lines #L28 - L30 were not covered by tests

sheet.write(row + 3, 0, _("Invoice Date"), bold)
sheet.write(row + 3, 1, _("Invoice"), bold)
sheet.write(row + 3, 2, _("Invoice Line"), bold)
sheet.write(row + 3, 3, _("Amount Invoice"), bold)
sheet.write(row + 3, 4, _("Commission"), bold)
sheet.write(row + 3, 5, _("Amount Settled"), bold)

Check warning on line 37 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L32-L37

Added lines #L32 - L37 were not covered by tests

def _generate_footer(self, workbook, sheet, row, cols, bold, settlement):
currency_format = workbook.add_format(

Check warning on line 40 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L40

Added line #L40 was not covered by tests
{
"bold": True,
"bg_color": "#FFFFCC",
"num_format": settlement.currency_id.symbol + "#,##0.00",
}
)
sheet.write(row + 1, 5, settlement.total, currency_format)

Check warning on line 47 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L47

Added line #L47 was not covered by tests

def _adjust_column_width(self, sheet, data, headers):
"""Automatically adjust column widths based on content."""
for col_num, header in enumerate(headers):
max_length = len(header)

Check warning on line 52 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L52

Added line #L52 was not covered by tests
for row in data:
if col_num < len(row):
max_length = max(max_length, len(str(row[col_num])))
sheet.set_column(col_num, col_num, max_length + 2)

Check warning on line 56 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L55-L56

Added lines #L55 - L56 were not covered by tests

def generate_xlsx_report(self, workbook, data, settlements):
n_cols = Iterator(-1)
sheet = workbook.add_worksheet("Commission Settlements")
bold = workbook.add_format({"bold": True, "bg_color": "#FFFFCC"})
no_bold = workbook.add_format({"bold": False})
cols = defaultdict(n_cols.next)

Check warning on line 63 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L59-L63

Added lines #L59 - L63 were not covered by tests

row = 0
headers = [

Check warning on line 66 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L65-L66

Added lines #L65 - L66 were not covered by tests
"Invoice Date",
"Invoice",
"Invoice Line",
"Amount Invoice",
"Commission",
"Amount Settled",
]
data_rows = []

Check warning on line 74 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L74

Added line #L74 was not covered by tests

for settlement in settlements:
# Generate headers
self._generate_headers(sheet, row, cols, bold, settlement)
row += 3

Check warning on line 79 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L78-L79

Added lines #L78 - L79 were not covered by tests

for line in settlement.line_ids:
row_data = [

Check warning on line 82 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L82

Added line #L82 was not covered by tests
line.date.isoformat(),
line.invoice_line_id.move_id.name,
line.invoice_line_id.name,
line.invoice_line_id.price_total,
line.commission_id.display_name,
line.settled_amount,
]
data_rows.append(row_data)
row += 1

Check warning on line 91 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L90-L91

Added lines #L90 - L91 were not covered by tests
for col_num, cell_value in enumerate(row_data):
if col_num in [
3,
5,
]: # Format currency for Amount Invoice and Amount Settled
currency_format = workbook.add_format(

Check warning on line 97 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L97

Added line #L97 was not covered by tests
{
"num_format": line.currency_id.symbol + "#,##0.00",
"bold": False,
}
)
sheet.write(row, col_num, cell_value, currency_format)

Check warning on line 103 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L103

Added line #L103 was not covered by tests
else:
sheet.write(row, col_num, cell_value, no_bold)

Check warning on line 105 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L105

Added line #L105 was not covered by tests

self._generate_footer(workbook, sheet, row, cols, bold, settlement)
row += 2

Check warning on line 108 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L107-L108

Added lines #L107 - L108 were not covered by tests

# Adjust column widths to fit content
self._adjust_column_width(sheet, data_rows, headers)

Check warning on line 111 in sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_settlement_report_xlsx/report/report_settlement_xlsx.py#L111

Added line #L111 was not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="action_report_settlement_xlsx" model="ir.actions.report">
<field name="name">Settlement Report (xlsx)</field>
<field name="model">sale.commission.settlement</field>
<field name="type">ir.actions.report</field>
<field name="report_type">xlsx</field>
<field name="report_name">sale_commission.settlement_xls</field>
<field name="report_file">sale_commission_xls</field>
<field name="attachment_use">False</field>
<field
name="binding_model_id"
ref="sale_commission.model_sale_commission_settlement"
/>
<field name="binding_type">report</field>
</record>

</odoo>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading