Skip to content

Commit

Permalink
Merge e1caf38 into 5f9f530
Browse files Browse the repository at this point in the history
  • Loading branch information
tarteo committed Dec 20, 2018
2 parents 5f9f530 + e1caf38 commit f954aee
Show file tree
Hide file tree
Showing 19 changed files with 454 additions and 22 deletions.
90 changes: 90 additions & 0 deletions l10n_nl_account_credit_control/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
==================================
Credit Control for the Netherlands
==================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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%2Fl10n--netherlands-lightgray.png?logo=github
:target: https://github.com/OCA/l10n-netherlands/tree/11.0/l10n_nl_account_credit_control
:alt: OCA/l10n-netherlands
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/l10n-netherlands-11-0/l10n-netherlands-11-0-l10n_nl_account_credit_control
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/176/11.0
:alt: Try me on Runbot

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

This module calculates the dunning fee based on the method defined by the WIK:
<https://www.rijksoverheid.nl/onderwerpen/hulp-bij-schulden/vraag-en-antwoord/hoogte-incassokosten>.

**Table of contents**

.. contents::
:local:

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

To change the dunning fee amount and percentages:

#. Go to 'Invoicing > Configuration > Credit Control > Credit Control Policies';
#. select a policy;
#. select the tab 'Fees'.

To print the dunning fees on the e-mail or PDF:

#. Go to the credit control policy form;
#. select a level in the 'Policy levels' tab;
#. select the tab 'Mail and reporting' on the policy level form;
#. put #FEE#, #FEENOTAX# or #FEETAX# in the preferred custom text fields.

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

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

* Onestein

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

* Dennis Sluijk <d.sluijk@onestein.nl>

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/l10n-netherlands <https://github.com/OCA/l10n-netherlands/tree/11.0/l10n_nl_account_credit_control>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions l10n_nl_account_credit_control/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import wizards
19 changes: 19 additions & 0 deletions l10n_nl_account_credit_control/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
'name': 'Credit Control for the Netherlands',
'summary': 'Dutch localization for credit control',
'license': 'AGPL-3',
'author': 'Onestein,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/l10n-netherlands',
'category': 'Localization',
'version': '11.0.1.0.0',
'development_status': 'Beta',
'depends': [
'account_credit_control',
],
'data': [
'security/ir.model.access.csv',
'data/credit_control_policy_fee_data.xml',
'views/credit_control_policy_view.xml',
'reports/report_credit_control_summary.xml'
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Onestein
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo noupdate="1">
<record id="fee_1" model="credit.control.policy.fee">
<field name="credit_control_policy_id"
ref="account_credit_control.credit_control_3_time" />
<field name="sequence">0</field>
<field name="amount">2500</field>
<field name="fee">15</field>
</record>

<record id="fee_2" model="credit.control.policy.fee">
<field name="credit_control_policy_id"
ref="account_credit_control.credit_control_3_time" />
<field name="sequence">1</field>
<field name="amount">2500</field>
<field name="fee">10</field>
</record>

<record id="fee_3" model="credit.control.policy.fee">
<field name="credit_control_policy_id"
ref="account_credit_control.credit_control_3_time" />
<field name="sequence">2</field>
<field name="amount">5000</field>
<field name="fee">5</field>
</record>

<record id="fee_4" model="credit.control.policy.fee">
<field name="credit_control_policy_id"
ref="account_credit_control.credit_control_3_time" />
<field name="sequence">3</field>
<field name="amount">190000</field>
<field name="fee">1</field>
</record>

<record id="fee_5" model="credit.control.policy.fee">
<field name="credit_control_policy_id"
ref="account_credit_control.credit_control_3_time" />
<field name="sequence">4</field>
<field name="amount">800000</field>
<field name="fee">0.5</field>
</record>
</odoo>
2 changes: 2 additions & 0 deletions l10n_nl_account_credit_control/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import credit_control_policy_fee
from . import credit_control_policy
53 changes: 53 additions & 0 deletions l10n_nl_account_credit_control/models/credit_control_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Copyright 2018 Onestein
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class CreditControlPolicy(models.Model):
_inherit = 'credit.control.policy'

fee_tax_ids = fields.Many2many(
comodel_name='account.tax',
string='Fee Taxes'
)

min_fee = fields.Monetary(
string='Minimum Fee',
default=40
)

max_fee = fields.Monetary(
string='Maximum Fee',
default=6775
)

fee_ids = fields.One2many(
string='Fees',
comodel_name='credit.control.policy.fee',
inverse_name='credit_control_policy_id'
)

currency_id = fields.Many2one(
'res.currency',
required=True,
default=lambda self: self.env.user.company_id.currency_id
)

@api.multi
def calculate_fee(self, amount):
fee = 0
for fee_record in self.fee_ids:
tmp_amount = amount - fee_record.amount

if tmp_amount < 0:
fee += amount * fee_record.fee_percentage
break
else:
fee += fee_record.amount * fee_record.fee_percentage
amount -= fee_record.amount
if fee > self.max_fee:
fee = self.max_fee
elif fee < self.min_fee:
fee = self.min_fee
return fee
40 changes: 40 additions & 0 deletions l10n_nl_account_credit_control/models/credit_control_policy_fee.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2018 Onestein
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class CreditControlPolicyFee(models.Model):
_name = 'credit.control.policy.fee'
_order = 'sequence'

credit_control_policy_id = fields.Many2one(
comodel_name='credit.control.policy',
required=True
)

currency_id = fields.Many2one(
'res.currency',
required=True,
related='credit_control_policy_id.currency_id'
)

sequence = fields.Integer()

amount = fields.Monetary(
string='Amount of the unpaid bill',
currency_field='currency_id'
)

fee = fields.Float(
string='Fee (%)'
)

fee_percentage = fields.Float(
compute='_compute_fee_percentage'
)

@api.multi
def _compute_fee_percentage(self):
for fee in self:
fee.fee_percentage = fee.fee / 100
12 changes: 12 additions & 0 deletions l10n_nl_account_credit_control/readme/CONFIGURE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
To change the dunning fee amount and percentages:

#. Go to 'Invoicing > Configuration > Credit Control > Credit Control Policies';
#. select a policy;
#. select the tab 'Fees'.

To print the dunning fees on the e-mail or PDF:

#. Go to the credit control policy form;
#. select a level in the 'Policy levels' tab;
#. select the tab 'Mail and reporting' on the policy level form;
#. put #FEE#, #FEENOTAX# or #FEETAX# in the preferred custom text fields.
1 change: 1 addition & 0 deletions l10n_nl_account_credit_control/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* Dennis Sluijk <d.sluijk@onestein.nl>
2 changes: 2 additions & 0 deletions l10n_nl_account_credit_control/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module calculates the dunning fee based on the method defined by the WIK:
<https://www.rijksoverheid.nl/onderwerpen/hulp-bij-schulden/vraag-en-antwoord/hoogte-incassokosten>.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2018 Onestein
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>
<template id="report_credit_control_summary_document"
inherit_id="account_credit_control.report_credit_control_summary_document">
<!-- Replace custom_text -->
<xpath expr="//span[@t-field='doc.current_policy_level.custom_text']" position="attributes">
<attribute name="class">hidden</attribute>
</xpath>
<xpath expr="//span[@t-field='doc.current_policy_level.custom_text']" position="after">
<span t-field="doc.custom_text" />
</xpath>

<!-- Replace custom_text_after_details -->
<xpath expr="//p[@t-field='doc.current_policy_level.custom_text_after_details']" position="attributes">
<attribute name="class">hidden</attribute>
</xpath>
<xpath expr="//p[@t-field='doc.current_policy_level.custom_text_after_details']" position="after">
<span t-field="doc.custom_text_after_details" />
</xpath>
</template>
</odoo>
4 changes: 4 additions & 0 deletions l10n_nl_account_credit_control/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_credit_control_policy_fee_manager,access_credit_control_policy_fee_manager,model_credit_control_policy_fee,account_credit_control.group_account_credit_control_manager,1,1,1,1
access_credit_control_policy_fee_user,access_credit_control_policy_fee_user,model_credit_control_policy_fee,account_credit_control.group_account_credit_control_user,1,0,0,0
access_credit_control_policy_fee_info,access_credit_control_policy_fee_info,model_credit_control_policy_fee,account_credit_control.group_account_credit_control_info,1,0,0,0
1 change: 1 addition & 0 deletions l10n_nl_account_credit_control/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_credit_control
41 changes: 41 additions & 0 deletions l10n_nl_account_credit_control/tests/test_credit_control.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2018 Onestein
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase


class TestCreditControl(TransactionCase):
def test_fee_calculation(self):
policy = self.env.ref('account_credit_control.credit_control_3_time')

# Test minimal amount
self.assertEqual(policy.calculate_fee(5), policy.min_fee)

# Test 1 tier fee
self.assertEqual(policy.calculate_fee(1500), 225)

# Test 2 tier fee
self.assertEqual(policy.calculate_fee(3000), 425)

# Test 3 tier fee
self.assertEqual(policy.calculate_fee(800000), 5775)

# Test maximum amount
self.assertEqual(policy.calculate_fee(1200000), policy.max_fee)

def test_communication(self):
partner = self.env.ref('base.main_partner')
level = self.env.ref('account_credit_control.3_time_1')
currency = self.env.ref('base.USD')
level.custom_text = '#FEE#'
level.custom_text_after_details = '#FEENOTAX#'
level.custom_mail_text = '#FEETAX#'

comm = self.env['credit.control.communication'].create({
'currency_id': currency.id,
'partner_id': partner.id,
'current_policy_level': level.id
})
self.assertTrue('#FEE#' not in comm.custom_text)
self.assertTrue('#FEENOTAX#' not in comm.custom_text_after_details)
self.assertTrue('#FEETAX#' not in comm.custom_mail_text)
Loading

0 comments on commit f954aee

Please sign in to comment.