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

[13.0] [MIG] account_reconcile_rule_early_payment_discount #356

Closed
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
126 changes: 126 additions & 0 deletions account_reconcile_rule_early_payment_discount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
===========================================
Early Payment Discount Reconciliation Rules
===========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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%2Faccount--reconcile-lightgray.png?logo=github
:target: https://github.com/OCA/account-reconcile/tree/13.0/account_reconcile_rule_early_payment_discount
:alt: OCA/account-reconcile
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/account-reconcile-13-0/account-reconcile-13-0-account_reconcile_rule_early_payment_discount
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/98/13.0
:alt: Try me on Runbot

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

Extends the module *Account Reconcile Rules* with a new rule type :
**Early Payment Discount**.

It allows to automatically create a write-off
entry for the amount paid by the customers when they received dunning
fees (using the **Account Credit Control** module).

**Table of contents**

.. contents::
:local:

Installation
============

This module only works with the ``account_early_payment_discount``
module in the project: https://github.com/OCA/account-payment

Usage
=====

1. Look at ``account_early_payment_discount``
module in the project: https://github.com/OCA/account-payment
to configure payment terms with an early payment discount.

-----

2. Configure some ``Reconciliation Models`` in
``Invoicing > Dashboard > Bank Card > Reconciliation Models``

.. image:: https://raw.githubusercontent.com/OCA/account-reconcile/13.0/account_reconcile_rule_early_payment_discount/docs/operation_rule_menu.png

.. image:: https://raw.githubusercontent.com/OCA/account-reconcile/13.0/account_reconcile_rule_early_payment_discount/docs/rule_model.png

-----

3. Then configure a new Reconciliation Rule in
``Invoicing > Dashboard > Bank Card > Reconciliation Rules``

.. image:: https://raw.githubusercontent.com/OCA/account-reconcile/13.0/account_reconcile_rule_early_payment_discount/docs/rule.png

-----

4. Then during reconciliation, if a bank statement line matches an invoice which has a
payment term configured with early payment discount, this rule will verify if
the remaining balance respects the early payment discount rules
(discount percentage and payment delay).
If true, the remaining balance will be automatically reconciled in the configured account.

.. image:: https://raw.githubusercontent.com/OCA/account-reconcile/13.0/account_reconcile_rule_early_payment_discount/docs/reconcilation.png

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/account-reconcile/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/account-reconcile/issues/new?body=module:%20account_reconcile_rule_early_payment_discount%0Aversion:%2013.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
~~~~~~~

* Camptocamp

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

* Cyril Gaudin <cyril.gaudin@camptocamp.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>
* Dung Tran <dungtd@trobz.com>

Other credits
~~~~~~~~~~~~~

The development of this module has been financially supported by:

* Camptocamp

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/account-reconcile <https://github.com/OCA/account-reconcile/tree/13.0/account_reconcile_rule_early_payment_discount>`_ 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 account_reconcile_rule_early_payment_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions account_reconcile_rule_early_payment_discount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2016 Cyril Gaudin (Camptocamp)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Early Payment Discount Reconciliation Rules",
"version": "13.0.1.0.0",
"author": "Camptocamp, Odoo Community Association (OCA)",
"license": "AGPL-3",
"category": "Accounting & Finance",
"depends": ["account_reconcile_rule", "account_early_payment_discount"],
"website": "https://github.com/OCA/account-reconcile",
"data": ["views/account_reconcile_rule_view.xml"],
"installable": True,
"auto_install": True,
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_reconcile_rule
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2016 Cyril Gaudin (Camptocamp)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from datetime import timedelta

from odoo import fields, models


class AccountReconcileRule(models.Model):
_inherit = "account.reconcile.rule"

rule_type = fields.Selection(
selection_add=[("early_payment_discount", "Early Payment Discount")],
)

def _is_valid_early_payment_discount(self, statement_line, move_lines, balance):
"""Return True if *move_lines* are linked to only one invoice
with a payment term which has an early payment discount
and if *balance* and the *statement_line* date match the
early payment discount rules.

:type statement_line: AccountBankStatementLine
:type move_lines: stock_move
:type balance: float
:rtype: bool
"""

if not move_lines or balance >= 0:
return False
else:
invoice = move_lines.mapped("move_id")

if len(invoice) != 1:
return False
elif not invoice.invoice_payment_term_id.early_payment_discount:
return False
else:
return self._check_early_payment_discount(
statement_line, invoice, balance
)

def _check_early_payment_discount(self, statement_line, invoice, balance):
""" Return True if *balance* and the *statement_line* date match the
early payment discount rules for *invoice*.

:type statement_line: AccountBankStatementLine
:type invoice: AccountMove
:type balance: float
:rtype: bool
"""
payment_term = invoice.invoice_payment_term_id

max_date = fields.Date.from_string(invoice.invoice_date) + timedelta(
days=payment_term.epd_nb_days
)

if fields.Date.from_string(statement_line.date) > max_date:
return False

percent = payment_term.epd_discount / 100.0
discount_balance = invoice.amount_total * percent

if payment_term.epd_tolerance:
discount_balance += payment_term.epd_tolerance

return self._between_with_bounds(
# Balance is negative in our case
0,
-balance,
discount_balance,
statement_line.currency_for_rules(),
)

def is_valid(self, statement_line, move_lines, balance):
""" Override account.operation.rule is_valid for early_payment_discount
case
"""
if self.rule_type == "early_payment_discount":
return self._is_valid_early_payment_discount(
statement_line, move_lines, balance
)
else:
return super().is_valid(statement_line, move_lines, balance)
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* Cyril Gaudin <cyril.gaudin@camptocamp.com>
* Akim Juillerat <akim.juillerat@camptocamp.com>
* Dung Tran <dungtd@trobz.com>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The development of this module has been financially supported by:

* Camptocamp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Extends the module *Account Reconcile Rules* with a new rule type :
**Early Payment Discount**.

It allows to automatically create a write-off
entry for the amount paid by the customers when they received dunning
fees (using the **Account Credit Control** module).
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module only works with the ``account_early_payment_discount``
module in the project: https://github.com/OCA/account-payment
29 changes: 29 additions & 0 deletions account_reconcile_rule_early_payment_discount/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
1. Look at ``account_early_payment_discount``
module in the project: https://github.com/OCA/account-payment
to configure payment terms with an early payment discount.

-----

2. Configure some ``Reconciliation Models`` in
``Invoicing > Dashboard > Bank Card > Reconciliation Models``

.. image:: docs/operation_rule_menu.png

.. image:: docs/rule_model.png

-----

3. Then configure a new Reconciliation Rule in
``Invoicing > Dashboard > Bank Card > Reconciliation Rules``

.. image:: docs/rule.png

-----

4. Then during reconciliation, if a bank statement line matches an invoice which has a
payment term configured with early payment discount, this rule will verify if
the remaining balance respects the early payment discount rules
(discount percentage and payment delay).
If true, the remaining balance will be automatically reconciled in the configured account.

.. image:: docs/reconcilation.png
Loading