Browse Source

[ADD] add module bringing bba communication to loan line

pull/134/head
houssine 4 years ago
parent
commit
0bcbe9ab37
  1. 1
      easy_my_coop_loan_bba/__init__.py
  2. 21
      easy_my_coop_loan_bba/__manifest__.py
  3. 1
      easy_my_coop_loan_bba/models/__init__.py
  4. 95
      easy_my_coop_loan_bba/models/loan_issue_line.py

1
easy_my_coop_loan_bba/__init__.py

@ -0,0 +1 @@
from . import models

21
easy_my_coop_loan_bba/__manifest__.py

@ -0,0 +1,21 @@
# Copyright 2020 - ongoing Coop IT Easy (http://www.coopiteasy.be)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Easy My Coop Loan BBA',
'category': 'Sales',
'author': "Coop IT Easy - Houssine BAKKALI <houssine@coopiteasy.be>",
'website': 'https://www.coopiteasy.be',
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'easy_my_coop_loan',
'l10n_be_invoice_bba'
],
"description": """
This module implements the bba structured communication on the loan line.
""",
'data': [
],
'installable': True,
}

1
easy_my_coop_loan_bba/models/__init__.py

@ -0,0 +1 @@
from . import loan_issue_line

95
easy_my_coop_loan_bba/models/loan_issue_line.py

@ -0,0 +1,95 @@
# © 2018 Coop IT Easy (http://www.coopiteasy.be)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import random
import re
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class LoanIssueLine(models.Model):
_inherit = 'loan.issue.line'
@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')
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 '
'for 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)
return reference
@api.multi
def action_validate(self):
super(LoanIssueLine, self).action_validate()
for line in self:
bba = line.generate_bbacomm()
line.write({'reference': bba})
Loading…
Cancel
Save