def empowering_patch(self, cursor, uid, ids, data=None, context=None): polissa_f = ['name', 'etag'] em = self.pool.get('empowering.api').service result = [] for polissa in self.read(cursor, uid, ids, polissa_f, context=context): if not polissa['etag']: self.empowering_post(cursor, uid, [polissa['id']]) continue amon_converter = AmonConverter(PoolWrapper(self.pool, cursor, uid)) if not data: data = amon_converter.contract_to_amon(polissa['id'])[0] res = em.contract(polissa['name']).update(data, polissa['etag']) result.append(none_to_false(res)) if check_response(res, data): self.write(cursor, uid, [polissa['id']], {'etag': res['_etag']}) return result
def write(self, cursor, uid, ids, vals, context=None): polissa_obj = self.pool.get('giscedata.polissa') res = super(GiscedataCupsPs, self).write(cursor, uid, ids, vals, context=context) amon_converter = AmonConverter(PoolWrapper(self.pool, cursor, uid)) trigger_fields = [ 'id_municipi', 'id_poblacio', 'tv', 'nv', 'pnp', 'es', 'pt', 'pu', 'cpo', 'cpa', 'dp' ] if set(vals.keys()) & set(trigger_fields): pols = polissa_obj.search(cursor, uid, [('cups.id', 'in', ids), ('state', 'not in', ('esborrany', 'validar'))]) for polissa_id in pols: data = amon_converter.contract_to_amon(polissa_id)[0] data = dict(meteringPointId=data['meteringPointId'], customer=data['customer']) polissa_obj.empowering_patch(cursor, uid, pols, data) return res
def empowering_post(self, cursor, uid, ids, context=None): res = [] amon_converter = AmonConverter(PoolWrapper(self.pool, cursor, uid)) em = self.pool.get('empowering.api').service for pol in self.read(cursor, uid, ids, ['modcontractuals_ids', 'name']): first = True upd = [] for modcon_id in reversed(pol['modcontractuals_ids']): amon_data = amon_converter.contract_to_amon( pol['id'], {'modcon_id': modcon_id})[0] if first: response = em.contracts().create(amon_data) first = False else: etag = upd[-1]['_etag'] response = em.contract(pol['name']).update(amon_data, etag) if check_response(response, amon_data): upd.append(response) if upd: res.append(upd[-1]) self.write(cursor, uid, [pol['id']], {'etag': upd[-1]['_etag']}) return res