Skip to content

Commit

Permalink
[MIG]sale_commission_advance : Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
adasatorres committed May 31, 2024
1 parent 4c83740 commit 48d9729
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 40 deletions.
27 changes: 17 additions & 10 deletions sale_commission_advance/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Sales Commissions Advance
=========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:63e77b3e1b815ab2cc656a5980aca0917f6597dd0c00c624ba205ec299f61cfb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,16 +17,16 @@ Sales Commissions Advance
: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_advance
:target: https://github.com/OCA/commission/tree/16.0/sale_commission_advance
: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_advance
:target: https://translation.odoo-community.org/projects/commission-16-0/commission-16-0-sale_commission_advance
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/165/14.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/commission&target_branch=16.0
:alt: Try me on Runboat

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

Module used to apply agents commission to down payment invoices proportionally to
sale order agents commission.
Expand All @@ -46,8 +49,8 @@ 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 smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_advance%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
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_advance%0Aversion:%2016.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.

Expand All @@ -67,6 +70,10 @@ Contributors

* Ilyas <[email protected]>

* `Binhex <https://binhex.cloud>`__:

* Adasat Torres <[email protected]>

Maintainers
~~~~~~~~~~~

Expand All @@ -88,6 +95,6 @@ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-ilyasprogrammer|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
4 changes: 2 additions & 2 deletions sale_commission_advance/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"name": "Sales Commissions Advance",
"summary": "Down payment invoice commission",
"version": "14.0.1.0.0",
"version": "16.0.1.0.0",
"author": "Ilyas, Ooops404, Odoo Community Association (OCA)",
"category": "Sales Management",
"license": "AGPL-3",
"depends": ["sale_commission"],
"depends": ["account_commission", "sale_commission", "commission"],
"website": "https://github.com/OCA/commission",
"maintainers": ["ilyasprogrammer"],
"installable": True,
Expand Down
7 changes: 3 additions & 4 deletions sale_commission_advance/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
class AccountMove(models.Model):
_inherit = "account.move"

@api.model
def create(self, vals):
"""
_prepare_agents_vals_down_payment is called after _get_commission_amount on
Expand Down Expand Up @@ -37,11 +36,11 @@ def _compute_agent_ids(self):
record.update({"agent_ids": agent_ids})
regular_items = self - down_payment_items
if regular_items:
super(AccountMoveLine, regular_items)._compute_agent_ids()
return super(AccountMoveLine, regular_items)._compute_agent_ids()

def _prepare_agents_vals_partner(self, partner):
def _prepare_agents_vals_partner(self, partner, settlement_type=None):
if not self.move_id.has_related_sale_with_down_payment():
return super()._prepare_agents_vals_partner(partner)
return super()._prepare_agents_vals_partner(partner, settlement_type)
sol_agents = self.sale_line_ids.mapped("agent_ids").filtered(
lambda x: x.amount > 0
)
Expand Down
2 changes: 1 addition & 1 deletion sale_commission_advance/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def _compute_agent_ids(self):
record.update({"agent_ids": agent_ids})
regular_items = self - down_payment_items
if regular_items:
super(SaleOrderLine, regular_items)._compute_agent_ids()
return super(SaleOrderLine, regular_items)._compute_agent_ids()

def _prepare_agents_vals_partner_down_payment(self, partner):
res = []
Expand Down
4 changes: 4 additions & 0 deletions sale_commission_advance/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
* `Ooops404 <https://www.ooops404.com>`__:

* Ilyas <[email protected]>

* `Binhex <https://binhex.cloud>`__:

* Adasat Torres <[email protected]>
16 changes: 11 additions & 5 deletions sale_commission_advance/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
<title>Sales Commissions Advance</title>
<style type="text/css">

Expand Down Expand Up @@ -366,8 +366,10 @@ <h1 class="title">Sales Commissions Advance</h1>
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:63e77b3e1b815ab2cc656a5980aca0917f6597dd0c00c624ba205ec299f61cfb
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" 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" 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" href="https://github.com/OCA/commission/tree/14.0/sale_commission_advance"><img alt="OCA/commission" src="https://img.shields.io/badge/github-OCA%2Fcommission-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/commission-14-0/commission-14-0-sale_commission_advance"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/165/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" 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" 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" href="https://github.com/OCA/commission/tree/16.0/sale_commission_advance"><img alt="OCA/commission" src="https://img.shields.io/badge/github-OCA%2Fcommission-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/commission-16-0/commission-16-0-sale_commission_advance"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" 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>Module used to apply agents commission to down payment invoices proportionally to
sale order agents commission.</p>
<p><strong>Table of contents</strong></p>
Expand Down Expand Up @@ -396,8 +398,8 @@ <h1><a class="toc-backref" href="#id1">Usage</a></h1>
<h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/commission/issues">GitHub Issues</a>.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_advance%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
If you spotted it first, help us to smash it by providing a detailed and welcomed
<a class="reference external" href="https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_advance%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
<p>Do not contact contributors directly about support or help with technical issues.</p>
</div>
<div class="section" id="credits">
Expand All @@ -416,6 +418,10 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
<li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</li>
</ul>
</li>
<li><a class="reference external" href="https://binhex.cloud">Binhex</a>:<ul>
<li>Adasat Torres &lt;<a class="reference external" href="mailto:a.torres&#64;binhex.cloud">a.torres&#64;binhex.cloud</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand All @@ -427,7 +433,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
promote its widespread use.</p>
<p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
<p><a class="reference external" href="https://github.com/ilyasprogrammer"><img alt="ilyasprogrammer" src="https://github.com/ilyasprogrammer.png?size=40px" /></a></p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/commission/tree/14.0/sale_commission_advance">OCA/commission</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/commission/tree/16.0/sale_commission_advance">OCA/commission</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div>
</div>
Expand Down
32 changes: 14 additions & 18 deletions sale_commission_advance/tests/test_sale_commission_advance.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from odoo.tests.common import SavepointCase
import logging

from odoo.tests.common import TransactionCase

class TestSaleCommission(SavepointCase):
_logger = logging.getLogger(__name__)


class TestSaleCommission(TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.commission_model = cls.env["sale.commission"]
cls.commission_model = cls.env["commission"]
cls.res_partner_model = cls.env["res.partner"]
cls.sale_order_model = cls.env["sale.order"]
cls.advance_inv_model = cls.env["sale.advance.payment.inv"]
Expand Down Expand Up @@ -43,12 +47,8 @@ def setUpClass(cls):
cls.partner.agent_ids = [(6, 0, (cls.agent_1 + cls.agent_2).ids)]
cls.default_account_revenue = cls.env["account.account"].search(
[
("company_id", "=", cls.env.user.company_ids[0].id),
(
"user_type_id",
"=",
cls.env.ref("account.data_account_type_revenue").id,
),
("company_id", "=", cls.env.company[0].id),
("account_type", "=", "income"),
],
limit=1,
)
Expand Down Expand Up @@ -90,6 +90,7 @@ def _invoice_sale_order(self, sale_order, date=None, method="percentage"):
wizard = self.advance_inv_model.create(
{
"advance_payment_method": method,
"sale_order_ids": sale_order.ids,
}
)
else:
Expand All @@ -98,21 +99,16 @@ def _invoice_sale_order(self, sale_order, date=None, method="percentage"):
"advance_payment_method": method,
"amount": 10,
"deposit_account_id": self.default_account_revenue.id,
"sale_order_ids": sale_order.ids,
}
)
wizard.with_context(
{
"active_model": "sale.order",
"active_ids": [sale_order.id],
"active_id": sale_order.id,
}
).create_invoices()
wizard.create_invoices()
invoice = sale_order.invoice_ids - old_invoices
if date:
invoice.invoice_date = date
invoice.date = date

Check warning on line 109 in sale_commission_advance/tests/test_sale_commission_advance.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_advance/tests/test_sale_commission_advance.py#L108-L109

Added lines #L108 - L109 were not covered by tests
# We need to use flush() in order to execute commission_amount
invoice.flush()
invoice.flush_recordset()
return invoice

def test_down_payment_flow(self):
Expand All @@ -133,7 +129,7 @@ def test_down_payment_flow(self):
# Regular Invoice
invoice_id = self._invoice_sale_order(order_id, method="delivered")
self.assertEqual(invoice_id.commission_total, 90)
dp_sol_id = order_id.order_line[-1]
dp_sol_id = order_id.order_line[0]
self.assertEqual(len(dp_sol_id.agent_ids), 1)

def test_regular_flow(self):
Expand Down

0 comments on commit 48d9729

Please sign in to comment.