[FIX] l10n_fi : set confrorm payment ref on invoice

Steps :
Install eCommerce and l10n_fi.
Create a Payment Acquirer with a new Journal.
Change this Journal's type to Sales.
Go to Website, order a Product with this Acquirer.
Go to Sales > the consequent SO. Note the Payment Ref.
Confirm, Create Invoice and Post.
Note the same Payment Reference.

Issue :
This reference is not valid in Finland accounting because letters are
not allowed.

Cause :
First, a Journal linked to an Acquirer should be
of type Bank or Cash. Such Journals do not have Payment References
specifications. So, in the current state of affairs, it would not be
possible to set a localized reference on the SO.
Second, SO's payment reference is its name or CUST/its partner's id.
Then it is copied to its Invoice's payment reference.
Upon posting this invoice, if it has a reference, it is not modified.

Fix :
Limit the modification of the Type of a Journal linked to a
Payment Acquirer to : Bank and Cash.
Create a Finnish Sale module to compute SaleOrder.reference form itself
the same way AccountMove.invoice_payment_ref is computed from its name.

opw-2745902

closes odoo/odoo#89122

X-original-commit: 7e0c436e5817722c0cb3c223a75def3b701535a4
Signed-off-by: Onockx Audric (auon) <auon@odoo.com>
This commit is contained in:
Audric Onockx (auon)
2022-04-20 18:48:55 +02:00
parent 6217bed174
commit cd7dc4f2c8
8 changed files with 127 additions and 0 deletions
+1
View File
@@ -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.
""",
+4
View File
@@ -0,0 +1,4 @@
#-*- coding:utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+17
View File
@@ -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',
}
+27
View File
@@ -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"
+27
View File
@@ -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 ""
+4
View File
@@ -0,0 +1,4 @@
# -*- coding:utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import sale
+47
View File
@@ -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
Binary file not shown.

After

Width:  |  Height:  |  Size: 615 B