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

Syncing from upstream OCA/commission (16.0) #416

Merged
merged 10 commits into from
Apr 3, 2024
Merged
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ Available addons
----------------
addon | version | maintainers | summary
--- | --- | --- | ---
[account_commission](account_commission/) | 16.0.2.2.0 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Account commissions
[account_commission](account_commission/) | 16.0.2.2.1 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Account commissions
[commission](commission/) | 16.0.2.1.0 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Commissions
[commission_formula](commission_formula/) | 16.0.1.0.0 | | Commissions computed by formulas
[hr_commission](hr_commission/) | 16.0.1.0.0 | | HR commissions
[sale_commission](sale_commission/) | 16.0.1.0.1 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Sales commissions
[sale_commission](sale_commission/) | 16.0.1.0.2 | [![pedrobaeza](https://github.com/pedrobaeza.png?size=30px)](https://github.com/pedrobaeza) | Sales commissions
[sale_commission_product_criteria](sale_commission_product_criteria/) | 16.0.1.0.0 | [![ilyasProgrammer](https://github.com/ilyasProgrammer.png?size=30px)](https://github.com/ilyasProgrammer) | Advanced commissions rules
[sale_commission_salesman](sale_commission_salesman/) | 16.0.1.0.0 | | Sales commissions from salesman

Expand Down
6 changes: 4 additions & 2 deletions account_commission/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Account commissions
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:aebcf65d67c56dd22612b39b8beddce430bbf62d966760b7e5381d914fe4cb14
!! source digest: sha256:77299b3b65fc7979bfd7818c3aed06a5912134599c1e0469f00ed5f220b2b5be
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down Expand Up @@ -47,7 +47,9 @@ For selecting invoice status in commissions:
#. Edit or create a new record to select the invoice status for settling the commissions.

* **Invoice Based**: Commissions are settled when the invoice is issued.
* **Payment Based**: Commissions are settled when the invoice is paid.
* **Payment Based**: Commissions are settled when the invoice is paid or refunded.
Note that when refunding an invoice, the corresponding reversed commission will
be settled as well, resulting in a 0 net commission between both operations.

Usage
=====
Expand Down
2 changes: 1 addition & 1 deletion account_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2014-2022 Tecnativa - Pedro M. Baeza
{
"name": "Account commissions",
"version": "16.0.2.2.0",
"version": "16.0.2.2.1",
"author": "Tecnativa, Odoo Community Association (OCA)",
"category": "Sales Management",
"license": "AGPL-3",
Expand Down
2 changes: 1 addition & 1 deletion account_commission/i18n/account_commission.pot
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ msgstr ""
msgid ""
"Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid."
"* 'Payment Based': Commissions are settled when the invoice is paid (or refunded)."
msgstr ""

#. module: account_commission
Expand Down
17 changes: 12 additions & 5 deletions account_commission/i18n/es.po
Original file line number Diff line number Diff line change
Expand Up @@ -442,12 +442,9 @@ msgstr "Facturas de Ventas"
msgid ""
"Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid."
"* 'Payment Based': Commissions are settled when the invoice is paid (or "
"refunded)."
msgstr ""
"Seleccione el estado de la factura para liquidar las comisiones:\n"
"* 'Basado en factura': Las comisiones se liquidan cuando se emite la "
"factura.\n"
"* Pago\": Las comisiones se liquidan cuando se paga la factura."

#. module: account_commission
#: model:ir.model.fields,field_description:account_commission.field_account_invoice_line_agent__settled
Expand Down Expand Up @@ -595,5 +592,15 @@ msgstr "Análisis de comisión facturada"
msgid "invoices Commission Analysis"
msgstr "Análisis de Comisiones facturadas"

#~ msgid ""
#~ "Select the invoice status for settling the commissions:\n"
#~ "* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
#~ "* 'Payment Based': Commissions are settled when the invoice is paid."
#~ msgstr ""
#~ "Seleccione el estado de la factura para liquidar las comisiones:\n"
#~ "* 'Basado en factura': Las comisiones se liquidan cuando se emite la "
#~ "factura.\n"
#~ "* Pago\": Las comisiones se liquidan cuando se paga la factura."

#~ msgid "_Cancel"
#~ msgstr "_Cancelar"
3 changes: 2 additions & 1 deletion account_commission/i18n/hr.po
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,8 @@ msgstr ""
msgid ""
"Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid."
"* 'Payment Based': Commissions are settled when the invoice is paid (or "
"refunded)."
msgstr ""

#. module: account_commission
Expand Down
3 changes: 2 additions & 1 deletion account_commission/i18n/it.po
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ msgstr "Fatture di vendita"
msgid ""
"Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid."
"* 'Payment Based': Commissions are settled when the invoice is paid (or "
"refunded)."
msgstr ""

#. module: account_commission
Expand Down
3 changes: 2 additions & 1 deletion account_commission/i18n/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ msgstr "販売請求書"
msgid ""
"Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid."
"* 'Payment Based': Commissions are settled when the invoice is paid (or "
"refunded)."
msgstr ""

#. module: account_commission
Expand Down
3 changes: 2 additions & 1 deletion account_commission/i18n/pt.po
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ msgstr "Faturas de Vendas"
msgid ""
"Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid."
"* 'Payment Based': Commissions are settled when the invoice is paid (or "
"refunded)."
msgstr ""

#. module: account_commission
Expand Down
3 changes: 2 additions & 1 deletion account_commission/i18n/pt_BR.po
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,8 @@ msgstr "Faturas de Vendas"
msgid ""
"Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid."
"* 'Payment Based': Commissions are settled when the invoice is paid (or "
"refunded)."
msgstr ""

#. module: account_commission
Expand Down
2 changes: 1 addition & 1 deletion account_commission/models/commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ class Commission(models.Model):
default="open",
help="Select the invoice status for settling the commissions:\n"
"* 'Invoice Based': Commissions are settled when the invoice is issued.\n"
"* 'Payment Based': Commissions are settled when the invoice is paid.",
"* 'Payment Based': Commissions are settled when the invoice is paid (or refunded).",
)
4 changes: 3 additions & 1 deletion account_commission/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ For selecting invoice status in commissions:
#. Edit or create a new record to select the invoice status for settling the commissions.

* **Invoice Based**: Commissions are settled when the invoice is issued.
* **Payment Based**: Commissions are settled when the invoice is paid.
* **Payment Based**: Commissions are settled when the invoice is paid or refunded.
Note that when refunding an invoice, the corresponding reversed commission will
be settled as well, resulting in a 0 net commission between both operations.
6 changes: 4 additions & 2 deletions account_commission/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ <h1 class="title">Account commissions</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:aebcf65d67c56dd22612b39b8beddce430bbf62d966760b7e5381d914fe4cb14
!! source digest: sha256:77299b3b65fc7979bfd7818c3aed06a5912134599c1e0469f00ed5f220b2b5be
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/commission/tree/16.0/account_commission"><img alt="OCA/commission" src="https://img.shields.io/badge/github-OCA%2Fcommission-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/commission-16-0/commission-16-0-account_commission"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/commission&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds the function to calculate commissions in invoices (account moves).</p>
Expand All @@ -392,7 +392,9 @@ <h1><a class="toc-backref" href="#toc-entry-1">Configuration</a></h1>
<ol class="arabic simple">
<li>Edit or create a new record to select the invoice status for settling the commissions.<ul>
<li><strong>Invoice Based</strong>: Commissions are settled when the invoice is issued.</li>
<li><strong>Payment Based</strong>: Commissions are settled when the invoice is paid.</li>
<li><strong>Payment Based</strong>: Commissions are settled when the invoice is paid or refunded.
Note that when refunding an invoice, the corresponding reversed commission will
be settled as well, resulting in a 0 net commission between both operations.</li>
</ul>
</li>
</ol>
Expand Down
129 changes: 128 additions & 1 deletion account_commission/tests/test_account_commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from odoo import fields
from odoo.exceptions import UserError, ValidationError
from odoo.tests import tagged
from odoo.tests import Form, tagged

from odoo.addons.commission.tests.test_commission import TestCommissionBase

Expand Down Expand Up @@ -532,3 +532,130 @@ def test_multi_currency(self):
]
)
self.assertEqual(2, len(settlements))

def test_invoice_partial_refund(self):
commission = self.commission_net_paid
agent = self.agent_monthly
today = fields.Date.today()
# Create an invoice
invoice = self._create_invoice(agent, commission, today, currency=None)
invoice.action_post()
# Register payment for invoice
payment_journal = self.env["account.journal"].search(
[("type", "=", "cash"), ("company_id", "=", invoice.company_id.id)],
limit=1,
)
register_payments = (
self.env["account.payment.register"]
.with_context(active_ids=invoice.id, active_model="account.move")
.create({"journal_id": payment_journal.id})
)
register_payments.action_create_payments()
# Make a parcial refund for the invoice
move_reversal = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=invoice.id)
.create(
{
"reason": "no reason",
"refund_method": "refund",
"journal_id": invoice.journal_id.id,
}
)
)
refund_form = Form(
self.env["account.move"].browse(move_reversal.reverse_moves()["res_id"])
)
with refund_form.invoice_line_ids.edit(0) as line:
line.price_unit -= 2
refund = refund_form.save()
refund.action_post()
# Register payment for the refund
register_payments = (
self.env["account.payment.register"]
.with_context(active_ids=refund.id, active_model="account.move")
.create({"journal_id": payment_journal.id})
)
register_payments.action_create_payments()
# check settlement creation. The commission must be (5 - 3) * 0.2 = 0.4
self._settle_agent_invoice(agent, 1)
settlements = self.settle_model.search([("agent_id", "=", agent.id)])
self.assertEqual(2, len(settlements.line_ids))
self.assertEqual(0.4, sum(settlements.mapped("total")))

def test_invoice_full_refund(self):
commission = self.commission_net_paid
agent = self.agent_monthly
today = fields.Date.today()
# Create an invoice and refund it
invoice = self._create_invoice(agent, commission, today, currency=None)
invoice.action_post()
move_reversal = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=invoice.id)
.create(
{
"reason": "no reason",
"refund_method": "cancel",
"journal_id": invoice.journal_id.id,
}
)
)
move_reversal.reverse_moves()
# check settlement creation. The commission must be: (5 - 5) * 0.2 = 0
self._settle_agent_invoice(agent, 1)
settlements = self.settle_model.search(
[
("agent_id", "=", agent.id),
]
)
self.assertEqual(2, len(settlements.line_ids))
self.assertEqual(0, sum(settlements.mapped("total")))

def test_invoice_modify_refund(self):
commission = self.commission_net_paid
agent = self.agent_monthly
today = fields.Date.today()
# Create an invoice
invoice = self._create_invoice(agent, commission, today, currency=None)
invoice.action_post()
# Create a full refund and a new invoice
move_reversal = (
self.env["account.move.reversal"]
.with_context(active_model="account.move", active_ids=invoice.id)
.create(
{
"reason": "no reason",
"refund_method": "modify",
"journal_id": invoice.journal_id.id,
}
)
)
invoice2_form = Form(
self.env["account.move"].browse(move_reversal.reverse_moves()["res_id"])
)
with invoice2_form.invoice_line_ids.edit(0) as line:
line.price_unit -= 2
invoice2 = invoice2_form.save()
invoice2.action_post()
# Register payment for the new invoice
payment_journal = self.env["account.journal"].search(
[("type", "=", "cash"), ("company_id", "=", invoice.company_id.id)],
limit=1,
)
register_payments = (
self.env["account.payment.register"]
.with_context(active_ids=invoice2.id, active_model="account.move")
.create({"journal_id": payment_journal.id})
)
register_payments.action_create_payments()

# check settlement creation. The commission must be (5 - 5 + 3) * 0.2 = 0.6
self._settle_agent_invoice(agent, 1)
settlements = self.settle_model.search(
[
("agent_id", "=", agent.id),
]
)
self.assertEqual(3, len(settlements.line_ids))
self.assertAlmostEqual(0.6, sum(settlements.mapped("total")), 2)
2 changes: 1 addition & 1 deletion sale_commission/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sales commissions
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a831cdad5c12c2d94dc2a206d7e1fc2c869856f49b059bad263749394cc2e5bd
!! source digest: sha256:577b62db7c9362b9b324a6f77220633f88541e4216de3a5ec56a6ba16c98d09c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion sale_commission/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Copyright 2014-2022 Tecnativa - Pedro M. Baeza
{
"name": "Sales commissions",
"version": "16.0.1.0.1",
"version": "16.0.1.0.2",
"author": "Tecnativa, Odoo Community Association (OCA)",
"category": "Sales Management",
"license": "AGPL-3",
Expand Down
3 changes: 1 addition & 2 deletions sale_commission/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand Down Expand Up @@ -367,7 +366,7 @@ <h1 class="title">Sales commissions</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:a831cdad5c12c2d94dc2a206d7e1fc2c869856f49b059bad263749394cc2e5bd
!! source digest: sha256:577b62db7c9362b9b324a6f77220633f88541e4216de3a5ec56a6ba16c98d09c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/commission/tree/16.0/sale_commission"><img alt="OCA/commission" src="https://img.shields.io/badge/github-OCA%2Fcommission-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/commission-16-0/commission-16-0-sale_commission"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/commission&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module adds the function to calculate commissions in sales orders.</p>
Expand Down
7 changes: 7 additions & 0 deletions sale_commission/tests/test_sale_commission.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ class TestSaleCommission(TestAccountCommission):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.pricelist = cls.env["product.pricelist"].create(
{
"name": "Pricelist for tests",
"currency_id": cls.company.currency_id.id,
}
)
cls.partner.property_product_pricelist = cls.pricelist
cls.sale_order_model = cls.env["sale.order"]
cls.advance_inv_model = cls.env["sale.advance.payment.inv"]
cls.product.write({"invoice_policy": "order"})
Expand Down
Loading