diff --git a/addons/l10n_fi/__manifest__.py b/addons/l10n_fi/__manifest__.py index d4841bff4dc..d7a11bf39a2 100644 --- a/addons/l10n_fi/__manifest__.py +++ b/addons/l10n_fi/__manifest__.py @@ -17,6 +17,7 @@ After installing this module, you'll have access to : * Finnish chart of account * Fiscal positions * Invoice Payment Reference Types (Finnish Standard Reference & Finnish Creditor Reference (RF)) + * Finnish Reference format for Sale Orders Set the payment reference type from the Sales Journal. """, diff --git a/addons/l10n_fi_sale/__init__.py b/addons/l10n_fi_sale/__init__.py new file mode 100644 index 00000000000..b60115f0aa5 --- /dev/null +++ b/addons/l10n_fi_sale/__init__.py @@ -0,0 +1,4 @@ +#-*- coding:utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/l10n_fi_sale/__manifest__.py b/addons/l10n_fi_sale/__manifest__.py new file mode 100644 index 00000000000..0bde5be3498 --- /dev/null +++ b/addons/l10n_fi_sale/__manifest__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Finland - Sale', + 'version': '1.0', + 'description': """Finland Sale""", + 'category': 'Localization', + 'depends': [ + 'l10n_fi', + 'sale', + ], + 'installable': True, + 'application': False, + 'auto_install': True, + 'license': 'LGPL-3', +} diff --git a/addons/l10n_fi_sale/i18n/fi.po b/addons/l10n_fi_sale/i18n/fi.po new file mode 100644 index 00000000000..4f1102ec887 --- /dev/null +++ b/addons/l10n_fi_sale/i18n/fi.po @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_fi_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-04-04 12:50+0000\n" +"PO-Revision-Date: 2022-04-04 12:50+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_sale +#: code:addons/l10n_fi_sale/models/sale.py:0 +#, python-format +msgid "Reference must contain numeric characters" +msgstr "Viitteen tulee sisältää numeerisia merkkejä" + +#. module: l10n_fi_sale +#: model:ir.model,name:l10n_fi_sale.model_sale_order +msgid "Sales Order" +msgstr "Myyntitilaus" diff --git a/addons/l10n_fi_sale/i18n/l10n_fi_sale.pot b/addons/l10n_fi_sale/i18n/l10n_fi_sale.pot new file mode 100644 index 00000000000..1fbec349967 --- /dev/null +++ b/addons/l10n_fi_sale/i18n/l10n_fi_sale.pot @@ -0,0 +1,27 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * l10n_fi_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 13.0+e\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2022-04-04 12:50+0000\n" +"PO-Revision-Date: 2022-04-04 12:50+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_sale +#: code:addons/l10n_fi_sale/models/sale.py:0 +#, python-format +msgid "Reference must contain numeric characters" +msgstr "" + +#. module: l10n_fi_sale +#: model:ir.model,name:l10n_fi_sale.model_sale_order +msgid "Sales Order" +msgstr "" diff --git a/addons/l10n_fi_sale/models/__init__.py b/addons/l10n_fi_sale/models/__init__.py new file mode 100644 index 00000000000..9bfcd2f0c87 --- /dev/null +++ b/addons/l10n_fi_sale/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding:utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import sale diff --git a/addons/l10n_fi_sale/models/sale.py b/addons/l10n_fi_sale/models/sale.py new file mode 100644 index 00000000000..ff370b0e23e --- /dev/null +++ b/addons/l10n_fi_sale/models/sale.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +import re +from odoo import api, models, _ +from odoo.exceptions import UserError + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + def write(self, values): + # We compute the l10n_fi/SaleOrder.reference from itself the same way + # we compute the l10n_fi/AccountMove.invoice_payment_ref from its name. + reference = values.get('reference', False) + if reference: + values['reference'] = self.compute_payment_reference_finnish(reference) + return super().write(values) + + @api.model + def number2numeric(self, number): + so_number = re.sub(r'\D', '', number) + if so_number == '' or so_number is False: + raise UserError(_('Reference must contain numeric characters')) + + # Make sure the base number is 3...19 characters long + if len(so_number) < 3: + so_number = ('11' + so_number)[-3:] + elif len(so_number) > 19: + so_number = so_number[:19] + + return so_number + + @api.model + def get_finnish_check_digit(self, 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) + + @api.model + def compute_payment_reference_finnish(self, number): + # Drop all non-numeric characters + so_number = self.number2numeric(number) + # Calculate the Finnish check digit + check_digit = self.get_finnish_check_digit(so_number) + return so_number + check_digit diff --git a/addons/l10n_fi_sale/static/description/icon.png b/addons/l10n_fi_sale/static/description/icon.png new file mode 100644 index 00000000000..0d382126003 Binary files /dev/null and b/addons/l10n_fi_sale/static/description/icon.png differ