~unifield-team/unifield-wm/us-826

« back to all changes in this revision

Viewing changes to financing_contract/format.py

  • Committer: Quentin THEURET
  • Date: 2016-03-04 12:15:00 UTC
  • Revision ID: qt@tempo-consulting.fr-20160304121500-u2ay8zrf83ih9fu3
US-826 [IMP] Change the way to check if products is not consistent on add multiple line wizard

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
from osv import fields, osv
23
23
 
24
24
class financing_contract_format(osv.osv):
25
 
    
 
25
 
26
26
    _name = "financing.contract.format"
27
 
    
 
27
    _rec_name = 'format_name'
 
28
 
28
29
    _columns = {
29
30
        'format_name': fields.char('Name', size=64, required=True),
30
31
        'reporting_type': fields.selection([('project','Total project only'),
32
33
                                            ('all', 'Earmarked and total project')], 'Reporting type', required=True),
33
34
        # For contract only, but needed for line domain;
34
35
        # we need to keep them available
 
36
        'overhead_percentage': fields.float('Overhead percentage'),
 
37
        'overhead_type': fields.selection([('cost_percentage','Percentage of direct costs'),
 
38
                                           ('grant_percentage','Percentage of grant')], 'Overhead calculation mode'),
35
39
        'eligibility_from_date': fields.date('Eligibility date from'),
36
40
        'eligibility_to_date': fields.date('Eligibility date to'),
37
41
        'funding_pool_ids': fields.one2many('financing.contract.funding.pool.line', 'contract_id', 'Funding Pools'),
38
42
        'cost_center_ids': fields.many2many('account.analytic.account', 'financing_contract_cost_center', 'contract_id', 'cost_center_id', string='Cost Centers'),
 
43
 
 
44
        'hidden_instance_id': fields.many2one('msf.instance','Proprietary Instance'),
39
45
    }
40
 
    
 
46
 
41
47
    _defaults = {
42
48
        'format_name': 'Format',
43
49
        'reporting_type': 'all',
 
50
        'overhead_type': 'cost_percentage',
44
51
    }
45
 
    
 
52
 
46
53
    def name_get(self, cr, uid, ids, context=None):
47
54
        result = self.browse(cr, uid, ids, context=context)
48
55
        res = []
50
57
            format_name = rs.format_name
51
58
            res += [(rs.id, format_name)]
52
59
        return res
53
 
        
 
60
 
 
61
    _sql_constraints = [
 
62
        ('date_overlap', 'check(eligibility_from_date < eligibility_to_date)', 'The "Eligibility Date From" should be sooner than the "Eligibility Date To".'),
 
63
    ]
 
64
 
 
65
 
54
66
financing_contract_format()
55
67
 
56
 
class account_account(osv.osv):
57
 
    _name = 'account.account'
58
 
    _inherit = 'account.account'
 
68
class account_destination_link(osv.osv):
 
69
    _name = 'account.destination.link'
 
70
    _inherit = 'account.destination.link'
59
71
 
60
 
    def _get_used(self, cr, uid, ids, field_name, arg, context=None):
61
 
        res = {}
 
72
    def _get_used_in_contract(self, cr, uid, ids, field_name, arg, context=None):
 
73
        ids_to_exclude = {}
62
74
        if context is None:
63
75
            context = {}
64
76
        exclude = {}
65
77
 
66
78
        if not context.get('contract_id') and not context.get('donor_id'):
67
79
            for id in ids:
68
 
                res[id] = False
69
 
            return res
 
80
                ids_to_exclude[id] = False
 
81
            return ids_to_exclude
70
82
 
71
83
        if context.get('contract_id'):
72
84
            ctr_obj = self.pool.get('financing.contract.contract')
75
87
            ctr_obj = self.pool.get('financing.contract.donor')
76
88
            id_toread = context['donor_id']
77
89
 
78
 
        exclude = {}
 
90
        active_id = context.get('active_id', False)
79
91
        for line in ctr_obj.browse(cr, uid, id_toread).actual_line_ids:
80
 
            for acc in line.account_ids:
81
 
                exclude[acc.id] = True
 
92
            if not active_id or line.id != active_id:
 
93
                for account_destination in line.account_destination_ids: # exclude from other duplet format lines
 
94
                    exclude[account_destination.id] = True
 
95
                for account_quadruplet in line.account_quadruplet_ids: # exclude from other quadruplet format lines
 
96
                    # UFTP-16: The list of all duplet acc/destination needs to be grey if one line of combination in the quad has been selected
 
97
                    duplet_ids_to_exclude = self.search(cr, uid, [('account_id', '=', account_quadruplet.account_id.id),('destination_id','=',account_quadruplet.account_destination_id.id)])
 
98
                    for item in duplet_ids_to_exclude:
 
99
                        exclude[item] = True
 
100
 
82
101
        for id in ids:
83
 
            res[id] = id in exclude
84
 
        return res
 
102
            ids_to_exclude[id] = id in exclude
 
103
        return ids_to_exclude
85
104
 
86
 
    def _search_used(self, cr, uid, obj, name, args, context=None):
 
105
    def _search_used_in_contract(self, cr, uid, obj, name, args, context=None):
87
106
        if not args:
88
107
            return []
89
108
        if context is None:
101
120
 
102
121
        exclude = {}
103
122
        for line in ctr_obj.browse(cr, uid, id_toread).actual_line_ids:
104
 
            for acc in line.account_ids:
105
 
                exclude[acc.id] = True
 
123
            if not context.get('active_id', False) or line.id != context['active_id']:
 
124
                for account_destination in line.account_destination_ids:
 
125
                    exclude[account_destination.id] = True
 
126
                for account_quadruplet in line.account_quadruplet_ids:
 
127
                    exclude[account_quadruplet.account_destination_id.id] = True
106
128
 
107
129
        return [('id', 'not in', exclude.keys())]
108
130
 
109
131
    _columns = {
110
 
        'used': fields.function(_get_used, method=True, type='boolean', string='Used', fnct_search=_search_used),
 
132
        'used_in_contract': fields.function(_get_used_in_contract, method=True, type='boolean', string='Used', fnct_search=_search_used_in_contract),
111
133
    }
112
134
 
113
135
    def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
114
136
        if context is None:
115
137
            context = {}
116
138
        if view_type == 'tree' and (context.get('contract_id') or context.get('donor_id')) :
117
 
            view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'financing_contract', 'view_account_for_contract_tree')[1]
118
 
        return super(account_account, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
119
 
 
120
 
account_account()
 
139
            view_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'financing_contract', 'view_account_destination_link_for_contract_tree')[1]
 
140
        return super(account_destination_link, self).fields_view_get(cr, uid, view_id, view_type, context, toolbar, submenu)
 
141
 
 
142
 
 
143
 
 
144
account_destination_link()
121
145
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: