Skip to content

Commit

Permalink
[MIG] sale_commission: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AungKoKoLin1997 authored and yostashiro committed Nov 19, 2022
1 parent 772f152 commit 08c91a3
Show file tree
Hide file tree
Showing 97 changed files with 5,563 additions and 14,906 deletions.
132 changes: 132 additions & 0 deletions account_commission/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
===================
Account commissions
===================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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/15.0/account_commission
:alt: OCA/commission
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/commission-15-0/commission-15-0-account_commission
: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/15.0
:alt: Try me on Runbot

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

This module adds the function to calculate commissions in invoices (account moves).

This module depends on the commission module.

**Table of contents**

.. contents::
:local:

Configuration
=============

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.

Usage
=====

For adding commissions on invoices:

#. Go to *Invoicing > Customers > Invoices*.
#. Edit or create a new record.
#. When you have selected a partner, each new invoice line you add will have
the agents and commissions set at customer level.
#. You can add, modify or delete these agents discretely clicking on the
icon with several persons represented, next to the "Commission" field in the
list. This icon will be available only if the line hasn't been invoiced yet.
#. If you have configured your system for editing lines in a popup window,
agents will appear also in this window.
#. The agents icon will be in this ocassion visible when the line hasn't been
settled.
#. You have a button "Regenerate agents" on the bottom of the page
"Invoice Lines" for forcing a recompute of all agents from the partner setup.
This is needed for example when you have changed the partner on the
invoice having already inserted lines.

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:%20account_commission%0Aversion:%2015.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
~~~~~~~

* Tecnativa

Contributors
~~~~~~~~~~~~

* Pexego.
* Davide Corio <[email protected]>
* Joao Alfredo Gama Batista <[email protected]>
* Sandy Carter <[email protected]>
* Giorgio Borelli <[email protected]>
* Daniel Campos <[email protected]>
* Oihane Crucelaegui <[email protected]>
* Nicola Malcontenti <[email protected]>
* Aitor Bouzas <[email protected]>

* `Tecnativa <https://www.tecnativa.com>`__:

* Pedro M. Baeza
* Manuel Calero

* `Quartile <https://www.quartile.co>`__:

* Aung Ko Ko Lin
* Yoshi Tashiro

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.

.. |maintainer-pedrobaeza| image:: https://github.com/pedrobaeza.png?size=40px
:target: https://github.com/pedrobaeza
:alt: pedrobaeza

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-pedrobaeza|

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 3 additions & 0 deletions account_commission/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import models
from . import wizards
from . import report
26 changes: 26 additions & 0 deletions account_commission/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2014-2020 Tecnativa - Pedro M. Baeza
# Copyright 2020 Tecnativa - Manuel Calero
{
"name": "Account commissions",
"version": "15.0.1.0.0",
"author": "Tecnativa," "Odoo Community Association (OCA)",
"category": "Sales Management",
"license": "AGPL-3",
"depends": [
"account",
"commission",
],
"website": "https://github.com/OCA/commission",
"maintainers": ["pedrobaeza"],
"data": [
"security/ir.model.access.csv",
"security/account_commission_security.xml",
"views/account_move_views.xml",
"views/account_commission_settlement_view.xml",
"views/commission_views.xml",
"views/report_settlement_templates.xml",
"views/res_partner.xml",
"report/commission_analysis_view.xml",
],
"installable": True,
}
4 changes: 4 additions & 0 deletions account_commission/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import account_move
from . import commission
from . import settlement
from . import res_partner
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class AccountMove(models.Model):
compute="_compute_commission_total",
store=True,
)

partner_agent_ids = fields.Many2many(
string="Agents",
comodel_name="res.partner",
Expand Down Expand Up @@ -45,20 +44,13 @@ def _compute_commission_total(self):
record.commission_total += sum(x.amount for x in line.agent_ids)

def button_cancel(self):
"""Put settlements associated to the invoices in exception
and check settled lines"""
"""Check settled lines."""
if any(self.mapped("invoice_line_ids.any_settled")):
raise exceptions.ValidationError(
_("You can't cancel an invoice with settled lines"),
)
self.mapped("line_ids.settlement_id").write({"state": "except_invoice"})
return super().button_cancel()

def action_post(self):
"""Put settlements associated to the invoices in invoiced state."""
self.mapped("line_ids.settlement_id").write({"state": "invoiced"})
return super().action_post()

def recompute_lines_agents(self):
self.mapped("invoice_line_ids").recompute_agents()

Expand Down Expand Up @@ -93,17 +85,12 @@ def fields_view_get(
class AccountMoveLine(models.Model):
_inherit = [
"account.move.line",
"sale.commission.mixin",
"commission.mixin",
]
_name = "account.move.line"

agent_ids = fields.One2many(comodel_name="account.invoice.line.agent")
any_settled = fields.Boolean(compute="_compute_any_settled")
settlement_id = fields.Many2one(
comodel_name="sale.commission.settlement",
help="Settlement that generates this invoice line",
copy=False,
)

@api.depends("agent_ids", "agent_ids.settled")
def _compute_any_settled(self):
Expand All @@ -112,6 +99,16 @@ def _compute_any_settled(self):

@api.depends("move_id.partner_id")
def _compute_agent_ids(self):
for res in self:
settlement_lines = self.env["commission.settlement.line"].search(
[("invoice_line_id", "=", res.id)]
)
for line in settlement_lines:
line.date = False
line.agent_id = False
line.settled_amount = 0.00
line.currency_id = False
line.commission_id = False
self.agent_ids = False # for resetting previous agents
for record in self.filtered(
lambda x: x.move_id.partner_id and x.move_id.move_type[:3] == "out"
Expand All @@ -121,20 +118,9 @@ def _compute_agent_ids(self):
record.move_id.partner_id
)

def _copy_data_extend_business_fields(self, values):
"""
We don't want to loose the settlement from the line when reversing the line if
it was a refund.
We need to include it, but as we don't want change it everytime, we will add
the data when a context key is passed
"""
super()._copy_data_extend_business_fields(values)
if self.settlement_id and self.env.context.get("include_settlement", False):
values["settlement_id"] = self.settlement_id.id


class AccountInvoiceLineAgent(models.Model):
_inherit = "sale.commission.line.mixin"
_inherit = "commission.line.mixin"
_name = "account.invoice.line.agent"
_description = "Agent detail of commission line in invoice lines"

Expand All @@ -152,7 +138,7 @@ class AccountInvoiceLineAgent(models.Model):
readonly=True,
)
agent_line = fields.Many2many(
comodel_name="sale.commission.settlement.line",
comodel_name="commission.settlement.line",
relation="settlement_agent_line_rel",
column1="agent_line_id",
column2="settlement_id",
Expand Down
14 changes: 14 additions & 0 deletions account_commission/models/commission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class Commission(models.Model):
_inherit = "commission"

invoice_state = fields.Selection(
[("open", "Invoice Based"), ("paid", "Payment Based")],
string="Invoice Status",
required=True,
default="open",
)
17 changes: 17 additions & 0 deletions account_commission/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2016-2019 Tecnativa - Pedro M. Baeza
# Copyright 2018 Tecnativa - Ernesto Tejeda
# License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html

from odoo import fields, models


class ResPartner(models.Model):
"""Add some fields related to commissions"""

_inherit = "res.partner"

settlement_ids = fields.One2many(
comodel_name="commission.settlement",
inverse_name="agent_id",
readonly=True,
)
31 changes: 31 additions & 0 deletions account_commission/models/settlement.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Copyright 2014-2020 Tecnativa - Pedro M. Baeza
# Copyright 2020 Tecnativa - Manuel Calero
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import _, api, fields, models
from odoo.exceptions import UserError


class SettlementLine(models.Model):
_inherit = "commission.settlement.line"

agent_line = fields.Many2many(
comodel_name="account.invoice.line.agent",
relation="settlement_agent_line_rel",
column1="settlement_id",
column2="agent_line_id",
required=True,
)
invoice_line_id = fields.Many2one(
comodel_name="account.move.line",
store=True,
related="agent_line.object_id",
string="Source invoice line",
)

@api.constrains("settlement_id", "agent_line")
def _check_company(self):
for record in self:
for line in record.agent_line:
if line.company_id != record.company_id:
raise UserError(_("Company must be the same"))
6 changes: 6 additions & 0 deletions account_commission/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,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.
19 changes: 19 additions & 0 deletions account_commission/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
* Pexego.
* Davide Corio <[email protected]>
* Joao Alfredo Gama Batista <[email protected]>
* Sandy Carter <[email protected]>
* Giorgio Borelli <[email protected]>
* Daniel Campos <[email protected]>
* Oihane Crucelaegui <[email protected]>
* Nicola Malcontenti <[email protected]>
* Aitor Bouzas <[email protected]>

* `Tecnativa <https://www.tecnativa.com>`__:

* Pedro M. Baeza
* Manuel Calero

* `Quartile <https://www.quartile.co>`__:

* Aung Ko Ko Lin
* Yoshi Tashiro
3 changes: 3 additions & 0 deletions account_commission/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This module adds the function to calculate commissions in invoices (account moves).

This module depends on the commission module.
17 changes: 17 additions & 0 deletions account_commission/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
For adding commissions on invoices:

#. Go to *Invoicing > Customers > Invoices*.
#. Edit or create a new record.
#. When you have selected a partner, each new invoice line you add will have
the agents and commissions set at customer level.
#. You can add, modify or delete these agents discretely clicking on the
icon with several persons represented, next to the "Commission" field in the
list. This icon will be available only if the line hasn't been invoiced yet.
#. If you have configured your system for editing lines in a popup window,
agents will appear also in this window.
#. The agents icon will be in this ocassion visible when the line hasn't been
settled.
#. You have a button "Regenerate agents" on the bottom of the page
"Invoice Lines" for forcing a recompute of all agents from the partner setup.
This is needed for example when you have changed the partner on the
invoice having already inserted lines.
1 change: 1 addition & 0 deletions account_commission/report/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import commission_analysis
Loading

0 comments on commit 08c91a3

Please sign in to comment.