Permalink
Browse files

[IMP] l10n_be_invoice_bba: update reference fields

Task 1920906
remove the l10n_be_structured_comm field
'random'/'date' references will not be longer used
new structured_invoice_number and structured_partner_ref reference types
  • Loading branch information...
william-andre committed Feb 11, 2019
1 parent b9b7baf commit a5800943bda6d7c7149d7f0b3af992f98d5920dc
@@ -15,19 +15,16 @@
Using BBA structured communication simplifies the reconciliation between invoices and payments.
You can select the structured communication as payment communication in Invoicing/Accounting settings.
Three algorithms are suggested:
Two algorithms are suggested:
1) Random : +++RRR/RRRR/RRRDD+++
**R..R =** Random Digits, **DD =** Check Digits
2) Date : +++DOY/YEAR/SSSDD+++
**DOY =** Day of the Year, **SSS =** Sequence Number, **DD =** Check Digits
3) Customer Reference +++RRR/RRRR/SSSDDD+++
1) Invoice Number +++RRR/RRRR/RRRDD+++
**R..R =** Invoice Number, **DD =** Check Digits
2) Customer Reference +++RRR/RRRR/SSSDD+++
**R..R =** Customer Reference without non-numeric characters, **SSS =** Sequence Number, **DD =** Check Digits
""",
'depends': ['account', 'l10n_be'],
'data' : [
'data/mail_template_data.xml',
'views/res_config_settings_views.xml',
],
'auto-install': True,
}
@@ -4,5 +4,4 @@
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.

from . import account_invoice
from . import res_company
from . import res_config_settings
from . import res_company
@@ -18,30 +18,10 @@ class AccountInvoice(models.Model):
_inherit = 'account.invoice'

@api.multi
def generate_bbacomm(self):
def generate_bbacomm(self, algorithm):
self.ensure_one()
algorithm = self.company_id.l10n_be_structured_comm
if algorithm == 'date':
date = fields.Date.from_string(fields.Date.today())
doy = date.strftime('%j')
year = date.strftime('%Y')
seq = '001'
invoices = self.search([('type', '=', 'out_invoice'),
('reference', 'like', '+++%s/%s/%%' % (doy, year))], order='reference')
if invoices:
prev_seq = int(invoices[-1].reference[12:15])
if prev_seq < 999:
seq = '%03d' % (prev_seq + 1)
else:
raise UserError(_('The daily maximum of outgoing invoices with an automatically generated BBA Structured Communications has been exceeded!'
'\nPlease create manually a unique BBA Structured Communication.'))
bbacomm = doy + year + seq
base = int(bbacomm)
mod = base % 97 or 97
reference = '+++%s/%s/%s%02d+++' % (doy, year, seq, mod)
elif algorithm == 'partner_ref':
if algorithm == 'bba_partner_ref':
partner_ref = self.partner_id.ref
print(partner_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'
@@ -56,14 +36,14 @@ def generate_bbacomm(self):
if prev_seq < 999:
seq = '%03d' % (prev_seq + 1)
else:
raise UserError(_('The daily maximum of outgoing invoices with an automatically generated BBA Structured Communications has been exceeded!'
raise UserError(_('The maximum of outgoing invoices with an automatically generated BBA Structured Communications has been exceeded for this customer!'
'\nPlease create manually a unique BBA Structured Communication.'))
bbacomm = partner_ref_nr + seq
base = int(bbacomm)
mod = base % 97 or 97
reference = '+++%s/%s/%s%02d+++' % (partner_ref_nr[:3], partner_ref_nr[3:], seq, mod)
elif algorithm == 'random':
base = random.randint(1, 9999999999)
elif algorithm == 'bba_invoice_number':
base = self.id
bbacomm = str(base).rjust(10, '0')
base = int(bbacomm)
mod = base % 97 or 97
@@ -77,6 +57,7 @@ def generate_bbacomm(self):
@api.multi
def _get_computed_reference(self):
self.ensure_one()
if self.company_id.invoice_reference_type == 'structured':
return self.generate_bbacomm()
ref_type = self.company_id.invoice_reference_type
if ref_type in ('bba_invoice_number', 'bba_partner_ref'):
return self.generate_bbacomm(ref_type)
return super(AccountInvoice, self)._get_computed_reference()
@@ -1,19 +1,15 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
from odoo import models, _


class ResCompany(models.Model):
_inherit = 'res.company'

def _get_invoice_reference_types(self):
# OVERRIDE
res = super(ResCompany, self)._get_invoice_reference_types()
res.append(('structured', 'Structured Communication'))
res.extend([
('bba_invoice_number', _('Structured communication based on invoice')),
('bba_partner_ref', _('Structured communication based on partner')),
])
return res

l10n_be_structured_comm = fields.Selection([
('random', "Random Reference"),
('date', "Based on Invoice's Creation Date"),
('partner_ref', "Based on Customer's Internal Reference"),
], string='Communication Algorithm', default='random', help='Choose an algorithm to generate the structured communication.')

This file was deleted.

Oops, something went wrong.

This file was deleted.

Oops, something went wrong.

0 comments on commit a580094

Please sign in to comment.