~scigghia/openobject-italia/riba_v7_scigghia_2

« back to all changes in this revision

Viewing changes to l10n_it_ricevute_bancarie/wizard/wizard_accreditation.py

  • Committer: Lorenzo Battistini
  • Date: 2013-12-16 15:19:16 UTC
  • Revision ID: lorenzo.battistini@agilebg.com-20131216151916-h1jljkoay1twqi56
[IMP] PEP8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
##############################################################################
3
 
#  
 
3
#
4
4
#    Copyright (C) 2012 Agile Business Group sagl (<http://www.agilebg.com>)
5
5
#    Copyright (C) 2012 Domsense srl (<http://www.domsense.com>)
6
6
#    Copyright (C) 2012 Associazione OpenERP Italia
21
21
#
22
22
##############################################################################
23
23
 
24
 
from openerp.osv import fields,orm
 
24
from openerp.osv import fields, orm
25
25
from tools.translate import _
26
26
import netsvc
27
27
 
 
28
 
28
29
class riba_accreditation(orm.TransientModel):
29
 
    
 
30
 
30
31
    def _get_accreditation_journal_id(self, cr, uid, context=None):
31
 
        return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'accreditation_journal_id', context=context)
32
 
    
 
32
        return self.pool.get(
 
33
            'riba.configurazione').get_default_value_by_distinta(
 
34
            cr, uid, 'accreditation_journal_id', context=context)
 
35
 
33
36
    def _get_accreditation_account_id(self, cr, uid, context=None):
34
 
        return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'accreditation_account_id', context=context)
35
 
    
 
37
        return self.pool.get(
 
38
            'riba.configurazione').get_default_value_by_distinta(
 
39
            cr, uid, 'accreditation_account_id', context=context)
 
40
 
36
41
    def _get_bank_account_id(self, cr, uid, context=None):
37
 
        return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'bank_account_id', context=context)
38
 
    
 
42
        return self.pool.get(
 
43
            'riba.configurazione').get_default_value_by_distinta(
 
44
            cr, uid, 'bank_account_id', context=context)
 
45
 
39
46
    def _get_bank_expense_account_id(self, cr, uid, context=None):
40
 
        return self.pool.get('riba.configurazione').get_default_value_by_distinta( cr, uid, 'bank_expense_account_id', context=context)
41
 
    
 
47
        return self.pool.get(
 
48
            'riba.configurazione').get_default_value_by_distinta(
 
49
            cr, uid, 'bank_expense_account_id', context=context)
 
50
 
42
51
    def _get_accreditation_amount(self, cr, uid, context=None):
43
52
        if context is None:
44
53
            context = {}
45
54
        if not context.get('active_id', False):
46
55
            return False
47
56
        distinta_pool = self.pool.get('riba.distinta')
48
 
        distinta = distinta_pool.browse(cr, uid, context['active_id'], context=context)
 
57
        distinta = distinta_pool.browse(
 
58
            cr, uid, context['active_id'], context=context)
49
59
        amount = 0.0
50
60
        for line in distinta.line_ids:
51
61
            amount += line.amount
52
62
        return amount
53
 
    
 
63
 
54
64
    _name = "riba.accreditation"
55
65
    _description = "Bank accreditation"
56
66
    _columns = {
57
 
        'accreditation_journal_id' : fields.many2one('account.journal', "Accreditation journal", 
 
67
        'accreditation_journal_id': fields.many2one(
 
68
            'account.journal', "Accreditation journal",
58
69
            domain=[('type', '=', 'bank')]),
59
 
        'accreditation_account_id' : fields.many2one('account.account', "Ri.Ba. bank account"),
 
70
        'accreditation_account_id': fields.many2one(
 
71
            'account.account', "Ri.Ba. bank account"),
60
72
        'accreditation_amount': fields.float('Credit amount'),
61
 
        'bank_account_id' : fields.many2one('account.account', "Bank account", 
 
73
        'bank_account_id': fields.many2one(
 
74
            'account.account', "Bank account",
62
75
            domain=[('type', '=', 'liquidity')]),
63
76
        'bank_amount': fields.float('Versed amount'),
64
 
        'bank_expense_account_id' : fields.many2one('account.account', "Bank Expenses account"),
 
77
        'bank_expense_account_id': fields.many2one(
 
78
            'account.account', "Bank Expenses account"),
65
79
        'expense_amount': fields.float('Expenses amount'),
66
80
        }
67
81
 
72
86
        'bank_expense_account_id': _get_bank_expense_account_id,
73
87
        'accreditation_amount': _get_accreditation_amount,
74
88
        }
75
 
        
 
89
 
76
90
    def skip(self, cr, uid, ids, context=None):
77
91
        if context is None:
78
92
            context = {}
83
97
        wf_service.trg_validate(
84
98
            uid, 'riba.distinta', active_id, 'accredited', cr)
85
99
        return {'type': 'ir.actions.act_window_close'}
86
 
        
 
100
 
87
101
    def create_move(self, cr, uid, ids, context=None):
88
102
        if context is None:
89
103
            context = {}
92
106
        if not active_id:
93
107
            raise orm.except_orm(_('Error'), _('No active ID found'))
94
108
        move_pool = self.pool.get('account.move')
95
 
        move_line_pool = self.pool.get('account.move.line')
96
109
        distinta_pool = self.pool.get('riba.distinta')
97
110
        distinta = distinta_pool.browse(cr, uid, active_id, context=context)
98
 
        wizard = self.browse(cr,uid,ids)[0]
99
 
        if not wizard.accreditation_journal_id or not wizard.accreditation_account_id or not wizard.bank_account_id or not wizard.bank_expense_account_id:
 
111
        wizard = self.browse(cr, uid, ids)[0]
 
112
        if (
 
113
            not wizard.accreditation_journal_id
 
114
            or not wizard.accreditation_account_id
 
115
            or not wizard.bank_account_id or not wizard.bank_expense_account_id
 
116
        ):
100
117
            raise orm.except_orm(_('Error'), _('Every account is mandatory'))
101
118
        move_vals = {
102
119
            'ref': _('Accreditation Ri.Ba. %s') % distinta.name,
103
120
            'journal_id': wizard.accreditation_journal_id.id,
104
121
            'line_id': [
105
 
                (0,0, {
 
122
                (0, 0, {
106
123
                    'name':  _('Credit'),
107
124
                    'account_id': wizard.accreditation_account_id.id,
108
125
                    'credit': wizard.accreditation_amount,
109
126
                    'debit': 0.0,
110
127
                    }),
111
 
                (0,0, {
 
128
                (0, 0, {
112
129
                    'name':  _('Bank'),
113
130
                    'account_id': wizard.bank_account_id.id,
114
131
                    'debit': wizard.bank_amount,
115
132
                    'credit': 0.0,
116
133
                    }),
117
 
                (0,0, {
 
134
                (0, 0, {
118
135
                    'name':  _('Bank'),
119
136
                    'account_id': wizard.bank_expense_account_id.id,
120
137
                    'debit': wizard.expense_amount,
135
152
            'target': 'current',
136
153
            'res_id': move_id or False,
137
154
        }
138
 
        
139