From cd7dc4f2c83e8e4770789d989fbc6f2aee03ef12 Mon Sep 17 00:00:00 2001 From: "Audric Onockx (auon)" Date: Thu, 31 Mar 2022 16:01:32 +0000 Subject: [PATCH] [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) --- addons/l10n_fi/__manifest__.py | 1 + addons/l10n_fi_sale/__init__.py | 4 ++ addons/l10n_fi_sale/__manifest__.py | 17 +++++++ addons/l10n_fi_sale/i18n/fi.po | 27 ++++++++++ addons/l10n_fi_sale/i18n/l10n_fi_sale.pot | 27 ++++++++++ addons/l10n_fi_sale/models/__init__.py | 4 ++ addons/l10n_fi_sale/models/sale.py | 47 ++++++++++++++++++ .../l10n_fi_sale/static/description/icon.png | Bin 0 -> 615 bytes 8 files changed, 127 insertions(+) create mode 100644 addons/l10n_fi_sale/__init__.py create mode 100644 addons/l10n_fi_sale/__manifest__.py create mode 100644 addons/l10n_fi_sale/i18n/fi.po create mode 100644 addons/l10n_fi_sale/i18n/l10n_fi_sale.pot create mode 100644 addons/l10n_fi_sale/models/__init__.py create mode 100644 addons/l10n_fi_sale/models/sale.py create mode 100644 addons/l10n_fi_sale/static/description/icon.png 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 0000000000000000000000000000000000000000..0d38212600315ec7e202aec242d56dee91ebc334 GIT binary patch literal 615 zcmeAS@N?(olHy`uVBq!ia0vp^cR-kf4M<8yoo@tEY)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP~rvSI0fI;6|MFs}OFP<)rAr-gY-rb++6ex1w;pZoU zx=d!8x=bruwoLL-V08DGDVP&%(U`(yUeK_kVV85zvP*7CDqRJeTPCzW|E*^6{XBnO zxiZjjg5ZHt=+Y^Zaxd<^XtK}je(%iZANPr$zS(_yhQn#Gh6fG>FsxwVPyoRKG71(5 z%)uuh1Hmlp9DE4e#LU7D!3PfZB15ZvYdSUt?G&W~}oQH6hO3>c*c9;Hs{QJkM|LwcwhM&LW=ReB*^TbRofM5RI zCEZ=Mq2^ih-j%8w&1+UyMb?SULrt4m2`K^j9gDkxekT|OKm`wM{xQs~Rg!AD&VCZ4 N-qY33Wt~$(699jItfl|} literal 0 HcmV?d00001