-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
575 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
======================================= | ||
Finnish Sales Invoice Payment Reference | ||
======================================= | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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-LGPL--3-blue.png | ||
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html | ||
:alt: License: LGPL-3 | ||
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fl10n--finland-lightgray.png?logo=github | ||
:target: https://github.com/OCA/l10n-finland/tree/11.0/l10n_fi_payment_reference | ||
:alt: OCA/l10n-finland | ||
.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/178/11.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| | ||
|
||
The module allows users to generate a valid invoice payment reference for sales invoices. | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Configuration | ||
============= | ||
|
||
Payment Reference Type can be selected from Account Settings. | ||
|
||
Usage | ||
===== | ||
|
||
A payment reference is generated upon validating a sales invoice. | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-finland/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. | ||
|
||
Do not contact contributors directly about support or help with technical issues. | ||
|
||
Credits | ||
======= | ||
|
||
Authors | ||
~~~~~~~ | ||
|
||
* Avoin.Systems | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
- Miku Laitinen (Avoin.Systems) | ||
- Mikko Närjänen (Avoin.Systems) | ||
- Oskars Zālītis (Avoin.Systems) | ||
|
||
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-finland <https://github.com/OCA/l10n-finland/tree/11.0/l10n_fi_payment_reference>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from. import models | ||
from. import tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright Avoin.Systems 2018 | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
"name": "Finnish Sales Invoice Payment Reference", | ||
"summary": "Generate a valid invoice payment reference for sales invoices", | ||
"version": "11.0.1.0.0", | ||
"category": "Localization", | ||
"website": "https://github.com/OCA/l10n-finland", | ||
"author": "Avoin.Systems, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"depends": [ | ||
"account", | ||
], | ||
"installable": True, | ||
"data": [ | ||
"views/account_invoice.xml", | ||
"views/res_config.xml", | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * l10n_fi_payment_reference | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2018-09-19 11:46+0000\n" | ||
"PO-Revision-Date: 2018-09-19 14:50+0300\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: 8bit\n" | ||
"Plural-Forms: nplurals=2; plural=(n != 1);\n" | ||
"X-Generator: Poedit 2.0.6\n" | ||
"Last-Translator: Miku Laitinen <miku@avoin.systems>\n" | ||
"Language: fi\n" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.ui.view,arch_db:l10n_fi_payment_reference.view_account_config_settings_finnish | ||
msgid "Choose the type of payment reference used on customer invoices" | ||
msgstr "Valitse myyntilaskuilla käytettävä maksuviitetyyppi" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model,name:l10n_fi_payment_reference.model_res_company | ||
msgid "Companies" | ||
msgstr "Yritykset" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: selection:res.company,payment_reference_type:0 | ||
msgid "Creditor Reference (RF)" | ||
msgstr "Kansainvälinen RF-viite" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: selection:res.company,payment_reference_type:0 | ||
msgid "Finnish Standard Reference" | ||
msgstr "Suomalainen maksuviite" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: selection:res.company,payment_reference_type:0 | ||
msgid "Free Reference" | ||
msgstr "Vapaa viite" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model,name:l10n_fi_payment_reference.model_account_invoice | ||
msgid "Invoice" | ||
msgstr "Lasku" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: code:addons/l10n_fi_payment_reference/models/account_invoice.py:15 | ||
#, python-format | ||
msgid "Invoice number must contain numeric characters" | ||
msgstr "Laskun numeron on sisällettävä numeerisia merkkejä" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.ui.view,arch_db:l10n_fi_payment_reference.view_account_config_settings_finnish | ||
msgid "Payment Reference" | ||
msgstr "Maksuviite" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_account_invoice_payment_reference | ||
msgid "Payment Reference Number" | ||
msgstr "Maksuviite" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_account_invoice_payment_reference_type | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_res_company_payment_reference_type | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_res_config_settings_payment_reference_type | ||
msgid "Payment Reference Type" | ||
msgstr "Maksuviitteen tyyppi" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model.fields,help:l10n_fi_payment_reference.field_account_invoice_payment_reference_type | ||
#: model:ir.model.fields,help:l10n_fi_payment_reference.field_res_company_payment_reference_type | ||
#: model:ir.model.fields,help:l10n_fi_payment_reference.field_res_config_settings_payment_reference_type | ||
msgid "The default payment reference for sales invoices" | ||
msgstr "Oletusmaksuviite myyntilaskuille" | ||
|
||
# non translatable | ||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model,name:l10n_fi_payment_reference.model_res_config_settings | ||
msgid "res.config.settings" | ||
msgstr "" |
82 changes: 82 additions & 0 deletions
82
l10n_fi_payment_reference/i18n/l10n_fi_payment_reference.pot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Translation of Odoo Server. | ||
# This file contains the translation of the following modules: | ||
# * l10n_fi_payment_reference | ||
# | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: Odoo Server 11.0\n" | ||
"Report-Msgid-Bugs-To: \n" | ||
"POT-Creation-Date: 2018-09-19 11:46+0000\n" | ||
"PO-Revision-Date: 2018-09-19 11:46+0000\n" | ||
"Last-Translator: <>\n" | ||
"Language-Team: \n" | ||
"MIME-Version: 1.0\n" | ||
"Content-Type: text/plain; charset=UTF-8\n" | ||
"Content-Transfer-Encoding: \n" | ||
"Plural-Forms: \n" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.ui.view,arch_db:l10n_fi_payment_reference.view_account_config_settings_finnish | ||
msgid "Choose the type of payment reference used on customer invoices" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model,name:l10n_fi_payment_reference.model_res_company | ||
msgid "Companies" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: selection:res.company,payment_reference_type:0 | ||
msgid "Creditor Reference (RF)" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: selection:res.company,payment_reference_type:0 | ||
msgid "Finnish Standard Reference" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: selection:res.company,payment_reference_type:0 | ||
msgid "Free Reference" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model,name:l10n_fi_payment_reference.model_account_invoice | ||
msgid "Invoice" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: code:addons/l10n_fi_payment_reference/models/account_invoice.py:15 | ||
#, python-format | ||
msgid "Invoice number must contain numeric characters" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.ui.view,arch_db:l10n_fi_payment_reference.view_account_config_settings_finnish | ||
msgid "Payment Reference" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_account_invoice_payment_reference | ||
msgid "Payment Reference Number" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_account_invoice_payment_reference_type | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_res_company_payment_reference_type | ||
#: model:ir.model.fields,field_description:l10n_fi_payment_reference.field_res_config_settings_payment_reference_type | ||
msgid "Payment Reference Type" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model.fields,help:l10n_fi_payment_reference.field_account_invoice_payment_reference_type | ||
#: model:ir.model.fields,help:l10n_fi_payment_reference.field_res_company_payment_reference_type | ||
#: model:ir.model.fields,help:l10n_fi_payment_reference.field_res_config_settings_payment_reference_type | ||
msgid "The default payment reference for sales invoices" | ||
msgstr "" | ||
|
||
#. module: l10n_fi_payment_reference | ||
#: model:ir.model,name:l10n_fi_payment_reference.model_res_config_settings | ||
msgid "res.config.settings" | ||
msgstr "" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from. import account_invoice | ||
from. import res_company | ||
from. import res_config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
# Copyright (C) Avoin.Systems 2018 | ||
import re | ||
from odoo import api, fields, models, _ | ||
from odoo.exceptions import UserError | ||
import logging | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
def number2numeric(number): | ||
|
||
invoice_number = re.sub(r'\D', '', number) | ||
|
||
if invoice_number == '' or invoice_number is False: | ||
raise UserError(_('Invoice number must contain numeric characters')) | ||
|
||
# Make sure the base number is 3...19 characters long | ||
if len(invoice_number) < 3: | ||
log.warning('Invoice number {} is less than 3 characters long, ' | ||
'padding to 3 characters with prefix 11.' | ||
.format(invoice_number)) | ||
invoice_number = ('11' + invoice_number)[-3:] | ||
elif len(invoice_number) > 19: | ||
log.warning('Invoice number {} is over 19 characters long, ' | ||
'truncating to 19 characters'.format(invoice_number)) | ||
invoice_number = invoice_number[:19] | ||
|
||
return invoice_number | ||
|
||
|
||
def get_finnish_check_digit(base_number): | ||
# Multiply digits from end to beginning with 7, 3 and 1 and | ||
# calculate the sum of the products | ||
total = sum((7, 3, 1)[idx % 3] * int(val) for idx, val in | ||
enumerate(base_number[::-1])) | ||
|
||
# Subtract the sum from the next decade. 10 = 0 | ||
return str((10 - (total % 10)) % 10) | ||
|
||
|
||
def get_rf_check_digits(base_number): | ||
check_base = base_number + 'RF00' | ||
# 1. Convert all non-digits to digits | ||
# 2. Calculate the modulo 97 | ||
# 3. Subtract the remainder from 98 | ||
# 4. Add leading zeros if necessary | ||
return ''.join( | ||
['00', str(98 - (int(''.join( | ||
[x if x.isdigit() else str(ord(x) - 55) for x in | ||
check_base])) % 97))])[-2:] | ||
|
||
|
||
def compute_payment_reference_fi(number): | ||
# Drop all non-numeric characters | ||
invoice_number = number2numeric(number) | ||
|
||
# Calculate the Finnish check digit | ||
check_digit = get_finnish_check_digit(invoice_number) | ||
|
||
return invoice_number + check_digit | ||
|
||
|
||
def compute_payment_reference_rf(number): | ||
# Drop all non-numeric characters | ||
invoice_number = number2numeric(number) | ||
|
||
# Calculate the Finnish check digit | ||
invoice_number += get_finnish_check_digit(invoice_number) | ||
|
||
# Calculate the RF check digits | ||
rf_check_digits = get_rf_check_digits(invoice_number) | ||
|
||
return 'RF' + rf_check_digits + invoice_number | ||
|
||
|
||
class AccountInvoiceFinnish(models.Model): | ||
_inherit = 'account.invoice' | ||
|
||
# noinspection PyMethodMayBeStatic | ||
def _compute_payment_reference_rf(self, invoice_number): | ||
return compute_payment_reference_rf(invoice_number) | ||
|
||
# noinspection PyMethodMayBeStatic | ||
def _compute_payment_reference_fi(self, invoice_number): | ||
return compute_payment_reference_fi(invoice_number) | ||
|
||
@api.multi | ||
def _compute_payment_reference(self): | ||
for invoice in self: | ||
ref_type = invoice.payment_reference_type | ||
if invoice.payment_reference or not ref_type or ref_type == 'none': | ||
continue | ||
|
||
if invoice.number: | ||
method_name = '_compute_payment_reference_' + ref_type | ||
if not hasattr(invoice, method_name): | ||
raise NotImplementedError( | ||
"Payment reference type {} doesn't have" | ||
"a compute method".format(ref_type)) | ||
|
||
self.payment_reference = \ | ||
getattr(invoice, method_name)(invoice.number) | ||
|
||
payment_reference = fields.Char( | ||
'Payment Reference Number', | ||
copy=False, | ||
) | ||
|
||
payment_reference_type = fields.Selection( | ||
related='company_id.payment_reference_type', | ||
readonly=True, | ||
) | ||
|
||
@api.multi | ||
def invoice_validate(self): | ||
res = super(AccountInvoiceFinnish, self).invoice_validate() | ||
# noinspection PyProtectedMember | ||
self.filtered(lambda i: i.payment_reference_type != 'none' and | ||
i.type == 'out_invoice') \ | ||
._compute_payment_reference() | ||
return res |
Oops, something went wrong.