[ADD] l10n_be_invoice_bba: update reference fields

Task 1920906
remove the l10n_be_structured_comm field
random/date references will not be longer used
adapt for the last changes in account

closes odoo/odoo#29858

Signed-off-by: Quentin De Paoli (qdp) <qdp@openerp.com>
This commit is contained in:
wan
2019-04-02 11:11:00 +00:00
parent 46a339fc9e
commit d60e6a1ab7
8 changed files with 44 additions and 112 deletions
+1 -1
View File
@@ -452,7 +452,7 @@ class AccountJournal(models.Model):
compute='_compute_refund_seq_number_next',
inverse='_inverse_refund_seq_number_next')
invoice_reference_type = fields.Selection(string='Communication Type', required=True, selection=[('none', 'Free'), ('partner', 'Based on Partner'), ('invoice', 'Based on Invoice')], default='none', help='You can set here the default communication that will appear on customer invoices, once validated, to help the customer to refer to that particular invoice when making the payment.')
invoice_reference_type = fields.Selection(string='Communication Type', required=True, selection=[('none', 'Free'), ('partner', 'Based on Partner'), ('invoice', 'Based on Invoice')], default='invoice', help='You can set here the default communication that will appear on customer invoices, once validated, to help the customer to refer to that particular invoice when making the payment.')
invoice_reference_model = fields.Selection(string='Communication Standard', required=True, selection=[('odoo', 'Odoo'),('euro', 'European')], default='odoo', help="You can choose different models for each type of reference. The default one is the Odoo reference.")
#groups_id = fields.Many2many('res.groups', 'account_journal_group_rel', 'journal_id', 'group_id', string='Groups')
+6 -9
View File
@@ -15,19 +15,16 @@ Add Structured Communication to customer invoices.
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': [
'data/mail_template_data.xml',
'views/res_config_settings_views.xml',
],
'auto-install': True,
'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 account_journal
@@ -18,65 +18,35 @@ class AccountInvoice(models.Model):
_inherit = 'account.invoice'
@api.multi
def generate_bbacomm(self):
def _get_reference_be_partner(self):
""" This computes the reference based on the belgian national standard
“OGM-VCS”.
For instance, if an invoice is issued for the partner with internal
reference 'food buyer 654', the digits will be extracted and used as
the data. This will lead to a check number equal to 72 and the
reference will be '+++000/0000/65472+++'.
If no reference is set for the partner, its id in the database will
be used.
"""
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':
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'
'\nfor the generation of BBA Structured Communications!'))
else:
partner_ref_nr = partner_ref_nr.ljust(7, '0')
seq = '001'
invoices = self.search([('type', '=', 'out_invoice'),
('reference', 'like', '+++%s/%s/%%' % (partner_ref_nr[:3], partner_ref_nr[3:]))], 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 = 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)
bbacomm = str(base).rjust(10, '0')
base = int(bbacomm)
mod = base % 97 or 97
mod = str(mod).rjust(2, '0')
reference = '+++%s/%s/%s%s+++' % (bbacomm[:3], bbacomm[3:7], bbacomm[7:], mod)
else:
raise UserError(_("Unsupported Structured Communication Type Algorithm '%s' !"
"\nPlease contact your Odoo support channel.") % algorithm)
bbacomm = (re.sub('\D', '', self.partner_id.ref or '') or str(self.partner_id.id))[-10:].rjust(10, '0')
base = int(bbacomm)
mod = base % 97 or 97
reference = '+++%s/%s/%s%02d+++' % (bbacomm[:3], bbacomm[3:7], bbacomm[7:], mod)
return reference
@api.multi
def _get_computed_reference(self):
def _get_reference_be_invoice(self):
""" This computes the reference based on the belgian national standard
“OGM-VCS”.
The data of the reference is the database id number of the invoice.
For instance, if an invoice is issued with id 654, the check number
is 72 so the reference will be '+++000/0000/65472+++'.
"""
self.ensure_one()
if self.company_id.invoice_reference_type == 'structured':
return self.generate_bbacomm()
return super(AccountInvoice, self)._get_computed_reference()
base = self.id
bbacomm = str(base).rjust(10, '0')
base = int(bbacomm)
mod = base % 97 or 97
reference = '+++%s/%s/%s%02d+++' % (bbacomm[:3], bbacomm[3:7], bbacomm[7:], mod)
return reference
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class AccountJournal(models.Model):
_inherit = 'account.journal'
invoice_reference_model = fields.Selection(selection_add=[('be', 'Belgium')])
@@ -1,19 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, 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'))
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.')
@@ -1,11 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
l10n_be_structured_comm = fields.Selection(related='company_id.l10n_be_structured_comm', readonly=False,
string='Communication Algorithm', default='random',
help='Choose an algorithm to generate the structured communication.')
@@ -1,13 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.l10n_be_invoice_bba</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='invoice_reference_type']" position="after">
<field name="l10n_be_structured_comm" attrs="{'invisible': [('invoice_reference_type', '!=', 'structured')]}"/>
</xpath>
</field>
</record>
</odoo>