1
from openerp.tools.translate import _
3
from openerp.osv import orm, fields
5
def float_or_zero(val):
6
return float(val) if val else 0.0
8
class AccountStatementProfil(orm.Model):
9
_inherit = "account.statement.profile"
11
def _write_extra_statement_lines(
12
self, cr, uid, parser, result_row_list, profile, statement_id, context):
13
"""Prepare the global commission line if there is one.
15
global_commission_amount = 0
16
for row in parser.result_row_list:
17
global_commission_amount += float_or_zero(row.get('commission_amount', '0.0'))
18
if not global_commission_amount:
20
partner_id = profile.partner_id and profile.partner_id.id or False
21
commission_account_id = profile.commission_account_id and profile.commission_account_id.id or False
22
commission_analytic_id = profile.commission_analytic_id and profile.commission_analytic_id.id or False
24
'name': 'IN ' + _('Commission line'),
25
'date': datetime.datetime.now().date(),
26
'amount': global_commission_amount,
27
'partner_id': partner_id,
29
'statement_id': statement_id,
30
'account_id': commission_account_id,
32
'analytic_account_id': commission_analytic_id,
33
# !! We set the already_completed so auto-completion will not update those values!
34
'already_completed': True,
36
statement_line_obj = self.pool.get('account.bank.statement.line')
37
statement_line_obj.create(cr, uid, comm_values, context=context)
39
class AccountStatementLineWithCommission(orm.Model):
40
_inherit = "account.bank.statement.line"
42
'commission_amount': fields.sparse(
44
string='Line Commission Amount',
45
serialization_field='additionnal_bank_fields'),
48
class CreditPartnerStatementImporter(orm.TransientModel):
49
_inherit = "credit.statement.import"
52
'commission_account_id': fields.many2one('account.account',
53
'Commission account'),
54
'commission_analytic_id': fields.many2one('account.analytic.account',
55
'Commission analytic account'),
58
def onchange_profile_id(self, cr, uid, ids, profile_id, context=None):
59
res = super(CreditPartnerStatementImporter, self).onchange_profile_id(
60
cr, uid, ids, profile_id, context=context)
62
c = self.pool.get("account.statement.profile").browse(
63
cr, uid, profile_id, context=context)
64
res['value']['commission_account_id'] = \
65
c.commission_account_id and c.commission_account_id.id or False
66
res['value']['commission_a'] = \
67
c.commission_analytic_id and c.commission_analytic_id.id or False
b'\\ No newline at end of file'