summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwan <wan@odoo.com>2019-02-28 10:03:34 +0000
committerwan <wan@odoo.com>2019-04-02 11:11:00 +0000
commitd60e6a1ab75e3722c393d10ef6d5c7d309cb0b84 (patch)
treef2b2594584e29f68b571e06bc8bff15078638151
parent46a339fc9e98e4bb2604a272bc6a90c7ea2a416f (diff)
[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>
-rw-r--r--addons/account/models/account.py2
-rw-r--r--addons/l10n_be_invoice_bba/__manifest__.py15
-rw-r--r--addons/l10n_be_invoice_bba/models/__init__.py3
-rw-r--r--addons/l10n_be_invoice_bba/models/account_invoice.py84
-rw-r--r--addons/l10n_be_invoice_bba/models/account_journal.py9
-rw-r--r--addons/l10n_be_invoice_bba/models/res_company.py19
-rw-r--r--addons/l10n_be_invoice_bba/models/res_config_settings.py11
-rw-r--r--addons/l10n_be_invoice_bba/views/res_config_settings_views.xml13
8 files changed, 44 insertions, 112 deletions
diff --git a/addons/account/models/account.py b/addons/account/models/account.py
index 382aee1010f..3379aa344cc 100644
--- a/addons/account/models/account.py
+++ b/addons/account/models/account.py
@@ -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')
diff --git a/addons/l10n_be_invoice_bba/__manifest__.py b/addons/l10n_be_invoice_bba/__manifest__.py
index 53c121f9de6..229b60b4293 100644
--- a/addons/l10n_be_invoice_bba/__manifest__.py
+++ b/addons/l10n_be_invoice_bba/__manifest__.py
@@ -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,
}
diff --git a/addons/l10n_be_invoice_bba/models/__init__.py b/addons/l10n_be_invoice_bba/models/__init__.py
index d90735fc6c5..18a4627629e 100644
--- a/addons/l10n_be_invoice_bba/models/__init__.py
+++ b/addons/l10n_be_invoice_bba/models/__init__.py
@@ -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 \ No newline at end of file
diff --git a/addons/l10n_be_invoice_bba/models/account_invoice.py b/addons/l10n_be_invoice_bba/models/account_invoice.py
index 50318e87b18..5f5f3a6f105 100644
--- a/addons/l10n_be_invoice_bba/models/account_invoice.py
+++ b/addons/l10n_be_invoice_bba/models/account_invoice.py
@@ -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
diff --git a/addons/l10n_be_invoice_bba/models/account_journal.py b/addons/l10n_be_invoice_bba/models/account_journal.py
new file mode 100644
index 00000000000..e8cc09daf44
--- /dev/null
+++ b/addons/l10n_be_invoice_bba/models/account_journal.py
@@ -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')])
diff --git a/addons/l10n_be_invoice_bba/models/res_company.py b/addons/l10n_be_invoice_bba/models/res_company.py
deleted file mode 100644
index 56776470055..00000000000
--- a/addons/l10n_be_invoice_bba/models/res_company.py
+++ /dev/null
@@ -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.')
diff --git a/addons/l10n_be_invoice_bba/models/res_config_settings.py b/addons/l10n_be_invoice_bba/models/res_config_settings.py
deleted file mode 100644
index 26f62dc966d..00000000000
--- a/addons/l10n_be_invoice_bba/models/res_config_settings.py
+++ /dev/null
@@ -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.')
diff --git a/addons/l10n_be_invoice_bba/views/res_config_settings_views.xml b/addons/l10n_be_invoice_bba/views/res_config_settings_views.xml
deleted file mode 100644
index 1844ecdd3a3..00000000000
--- a/addons/l10n_be_invoice_bba/views/res_config_settings_views.xml
+++ /dev/null
@@ -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>