Permalink
Browse files

[ADD] account: new european invoice reference

OPW 1920906
new rf_invoice_number and rf_partner_ref added as possible invoice reference generation
  • Loading branch information...
william-andre committed Jan 2, 2019
1 parent 2cc263b commit e02626d2cccb2f0c8581c1a6d8598808424884c9
Showing with 40 additions and 2 deletions.
  1. +35 −1 addons/account/models/account_invoice.py
  2. +5 −1 addons/account/models/company.py
@@ -4,6 +4,8 @@
import re
import uuid
from functools import partial
from stdnum.iso7064 import mod_97_10
from itertools import zip_longest

from lxml import etree
from dateutil.relativedelta import relativedelta
@@ -390,11 +392,43 @@ def _get_vendor_display_info(self):
vendor_display_name = ('Created by: ') + invoice.create_uid.name
invoice.invoice_icon = '#'
invoice.vendor_display_name = vendor_display_name

def _get_rf_invoice_number(self):
self.ensure_one()
base = self.id
check_digits = mod_97_10.calc_check_digits('{}RF'.format(base))
reference = 'RF{} {}'.format(check_digits, " ".join(["".join(x) for x in zip_longest(*[iter(str(base))]*4,fillvalue="")]))
return reference

def _get_rf_partner_ref(self):
self.ensure_one()
partner_ref = self.partner_id.ref
partner_ref_nr = re.sub('\D', '', partner_ref or '')
if (len(partner_ref_nr) < 3) or (len(partner_ref_nr) > 7):
raise UserError(_('The Customer should have an Internal Reference with min 3 and max 7 digits'
'\nfor the generation of RF Structured Communications!'))
else:
partner_ref_nr = partner_ref_nr.ljust(7, '0')
seq = '1'
invoices = self.search([('type', '=', 'out_invoice'),
('reference', 'like', 'RF__ {}%'.format(partner_ref_nr))], order='reference')
if invoices:
prev_ref = invoices[-1].reference.replace(" ", "")
prev_seq = int(prev_ref[(4+len(partner_ref_nr)):])
seq = '%d' % (prev_seq + 1)
comm = partner_ref_nr + seq
check_digits = mod_97_10.calc_check_digits('{}RF'.format(comm))
reference = 'RF{} {}'.format(check_digits, " ".join(["".join(x) for x in zip_longest(*[iter(comm)]*4,fillvalue="")]))
return reference

@api.multi
def _get_computed_reference(self):
self.ensure_one()
if self.company_id.invoice_reference_type == 'invoice_number':
if self.company_id.invoice_reference_type == 'rf_invoice_number':
return self._get_rf_invoice_number()
elif self.company_id.invoice_reference_type == 'rf_partner_ref':
return self._get_rf_partner_ref()
elif self.company_id.invoice_reference_type == 'invoice_number':
seq_suffix = self.journal_id.sequence_id.suffix or ''
regex_number = '.*?([0-9]+)%s$' % seq_suffix
exact_match = re.match(regex_number, self.number)
@@ -16,7 +16,11 @@ class ResCompany(models.Model):
_inherit = "res.company"

def _get_invoice_reference_types(self):
return [('invoice_number', _('Based on Invoice Number')), ('partner', _('Based on Customer'))]
return [('invoice_number', _('Based on Invoice Number')),
('partner', _('Based on Customer')),
('rf_invoice_number', _('RF Creditor Reference based on invoice')),
('rf_partner_ref', _('RF Creditor Reference based on partner')),
]

#TODO check all the options/fields are in the views (settings + company form view)
fiscalyear_last_day = fields.Integer(default=31, required=True)

0 comments on commit e02626d

Please sign in to comment.