Skip to content
Snippets Groups Projects
Unverified Commit 766a1025 authored by Laurent Smet's avatar Laurent Smet Committed by GitHub
Browse files

[IMP] l10n_be_invoice_bba: make structured comm working per company, not partner (#26154)

The structured communication is no longer configured for each partner independently. It can be configured like others communication type through the settings.

task: 32254
PR: 26154
co-author: Haresh Shyara (hsh)
parent aeb381c0
Branches
Tags
No related merge requests found
......@@ -11,25 +11,23 @@
'category': 'Localization',
'description': """
Add support for Belgian Structured Communication
A Structured Communication can be generated automatically on outgoing invoices according to the following algorithms:
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:
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+++
**R..R =** Customer Reference without non-numeric characters, **SSS =** Sequence Number, **DD =** Check Digits
The preferred type of Structured Communication and associated Algorithm can be
specified on the Partner records. A 'random' Structured Communication will
generated if no algorithm is specified on the Partner record.
""",
'depends': ['account'],
'depends': ['account', 'l10n_be'],
'data' : [
'data/mail_template_data.xml',
'views/res_partner_view.xml',
'views/res_config_settings_views.xml',
],
'auto-install': True,
}
......@@ -3,5 +3,6 @@
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
from . import res_partner
from . import account_invoice
from . import res_company
from . import res_config_settings
......@@ -17,9 +17,10 @@ account.invoice object: add support for Belgian structured communication
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
def generate_bbacomm(self, partner):
reference = ''
algorithm = partner.out_inv_comm_algorithm or 'random'
@api.multi
def generate_bbacomm(self):
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')
......@@ -39,12 +40,12 @@ class AccountInvoice(models.Model):
mod = base % 97 or 97
reference = '+++%s/%s/%s%02d+++' % (doy, year, seq, mod)
elif algorithm == 'partner_ref':
partner_ref = 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 Partner should have a 3-7 digit Reference Number for the generation of BBA Structured Communications!'
'\nPlease correct the Partner record.'))
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'
......@@ -76,6 +77,6 @@ class AccountInvoice(models.Model):
@api.multi
def _get_computed_reference(self):
self.ensure_one()
if self.company_id.invoice_reference_type == 'bba':
return self.generate_bbacomm(self.partner_id)
if self.company_id.invoice_reference_type == 'structured':
return self.generate_bbacomm()
return super(AccountInvoice, self)._get_computed_reference()
# -*- 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.')
# -*- 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',
string='Communication Algorithm', default='random',
help='Choose an algorithm to generate the structured communication.')
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
# Copyright (c) 2011 Noviat nv/sa (www.noviat.be). All rights reserved.
from odoo import api, fields, models
class ResCompany(models.Model):
_inherit = "res.company"
@api.model
def _get_invoice_reference_types(self):
res = super(ResCompany, self)._get_invoice_reference_types()
# Add BBA Structured Communication Type
res.append(('bba', 'BBA Structured Communication'))
return res
invoice_reference_type = fields.Selection(string='Default Communication Type', selection='_get_invoice_reference_types',
default='bba', 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.')
class ResPartner(models.Model):
""" add field to indicate default 'Communication Type' on customer invoices """
_inherit = 'res.partner'
@api.model
def _get_comm_type(self):
return self.env['res.company']._get_invoice_reference_types()
out_inv_comm_type = fields.Selection('_get_comm_type', string='Communication Type', change_default=True,
help='Select Default Communication Type for Outgoing Invoices.', default='none')
out_inv_comm_algorithm = fields.Selection([
('random', 'Random'),
('date', 'Date'),
('partner_ref', 'Customer Reference'),
], string='Communication Algorithm',
help='Select Algorithm to generate the Structured Communication on Outgoing Invoices.')
@api.model
def _commercial_fields(self):
return super(ResPartner, self)._commercial_fields() + ['out_inv_comm_type', 'out_inv_comm_algorithm']
<?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="l10n_be.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>
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Extension to Partner Form to support outgoing invoices with automatic generation of structured communication -->
<record id="view_partner_inv_comm_type_form" model="ir.ui.view">
<field name="name">res.partner.inv_comm_type.form.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="account.view_partner_property_form"/>
<field name="arch" type="xml">
<group name="sale" position="inside">
<field name="out_inv_comm_type"/>
<field name="out_inv_comm_algorithm" attrs="{'invisible':[('out_inv_comm_type','!=','bba')]}"/>
</group>
</field>
</record>
</odoo>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment