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

8.0 add account cash discount compute ape #1

Open
wants to merge 10 commits into
base: 8.0
Choose a base branch
from
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ virtualenv:

install:
- git clone --depth=1 https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- git clone https://github.com/OCA/account-financial-reporting ${HOME}/account-financial-reporting -b ${VERSION}
- git clone -b 8.0-add-account-cash-discount-base-ape https://github.com/acsone/banking.git ${HOME}/banking-cash-discount-base
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- pip install xlrd pycoda unidecode
- travis_install_nightly
Expand Down
12 changes: 12 additions & 0 deletions l10n_be_cash_discount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Belgium cash discount computation
===

The module implements the Belgian method of applying taxes in presence of cash discount.

The cash discount percentage is applied is applied on the amount without tax, and the VAT is computed on the discounted amount.

Credits
---

* the computation algorithm has been designed by Luc De Meyer (Noviat)
* ACSONE implemented the current module structure and integrated with OCA/bank-payment
23 changes: 23 additions & 0 deletions l10n_be_cash_discount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import models
41 changes: 41 additions & 0 deletions l10n_be_cash_discount/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

{
"name": "Belgium cash discount computation",
"version": "8.0.1.0.0",
"author": "ACSONE SA/NV",
"maintainer": "ACSONE SA/NV",
"website": "http://www.acsone.eu",
"images": [],
"category": "Accounting",
"depends": [
"account_cash_discount_base",
],
"data": [],
"demo": [],
"test": [],
"licence": "AGPL-3",
"installable": True,
"auto_install": False,
"application": True,
}
24 changes: 24 additions & 0 deletions l10n_be_cash_discount/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import account_invoice_tax
from . import account_invoice_line
53 changes: 53 additions & 0 deletions l10n_be_cash_discount/models/account_invoice_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import models, api, fields
from openerp.addons.l10n_be_cash_discount.models.account_invoice_tax \
import BelgiumBaseTaxCodes


class account_invoice_line(models.Model):
_inherit = 'account.invoice.line'

@api.model
def _move_line_get_discount(self, invoice_id, aml):
invoice = self.env['account.invoice'].browse(invoice_id)
pct = invoice.discount_percent
if not pct and invoice.discount_amount:
pct = (1 - (invoice.discount_amount / invoice.amount_total)) * 100
if pct:
currency = invoice.currency_id\
.with_context(date=invoice.date_invoice or
fields.Date.context_today(invoice))
multiplier = 1-pct/100
atc_obj = self.env['account.tax.code']
belgium_btc = atc_obj.search([('code', 'in', BelgiumBaseTaxCodes)])
for tax in aml:
if tax['tax_code_id'] in belgium_btc.ids:
tax['tax_amount'] = \
currency.round(tax['tax_amount'] * multiplier)

@api.model
def move_line_get(self, invoice_id):
aml = super(account_invoice_line, self).move_line_get(invoice_id)
self._move_line_get_discount(invoice_id, aml)
return aml
63 changes: 63 additions & 0 deletions l10n_be_cash_discount/models/account_invoice_tax.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import api, models, fields

BelgiumBaseTaxCodesIn = ['81', '82', '83', '84', '85', '86', '87', '88']
BelgiumBaseTaxCodesOut = ['00', '01', '02', '03', '44', '45', '46', '46L',
'46T', '47', '48', '48s44', '48s46L', '48s46T', '49']
BelgiumBaseTaxCodes = BelgiumBaseTaxCodesIn + BelgiumBaseTaxCodesOut


class account_invoice_tax(models.Model):
_inherit = 'account.invoice.tax'

def _compute_discount_tax_value(self, invoice, tax_grouped):
""" This method compute taxes values consider discount percent.
This method is designed to be inherited"""

currency = invoice.currency_id\
.with_context(date=invoice.date_invoice or
fields.Date.context_today(invoice))
pct = invoice.discount_percent
if not pct and invoice.discount_amount:
pct = (1 - (invoice.discount_amount / invoice.amount_total)) * 100
if pct:
multiplier = 1-pct/100
atc_obj = self.env['account.tax.code']
belgium_btc = atc_obj.search([('code', 'in',
BelgiumBaseTaxCodes)])
for t in tax_grouped.values():
if t['base_code_id'] in belgium_btc.ids:
t['base'] = currency.round(t['base'] * multiplier)
t['amount'] = currency.round(t['amount'] * multiplier)
t['base_amount'] = currency.round(t['base_amount'] *
multiplier)
t['tax_amount'] = currency.round(t['tax_amount'] *
multiplier)
return tax_grouped

@api.v8
def compute(self, invoice):
tax_grouped = super(account_invoice_tax, self).compute(invoice)
tax_grouped = self._compute_discount_tax_value(invoice, tax_grouped)
return tax_grouped
24 changes: 24 additions & 0 deletions l10n_be_cash_discount/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#

from . import test_l10n_be_cash_discount
95 changes: 95 additions & 0 deletions l10n_be_cash_discount/tests/test_l10n_be_cash_discount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import openerp.tests.common as common
from datetime import datetime
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
import logging
_logger = logging.getLogger(__name__)


DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID


def create_simple_invoice(self, date, tax_id):
journal_id = self.ref('account.sales_journal')
partner_id = self.ref('base.res_partner_2')
product_id = self.ref('product.product_product_4')
return self.env['account.invoice']\
.create({'partner_id': partner_id,
'account_id':
self.ref('account.a_recv'),
'journal_id':
journal_id,
'discount_due_date': date,
'discount_percent': 10.0,
'date_invoice': date,
'invoice_line': [(0, 0, {'name': 'test',
'account_id':
self.ref('account.a_sale'),
'price_unit': 2000.00,
'quantity': 1,
'product_id': product_id,
'invoice_line_tax_id': [(4, tax_id)],
}
)
],
})


def create_belgium_tax_code(self, code):
return self.env['account.tax.code'].create({'name': 'Belgium Tax Code',
'code': code
})


def create_tax(self, name, type_tax_use, compute_type, amount, base_code_id,
tax_code_id):
return self.env['account.tax'].create({'name': name,
'type_tax_use': type_tax_use,
'type': compute_type,
'amount': amount,
'base_code_id': base_code_id,
'tax_code_id': tax_code_id,
})


class TestAccountCashDiscountCompute(common.TransactionCase):

def setUp(self):
super(TestAccountCashDiscountCompute, self).setUp()
self.context = self.registry("res.users").context_get(self.cr,
self.uid)

def test_invoice_tax_discount(self):
tax_code = create_belgium_tax_code(self, '48')
tax = create_tax(self, 'Tax Test 21%', 'sale', 'percent', '0.21',
tax_code.id, tax_code.id)
today = datetime.now()
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
invoice = create_simple_invoice(self, date, tax.id)
invoice.button_reset_taxes()
tax_line = invoice.tax_line
self.assertEqual(len(tax_line), 1, "Number of tax line isn't correct")
self.assertAlmostEqual(tax_line.base_amount, 1800, 2,
"Tax Base Amoount isn't correct")
1 change: 1 addition & 0 deletions setup/l10n_be_cash_discount/odoo_addons/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)
6 changes: 6 additions & 0 deletions setup/l10n_be_cash_discount/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)