~acsone-openerp/banking-addons/bank-statement-reconcile-70-improve-acc-number-completion

« back to all changes in this revision

Viewing changes to account_statement_commission/commission.py

  • Committer: Guewen Baconnier
  • Author(s): Virgil Dupras
  • Date: 2013-07-22 09:06:56 UTC
  • mfrom: (90.2.5 purge-base-import)
  • Revision ID: guewen.baconnier@camptocamp.com-20130722090656-sm1zkp5tqq5tn72q
[IMP] Extracted the commission-handling feature from account_statement_base_import to a new module account_statement_commission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from openerp.tools.translate import _
 
2
import datetime
 
3
from openerp.osv import orm, fields
 
4
 
 
5
def float_or_zero(val):
 
6
    return float(val) if val else 0.0
 
7
 
 
8
class AccountStatementProfil(orm.Model):
 
9
    _inherit = "account.statement.profile"
 
10
 
 
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.
 
14
        """
 
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:
 
19
            return
 
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
 
23
        comm_values = {
 
24
            'name': 'IN ' + _('Commission line'),
 
25
            'date': datetime.datetime.now().date(),
 
26
            'amount': global_commission_amount,
 
27
            'partner_id': partner_id,
 
28
            'type': 'general',
 
29
            'statement_id': statement_id,
 
30
            'account_id': commission_account_id,
 
31
            'ref': 'commission',
 
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,
 
35
        }
 
36
        statement_line_obj = self.pool.get('account.bank.statement.line')
 
37
        statement_line_obj.create(cr, uid, comm_values, context=context)
 
38
 
 
39
class AccountStatementLineWithCommission(orm.Model):
 
40
    _inherit = "account.bank.statement.line"
 
41
    _columns = {
 
42
        'commission_amount': fields.sparse(
 
43
            type='float',
 
44
            string='Line Commission Amount',
 
45
            serialization_field='additionnal_bank_fields'),
 
46
    }
 
47
 
 
48
class CreditPartnerStatementImporter(orm.TransientModel):
 
49
    _inherit = "credit.statement.import"
 
50
 
 
51
    _columns = {
 
52
        'commission_account_id': fields.many2one('account.account',
 
53
                                                 'Commission account'),
 
54
        'commission_analytic_id': fields.many2one('account.analytic.account',
 
55
                                                 'Commission analytic account'),
 
56
    }
 
57
 
 
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)
 
61
        if profile_id:
 
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
 
68
        return res
 
 
b'\\ No newline at end of file'