~julie-w/unifield-wm/UTP-758

« back to all changes in this revision

Viewing changes to account_mcdb/account_period_state.py

  • Committer: jf
  • Date: 2016-01-29 10:21:28 UTC
  • mfrom: (2740.5.2 us-864)
  • Revision ID: jfb@tempo-consulting.fr-20160129102128-sfki9o5v7bjcb260
US-864 [FIX] Fiscal Year state: ignore sync update if new FY created on lower level
US-864 [FIX] Send FY state update on FY creation

lp:~jfb-tempo-consulting/unifield-wm/us-864

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
    _name = "account.period.state"
33
33
 
34
34
    _columns = {
35
 
        'period_id': fields.many2one('account.period', 'Period', required=1, ondelete='cascade'),
36
 
        'instance_id': fields.many2one('msf.instance', 'Proprietary Instance'),
 
35
        'period_id': fields.many2one('account.period', 'Period', required=1, ondelete='cascade', select=1),
 
36
        'instance_id': fields.many2one('msf.instance', 'Proprietary Instance', select=1),
37
37
        'state': fields.selection(ACCOUNT_PERIOD_STATE_SELECTION, 'State',
38
38
                                  readonly=True),
39
39
    }
126
126
 
127
127
    _columns = {
128
128
        'fy_id': fields.many2one('account.fiscalyear', 'Fiscal Year',
129
 
            required=True, ondelete='cascade'),
130
 
        'instance_id': fields.many2one('msf.instance', 'Proprietary Instance'),
 
129
            required=True, ondelete='cascade', select=1),
 
130
        'instance_id': fields.many2one('msf.instance', 'Proprietary Instance', select=1),
131
131
        'state': fields.selection(ACCOUNT_FY_STATE_SELECTION, 'State',
132
132
            readonly=True),
133
133
    }
134
134
 
 
135
    def create(self, cr, uid, vals, context=None):
 
136
        if context is None:
 
137
            context = {}
 
138
        if context.get('sync_update_execution') and not vals.get('fy_id'):
 
139
            # US-841: period is required but we got
 
140
            # an update related to non existant period: ignore it
 
141
            return False
 
142
 
 
143
        return super(account_fiscalyear_state, self).create(cr, uid, vals, context=context)
 
144
 
135
145
    def get_fy(self, cr, uid, ids, context=None):
136
146
        mod_obj = self.pool.get('ir.model.data')
137
147
        view_id = mod_obj.get_object_reference(cr, uid, 'account_mcdb',
166
176
        fy_state_obj = self.pool.get('account.fiscalyear.state')
167
177
        parent = user.company_id.instance_id.id
168
178
        ids_to_write = []
 
179
        state_to_update = []
169
180
        for fy_id in fy_ids:
170
181
            user = self.pool.get('res.users').browse(cr, uid, uid,
171
182
                context=context)
183
194
                        'state': fy['state']
184
195
                    }
185
196
                    self.write(cr, uid, ids, vals, context=context)
186
 
                    for fy_state_id in ids:
187
 
                        fy_state_xml_id = fy_state_obj.get_sd_ref(cr, uid,
188
 
                            fy_state_id)
189
 
                        ids_to_write.append(model_data._get_id(cr, uid, 'sd',
190
 
                            fy_state_xml_id))
 
197
                    state_to_update = ids[:]
191
198
                else:
192
199
                    vals = {
193
200
                        'fy_id': fy['id'],
194
201
                        'instance_id': parent,
195
202
                        'state': fy['state']
196
203
                    }
197
 
                    self.create(cr, uid, vals, context=context)
 
204
                    nid = self.create(cr, uid, vals, context=context)
 
205
                    state_to_update = [nid]
 
206
 
 
207
        for fy_state_id in state_to_update:
 
208
            fy_state_xml_id = fy_state_obj.get_sd_ref(cr, uid, fy_state_id)
 
209
            ids_to_write.append(model_data._get_id(cr, uid, 'sd', fy_state_xml_id))
198
210
 
199
211
        # like for US-649 period state: in context of synchro last_modification
200
212
        # date must be updated on account.fisclayear.state because they are
201
213
        # created with synchro and they need to be sync down to other instances
202
214
        if ids_to_write:
203
215
            model_data.write(cr, uid, ids_to_write,
204
 
                {'last_modification': fields.datetime.now()})
 
216
                {'last_modification': fields.datetime.now(), 'touched': "['state']"})
205
217
        return True
206
218
 
207
219
account_fiscalyear_state()