23
23
from openerp.tools import mod10r
26
class AccountMoveLine(Model):
28
_inherit = "account.move.line"
30
_compile_get_ref = re.compile('[^0-9]')
33
'transaction_ref': fields.char('Transaction Ref.', size=128),
37
cr.execute('UPDATE account_move_line SET transaction_ref = ref'
38
' WHERE transaction_ref IS NULL'
39
' AND ref IS NOT NULL')
42
def get_bvr_ref(self, cursor, uid, move_line_id, context=None):
43
"""Retrieve ESR/BVR reference from move line in order to print it"""
45
if isinstance(move_line_id, (tuple, list)):
46
assert len(move_line_id) == 1, "Only 1 ID expected"
47
move_line_id = move_line_id[0]
48
move_line = self.browse(cursor, uid, move_line_id, context=context)
49
## We check if the type is bvr, if not we return false
50
if move_line.invoice.partner_bank_id.state != 'bvr':
53
if move_line.invoice.partner_bank_id.bvr_adherent_num:
54
res = move_line.invoice.partner_bank_id.bvr_adherent_num
56
if move_line.invoice.number:
57
move_number = self._compile_get_ref.sub('', str(move_line.invoice.number) + str(move_line_id))
58
return mod10r(res + move_number.rjust(26 - len(res), '0'))
26
61
class AccountInvoice(Model):
27
62
"""Inherit account.invoice in order to add bvr
28
63
printing functionnalites. BVR is a Swiss payment vector"""
41
76
def _compute_full_bvr_name(self, cursor, uid, ids, field_names, arg, context=None):
78
move_line_obj = self.pool.get('account.move.line')
79
account_obj = self.pool.get('account.account')
80
tier_account_id = account_obj.search(cursor, uid, [('type', 'in', ['receivable', 'payable'])])
43
81
for inv in self.browse(cursor, uid, ids, context=context):
44
res[inv.id] = self._space(inv.get_bvr_ref())
82
move_lines = move_line_obj.search(cursor, uid, [('move_id', '=', inv.move_id.id),
83
('account_id', 'in', tier_account_id)])
85
if len(move_lines) == 1:
86
res[inv.id] = self._space(inv.get_bvr_ref())
89
for move_line in move_line_obj.browse(cursor, uid, move_lines, context=context):
90
refs.append(self._space(move_line.get_bvr_ref()))
91
res[inv.id] = ' ; '.join(refs)
79
>>> self._space('123456789012345')
126
self._space('123456789012345')
80
127
'12 34567 89012 345'
82
129
return ''.join([' '[(i - 2) % nbrspc:] + c for i, c in enumerate(nbr)])
84
def action_number(self, cursor, uid, ids, context=None):
85
res = super(AccountInvoice, self).action_number(cursor, uid, ids, context=context)
86
for inv in self.browse(cursor, uid, ids, context=context):
87
if inv.type != 'out_invoice' or inv.partner_bank_id.state != 'bvr':
131
def _update_ref_on_account_analytic_line(self, cr, uid, ref, move_id, context=None):
132
cr.execute('UPDATE account_analytic_line SET ref=%s'
133
' FROM account_move_line '
134
' WHERE account_move_line.move_id = %s '
135
' AND account_analytic_line.move_id = account_move_line.id',
139
def action_number(self, cr, uid, ids, context=None):
140
res = super(AccountInvoice, self).action_number(cr, uid, ids, context=context)
141
move_line_obj = self.pool.get('account.move.line')
142
account_obj = self.pool.get('account.account')
143
tier_account_id = account_obj.search(cr, uid, [('type', 'in', ['receivable', 'payable'])])
145
for inv in self.browse(cr, uid, ids, context=context):
146
if inv.type != 'out_invoice' and inv.partner_bank_id.state != 'bvr':
89
ref = inv.get_bvr_ref()
92
cursor.execute('UPDATE account_move SET ref=%s'
95
cursor.execute('UPDATE account_move_line SET ref=%s'
98
cursor.execute('UPDATE account_analytic_line SET ref=%s'
99
' FROM account_move_line '
100
' WHERE account_move_line.move_id = %s '
101
' AND account_analytic_line.move_id = account_move_line.id',
148
move_lines = move_line_obj.search(cr, uid, [('move_id', '=', inv.move_id.id),
149
('account_id', 'in', tier_account_id)])
150
# We keep this branch for compatibility with single BVR report.
151
# This should be cleaned when porting to V8
153
if len(move_lines) == 1:
154
ref = inv.get_bvr_ref()
155
move_id = inv.move_id
157
cr.execute('UPDATE account_move_line SET transaction_ref=%s'
160
self._update_ref_on_account_analytic_line(cr, uid, ref, move_id.id)
162
for move_line in move_line_obj.browse(cr, uid, move_lines, context=context):
163
ref = move_line.get_bvr_ref()
165
cr.execute('UPDATE account_move_line SET transaction_ref=%s'
168
self._update_ref_on_account_analytic_line(cr, uid, ref,
169
move_line.move_id.id)
105
172
def copy(self, cursor, uid, inv_id, default=None, context=None):