l10n_se_ocr: Adding support of OCR Number for Invoice and Vendor Bill. Invoice supports OCR level 1 to 4 on both Parter ref and Invoice. Vendor Bill supports default vendor OCR number and OCR checksum.

closes odoo/odoo#53132

X-original-commit: 739e7c0b11c0cda705a2e7db3674863436e346ea
Signed-off-by: Josse Colpaert <jco@openerp.com>
This commit is contained in:
Daniel Stenlöv
2020-06-17 09:54:35 +00:00
parent 8a94f62e08
commit 7b2ed98cb9
10 changed files with 320 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
+26
View File
@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name' : 'Sweden - Structured Communication OCR',
'version' : '1.0',
'author': 'XCLUDE',
'website': 'https://www.xclude.se',
'category': 'Localization',
'description': """
Add Structured Communication to Customer Invoices and Vendor Bill.
------------------------------------------------------------------
Using OCR structured communication simplifies the reconciliation between invoices and payments.
For Customer Invoicing support for OCR level 1 to 4. The OCR number can be based on partner or
the invoice.
For Vendor Bill support for Default Vendor Specific OCR is added and validation for OCR.
""",
'depends': ['l10n_se'],
'data': [
'views/partner_view.xml',
'views/account_journal_view.xml'
],
'auto_install': True,
}
+139
View File
@@ -0,0 +1,139 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * l10n_se_ocr
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0+e-20191106\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-05-28 18:15+0000\n"
"PO-Revision-Date: 2020-05-28 18:15+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_se_ocr
#: model:ir.model.fields,field_description:l10n_se_ocr.field_account_journal__invoice_reference_model
msgid "Communication Standard"
msgstr "Kommunikationsstandard"
#. module: l10n_se_ocr
#: model:ir.model,name:l10n_se_ocr.model_res_partner
msgid "Contact"
msgstr "Kontakt"
#. module: l10n_se_ocr
#: code:addons/l10n_se_ocr/models/partner.py:0
#, python-format
msgid "Default vendor OCR number isn't a valid OCR number."
msgstr "Standard OCR nummer för leverantören är inte ett godkänt OCR nummer."
#. module: l10n_se_ocr
#: model:ir.model.fields,help:l10n_se_ocr.field_res_partner__default_vendor_ocr
#: model:ir.model.fields,help:l10n_se_ocr.field_res_users__default_vendor_ocr
msgid ""
"If set, the vendor uses the same Default Payment Reference or OCR Number on all their Vendor "
"Bills."
msgstr "Om satt, kommer denna texten eller OCR numret att användas som betalnings referensen för alla leverantörens fakturor."
#. module: l10n_se_ocr
#: model:ir.model,name:l10n_se_ocr.model_account_journal
msgid "Journal"
msgstr "Verifikat"
#. module: l10n_se_ocr
#: model:ir.model,name:l10n_se_ocr.model_account_move
msgid "Journal Entries"
msgstr "Verifikat rad"
#. module: l10n_se_ocr
#: model:ir.model.fields,field_description:l10n_se_ocr.field_account_journal__invoice_ocr_length
msgid "OCR Number Length"
msgstr "OCR Nummerlängd"
#. module: l10n_se_ocr
#: code:addons/l10n_se_ocr/models/account_move.py:0
#, python-format
msgid ""
"OCR Reference Number length is greater than allowed. Allowed length in "
"invoice journal setting is %s."
msgstr "OCR referensnummer är längre än tillåtet. Ändra inställningar i "
"inställningarna för fakturaverifikat. Inställningarn är idag %s."
#. module: l10n_se_ocr
#: code:addons/l10n_se_ocr/models/account_move.py:0
#, python-format
msgid ""
"OCR Reference Number length need to be greater than 5. Please correct "
"settings under invoice journal settings."
msgstr "OCR referensnummerlängd behöver vara större än 5. Ändra "
"inställningar för fakturaverifikat."
#. module: l10n_se_ocr
#: model_terms:ir.ui.view,arch_db:l10n_se_ocr.res_partner_ocr_form
msgid "Payment Options"
msgstr "Betalningsalternativ"
#. module: l10n_se_ocr
#: model:ir.model.fields.selection,name:l10n_se_ocr.selection__account_journal__invoice_reference_model__se_ocr2
msgid "Sweden OCR Level 1 & 2"
msgstr "Sverige OCR typ 1 & 2"
#. module: l10n_se_ocr
#: model:ir.model.fields.selection,name:l10n_se_ocr.selection__account_journal__invoice_reference_model__se_ocr3
msgid "Sweden OCR Level 3"
msgstr "Sverige OCR typ 3"
#. module: l10n_se_ocr
#: model:ir.model.fields.selection,name:l10n_se_ocr.selection__account_journal__invoice_reference_model__se_ocr4
msgid "Sweden OCR Level 4"
msgstr "Sverige OCR typ 4"
#. module: l10n_se_ocr
#: model:ir.model.fields,help:l10n_se_ocr.field_res_partner__use_vendor_ocr
#: model:ir.model.fields,help:l10n_se_ocr.field_res_users__use_vendor_ocr
msgid "This Vendor uses OCR Number on their Vendor Bills."
msgstr "Denna leverantör använder sig av OCR referensnummer på deras leverantörsfakturor."
#. module: l10n_se_ocr
#: model:ir.model.fields,help:l10n_se_ocr.field_account_journal__invoice_ocr_length
msgid "Total length of OCR Reference Number including checksum."
msgstr "Den totala längden för OCR refrensnummer inklusive kontrollsiffra."
#. module: l10n_se_ocr
#: model:ir.model.fields,field_description:l10n_se_ocr.field_res_partner__use_vendor_ocr
#: model:ir.model.fields,field_description:l10n_se_ocr.field_res_users__use_vendor_ocr
msgid "Check Vendor OCR"
msgstr "Kontrollera Leverantörens OCR Nummer"
#. module: l10n_se_ocr
#: model:ir.model.fields,field_description:l10n_se_ocr.field_res_partner__default_vendor_ocr
#: model:ir.model.fields,field_description:l10n_se_ocr.field_res_users__default_vendor_ocr
msgid "Default Vendor Payment Ref"
msgstr "Standard Lev. betalningsref."
#. module: l10n_se_ocr
#: code:addons/l10n_se_ocr/models/account_move.py:0
#, python-format
msgid ""
"Vendor require OCR Number as payment reference. Payment reference isn't a "
"valid OCR Number."
msgstr "Leverantör kräver OCR nummer som sin betalningsreferens. "
"Betalningsrefrensen är inte ett godkänt OCR nummer."
#. module: l10n_se_ocr
#: code:addons/l10n_se_ocr/models/account_move.py:0
#: code:addons/l10n_se_ocr/models/partner.py:0
#, python-format
msgid "Warning"
msgstr "Varning"
#. module: l10n_se_ocr
#: model:ir.model.fields,help:l10n_se_ocr.field_account_journal__invoice_reference_model
msgid ""
"You can choose different models for each type of reference. The default one "
"is the Odoo reference."
msgstr ""
+6
View File
@@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import account_move
from . import account_journal
from . import res_partner
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api, _
from odoo.exceptions import ValidationError
class AccountJournal(models.Model):
_inherit = 'account.journal'
invoice_reference_model = fields.Selection(selection_add=[('se_ocr2', 'Sweden OCR Level 1 & 2'), ('se_ocr3', 'Sweden OCR Level 3'), ('se_ocr4', 'Sweden OCR Level 4')])
l10n_se_invoice_ocr_length = fields.Integer(string='OCR Number Length', help="Total length of OCR Reference Number including checksum.", default=6)
@api.constrains('l10n_se_invoice_ocr_length')
def _check_l10n_se_invoice_ocr_length(self):
if self.l10n_se_invoice_ocr_length < 6:
return ValidationError(_('OCR Reference Number length need to be greater than 5. Please correct settings under invoice journal settings.'))
+73
View File
@@ -0,0 +1,73 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, _
from odoo.exceptions import UserError
from stdnum import luhn
class AccountMove(models.Model):
_inherit = 'account.move'
def _get_invoice_reference_se_ocr2(self, reference):
self.ensure_one()
return reference + luhn.calc_check_digit(reference)
def _get_invoice_reference_se_ocr3(self, reference):
self.ensure_one()
reference = reference + str(len(reference) + 2)[:1]
return reference + luhn.calc_check_digit(reference)
def _get_invoice_reference_se_ocr4(self, reference):
self.ensure_one()
ocr_length = self.journal_id.l10n_se_invoice_ocr_length
if len(reference) + 1 > ocr_length:
raise UserError(_("OCR Reference Number length is greater than allowed. Allowed length in invoice journal setting is %s.") % str(ocr_length))
reference = reference.rjust(ocr_length - 1, '0')
return reference + luhn.calc_check_digit(reference)
def _get_invoice_reference_se_ocr2_invoice(self):
self.ensure_one()
return self._get_invoice_reference_se_ocr2(str(self.id))
def _get_invoice_reference_se_ocr3_invoice(self):
self.ensure_one()
return self._get_invoice_reference_se_ocr3(str(self.id))
def _get_invoice_reference_se_ocr4_invoice(self):
self.ensure_one()
return self._get_invoice_reference_se_ocr4(str(self.id))
def _get_invoice_reference_se_ocr2_partner(self):
self.ensure_one()
return self._get_invoice_reference_se_ocr2(self.partner_id.ref if str(self.partner_id.ref).isdecimal() else str(self.partner_id.id))
def _get_invoice_reference_se_ocr3_partner(self):
self.ensure_one()
return self._get_invoice_reference_se_ocr3(self.partner_id.ref if str(self.partner_id.ref).isdecimal() else str(self.partner_id.id))
def _get_invoice_reference_se_ocr4_partner(self):
self.ensure_one()
return self._get_invoice_reference_se_ocr4(self.partner_id.ref if str(self.partner_id.ref).isdecimal() else str(self.partner_id.id))
@api.onchange('partner_id')
def _onchange_partner_id(self):
""" If Vendor Bill and Vendor OCR is set, add it. """
if self.partner_id and self.type == 'in_invoice' and self.partner_id.l10n_se_default_vendor_payment_ref:
self.invoice_payment_ref = self.partner_id.l10n_se_default_vendor_payment_ref
return super(AccountMove, self)._onchange_partner_id()
@api.onchange('invoice_payment_ref')
def _onchange_invoice_payment_ref(self):
""" If Vendor Bill and Payment Reference is changed check validation. """
if self.partner_id and self.type == 'in_invoice' and self.partner_id.l10n_se_check_vendor_ocr:
reference = self.invoice_payment_ref
try:
luhn.validate(reference)
except:
return {'warning': {'title': _('Warning'), 'message': _('Vendor require OCR Number as payment reference. Payment reference isn\'t a valid OCR Number.')}}
return super(AccountMove, self)._onchange_invoice_payment_ref()
+21
View File
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models, api, _
from stdnum import luhn
class ResPartner(models.Model):
_inherit = 'res.partner'
l10n_se_check_vendor_ocr = fields.Boolean(string='Check Vendor OCR', help='This Vendor uses OCR Number on their Vendor Bills.')
l10n_se_default_vendor_payment_ref = fields.Char(string='Default Vendor Payment Ref', help='If set, the vendor uses the same Default Payment Reference or OCR Number on all their Vendor Bills.')
@api.onchange('l10n_se_default_vendor_payment_ref')
def onchange_l10n_se_default_vendor_payment_ref(self):
if not self.l10n_se_default_vendor_payment_ref == "" and self.l10n_se_check_vendor_ocr:
reference = self.l10n_se_default_vendor_payment_ref
try:
luhn.validate(reference)
except:
return {'warning': {'title': _('Warning'), 'message': _('Default vendor OCR number isn\'t a valid OCR number.')}}
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="view_account_journal_se_ocr_form" model="ir.ui.view">
<field name="name">account.journal.se.ocr.form</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.view_account_journal_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_reference_model']" position="after">
<field name="l10n_se_invoice_ocr_length" attrs="{'invisible': [('invoice_reference_model', '!=', 'se_ocr4')]}"/>
</xpath>
</field>
</record>
</data>
</odoo>
+18
View File
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="res_partner_ocr_form" model="ir.ui.view">
<field name="name">res.partner.ocr.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<group name="accounting_entries" position="after">
<group string="Payment Options Sweden" name="payment_options">
<field name="l10n_se_check_vendor_ocr"/>
<field name="l10n_se_default_vendor_payment_ref"/>
</group>
</group>
</field>
</record>
</data>
</odoo>