Exemple #1
0
    def building_to_amon(self,building_id):
        """ Convert building to AMON

         {
              "buildingConstructionYear": 2014,
              "dwellingArea": 196,
              "propertyType": "primary",
              "buildingType": "Apartment",
              "dwellingPositionInBuilding": "first_floor",
              "dwellingOrientation": "SE",
              "buildingWindowsType": "double_panel",
              "buildingWindowsFrame": "PVC",
              "buildingCoolingSource": "electricity",
              "buildingHeatingSource": "district_heating",
              "buildingHeatingSourceDhw": "gasoil",
              "buildingSolarSystem": "not_installed"
         }
        """
        if not building_id:
            return None

        O = self.O
        building_obj = O.EmpoweringCupsBuilding

        fields_to_read =  ['buildingConstructionYear', 'dwellingArea', 'propertyType', 'buildingType', 'dwellingPositionInBuilding',
                           'dwellingOrientation', 'buildingWindowsType', 'buildingWindowsFrame',
                           'buildingCoolingSource', 'buildingHeatingSource', 'buildingHeatingSourceDhw',
                           'buildingSolarSystem']
        building = building_obj.read(building_id)

        return remove_none(null_to_none({ field: building[field] for field in fields_to_read}))
Exemple #2
0
    def device_to_amon(self, device_ids):
        """Convert a device to AMON.

        {
            "utilityId": "Utility Id",
            "externalId": required string UUID,
            "meteringPointId": required string UUID,
            "metadata": {
                "max": "Max number",
                "serial": "Device serial",
                "owner": "empresa/client"
            },
        }
        """
        O = self.O
        res = []
        if not hasattr(device_ids, '__iter__'):
            device_ids = [device_ids]
        for dev_id in device_ids:
            dev = O.GiscedataLecturesComptador.browse(dev_id)
            if dev.propietat == "empresa":
                dev.propietat = "company"
            res.append(remove_none({
                "utilityId": "1",
                "externalId": make_uuid('giscedata.lectures.comptador', dev_id),
                "meteringPointId": make_uuid('giscedata.cups.ps', dev.polissa.cups.name),
                "metadata": {
                   "max": dev.giro,
                   "serial": dev.name,
                   "owner": dev.propietat,
                }
            }))
        return res
Exemple #3
0
    def device_to_amon(self, device_ids):
        """Convert a device to AMON.

        {
            "utilityId": "Utility Id",
            "externalId": required string UUID,
            "meteringPointId": required string UUID,
            "metadata": {
                "max": "Max number",
                "serial": "Device serial",
                "owner": "empresa/client"
            },
        }
        """
        O = self.O
        res = []
        if not hasattr(device_ids, '__iter__'):
            device_ids = [device_ids]
        for dev_id in device_ids:
            dev = O.GiscedataLecturesComptador.browse(dev_id)
            if dev.propietat == "empresa":
                dev.propietat = "company"
            res.append(remove_none({
                "utilityId": "1",
                "externalId": make_uuid('giscedata.lectures.comptador', dev_id),
                "meteringPointId": make_uuid('giscedata.cups.ps', dev.polissa.cups.name),
                "metadata": {
                   "max": dev.giro,
                   "serial": dev.name,
                   "owner": dev.propietat,
                }
            }))
        return res
Exemple #4
0
 def power_to_amon(self, modcons_id):
     """ Convert power to AMON.
     "power_": {
       "power": 123,
       "dateStart": "2014-10-11T00:00:00Z",
       "dateEnd": null,
     }
     """
     modcon = self.find_changes(modcons_id, 'potencia')[-1]
     return remove_none({
       "power": int(modcon['potencia'] * 1000),
       "dateStart": make_utc_timestamp(modcon['data_inici']),
       "dateEnd": make_utc_timestamp(eofday(modcon['data_final']))
     })
Exemple #5
0
 def tariff_to_amon(self, modcons_id):
     """ Convert tariff to AMON.
     "tariff_": {
       "tariffId": "tariffID-123",
       "dateStart": "2014-10-11T00:00:00Z",
       "dateEnd": null,
     }
     """
     modcon = self.find_changes(modcons_id, 'tarifa')[-1]
     return remove_none({
       "tariffId": modcon['tarifa'][1],
       "dateStart": make_utc_timestamp(modcon['data_inici']),
       "dateEnd": make_utc_timestamp(eofday(modcon['data_final']))
     })
Exemple #6
0
    def report_to_amon(self, date_start, partner_id):
        """Convert report to AMON.

        {
            "language": "ca_ES",
            "initialMonth": "201701"
        }
        """
        O = self.O
        partner_obj = O.ResPartner
        partner = partner_obj.read(partner_id, ['lang'])

        initial_month = int(datetime.strptime(date_start, '%Y-%m-%d').strftime('%Y%m'))
        return remove_none({
            "language": partner['lang'],
            "initialMonth": initial_month,
            })
Exemple #7
0
    def service_to_amon(self,service_id):
        """ Convert service to AMON

         {
            "OT701": "p1;P2;px"
         }
        """
        if not service_id:
            return None

        O = self.O
        service_obj = O.EmpoweringModcontractualService
        fields_to_read = ['OT101', 'OT103', 'OT105', 'OT106', 'OT109', 'OT201', 'OT204', 'OT401', 'OT502', 'OT503', 'OT603',
                         'OT603g', 'OT701', 'OT703']
        service = service_obj.read(service_id)

        return remove_none(null_to_none({ field: service[field] for field in fields_to_read}))
Exemple #8
0
    def eprofile_to_amon(self,profile_id):
        """ Convert profile to AMON

        {
          "totalPersonsNumber": 3,
          "minorsPersonsNumber": 0,
          "workingAgePersonsNumber": 2,
          "retiredAgePersonsNumber": 1,
          "malePersonsNumber": 2,
          "femalePersonsNumber": 1,
          "educationLevel": {
            "edu_prim": 0,
            "edu_sec": 1,
            "edu_uni": 1,
            "edu_noStudies": 1
        }
        """
        if not profile_id:
            return None

        O = self.O
        profile_obj = O.EmpoweringModcontractualProfile
        fields_to_read = ['totalPersonsNumber', 'minorPersonsNumber', 'workingAgePersonsNumber', 'retiredAgePersonsNumber',
                          'malePersonsNumber', 'femalePersonsNumber', 'eduLevel_prim', 'eduLevel_sec', 'eduLevel_uni',
                          'eduLevel_noStudies']
        profile = profile_obj.read(profile_id)

        return remove_none(null_to_none({
            "totalPersonsNumber": profile['totalPersonsNumber'],
            "minorsPersonsNumber": profile['minorPersonsNumber'],
            "workingAgePersonsNumber": profile['workingAgePersonsNumber'],
            "retiredAgePersonsNumber": profile['retiredAgePersonsNumber'],
            "malePersonsNumber": profile['malePersonsNumber'],
            "femalePersonsNumber": profile['femalePersonsNumber'],
            "educationLevel": {
                "edu_prim": profile['eduLevel_prim'],
                "edu_sec": profile['eduLevel_sec'],
                "edu_uni": profile['eduLevel_uni'],
                "edu_noStudies": profile['eduLevel_noStudies']
            }
        }))
Exemple #9
0
    def contract_to_amon(self, contract_ids, context=None):
        """Converts contracts to AMON.

        {
          "payerId":"payerID-123",
          "ownerId":"ownerID-123",
          "signerId":"signerID-123",
          "power":123,
          "dateStart":"2013-10-11T16:37:05Z",
          "dateEnd":null,
          "contractId":"contractID-123",
          "customer":{
            "customerId":"payerID-123",
            "address":{
              "city":"city-123",
              "cityCode":"cityCode-123",
              "countryCode":"ES",
              "country":"Spain",
              "street":"street-123",
              "postalCode":"postalCode-123"
            }
          },
          "meteringPointId":"c1759810-90f3-012e-0404-34159e211070",
          "devices":[
            {
              "dateStart":"2013-10-11T16:37:05Z",
              "dateEnd":null,
              "deviceId":"c1810810-0381-012d-25a8-0017f2cd3574"
            }
          ],
          "version":1,
          "activityCode":"activityCode",
          "tariffId":"tariffID-123",
        }
        """
        O = self.O
        if not context:
            context = {}
        res = []
        pol = O.GiscedataPolissa
        modcon_obj = O.GiscedataPolissaModcontractual
        if not hasattr(contract_ids, '__iter__'):
            contract_ids = [contract_ids]
        fields_to_read = ['modcontractual_activa', 'name', 'cups', 'comptadors', 'state']
        for polissa in pol.read(contract_ids, fields_to_read):
            if polissa['state'] in ('esborrany', 'validar'):
                continue
            if 'modcon_id' in context:
                modcon = modcon_obj.read(context['modcon_id'])
            elif polissa['modcontractual_activa']:
                modcon = modcon_obj.read(polissa['modcontractual_activa'][0])
            else:
                logger.error("Problema amb la polissa %s" % polissa['name'])
                continue
            contract = {
                'ownerId': make_uuid('res.partner', modcon['titular'][0]),
                'payerId': make_uuid('res.partner', modcon['pagador'][0]),
                'dateStart': make_utc_timestamp(modcon['data_inici']),
                'dateEnd': make_utc_timestamp(modcon['data_final']),
                'contractId': polissa['name'],
                'tariffId': modcon['tarifa'][1],
                'power': int(modcon['potencia'] * 1000),
                'version': int(modcon['name']),
                'activityCode': modcon['cnae'] and modcon['cnae'][1] or None,
                'customer': {
                    'customerId': make_uuid('res.partner', modcon['titular'][0]),
                },
                'devices': self.device_to_amon(polissa['comptadors'])
            }
            cups = self.cups_to_amon(modcon['cups'][0])
            recursive_update(contract, cups)
            res.append(remove_none(contract, context))
        return res
Exemple #10
0
    def contract_to_amon(self, contract_ids, context=None):
        """Converts contracts to AMON.
        {
          "contractId": "contractId-123",
          "ownerId": "ownerId-123",
          "payerId": "payerId-123",
          "signerId": "signerId-123",
          "power": 123,
          "power_": {
            "power": 123,
            "dateStart": "2014-10-11T00:00:00Z",
            "dateEnd": null,
          },
          "powerHistory": [
            {
              "power": 122,
              "dateStart": "2013-10-11T16:37:05Z",
              "dateEnd": "2014-10-10T23:59:59Z"
            }
          ],
          "dateStart": "2013-10-11T16:37:05Z",
          "dateEnd": null,
          "climaticZone": "climaticZoneId-123",
          "weatherStationId": "weatherStatioId-123",
          "version": 1,
          "activityCode": "activityCode",
          "tariffId": "tariffID-123",
          "tariff_": {
            "tariffId": "tariffID-123",
            "dateStart": "2014-10-11T00:00:00Z",
            "dateEnd": null,
          },
          "tariffHistory": [
            {
              "tariffId": "tariffID-122",
              "dateStart": "2013-10-11T16:37:05Z",
              "dateEnd": "2014-10-10T23:59:59Z"
            }
          ],
          "meteringPointId": "c1759810-90f3-012e-0404-34159e211070",
          "experimentalGroupUser": True,
          "experimentalGroupUserTest": True,
          "activeUser": True,
          "activeUserDate": "2014-10-11T16:37:05Z",
          "customer": {
            "customerId": "customerId-123",
            "address": {
              "buildingId": "building-123",
              "city": "city-123",
              "cityCode": "cityCode-123",
              "countryCode": "ES",
              "country": "Spain",
              "street": "street-123",
              "postalCode": "postalCode-123",
              "province": "Barcelona",
              "provinceCode": "provinceCode-123",
              "parcelNumber": "parcelNumber-123"
            },
            "buildingData": {
              "buildingConstructionYear": 2014,
              "dwellingArea": 196,
              "propertyType": "primary",
              "buildingType": "Apartment",
              "dwellingPositionInBuilding": "first_floor",
              "dwellingOrientation": "SE",
              "buildingWindowsType": "double_panel",
              "buildingWindowsFrame": "PVC",
              "buildingCoolingSource": "electricity",
              "buildingHeatingSource": "district_heating",
              "buildingHeatingSourceDhw": "gasoil",
              "buildingSolarSystem": "not_installed"
            },
            "profile": {
              "totalPersonsNumber": 3,
              "minorsPersonsNumber": 0,
              "workingAgePersonsNumber": 2,
              "retiredAgePersonsNumber": 1,
              "malePersonsNumber": 2,
              "femalePersonsNumber": 1,
              "educationLevel": {
                "edu_prim": 0,
                "edu_sec": 1,
                "edu_uni": 1,
                "edu_noStudies": 1
              }
            },
            "customisedGroupingCriteria": {
              "criteria_1": "CLASS 1",
              "criteria_2": "XXXXXXX",
              "criteria_3": "YYYYYYY"
            },
            "customisedServiceParameters": {
              "OT701": "p1;P2;px"
            }
          },
          "devices": [
            {
              "dateStart": "2013-10-11T16:37:05Z",
              "dateEnd": null,
              "deviceId": "c1810810-0381-012d-25a8-0017f2cd3574"
            }
          ]
        }
        """
        O = self.O
        if not context:
            context = {}
        first = context.get('first', None)

        res = []
        pol = O.GiscedataPolissa
        modcon_obj = O.GiscedataPolissaModcontractual

        cups_obj = O.GiscedataCupsPs
        muni_obj = O.ResMunicipi

        building_obj = O.EmpoweringCupsBuilding
        profile_obj = O.EmpoweringModcontractualProfile
        service_obj = O.EmpoweringModcontractualService

        if not hasattr(contract_ids, '__iter__'):
            contract_ids = [contract_ids]
        fields_to_read = ['modcontractual_activa', 'modcontractuals_ids',
            'name', 'cups', 'comptadors', 'state', 'data_alta', 'data_baixa']
        for polissa in pol.read(contract_ids, fields_to_read):
            if polissa['state'] in ('esborrany', 'validar'):
                continue

            modcon_id = None
            if 'modcon_id' in context:
                modcon_id = context['modcon_id']
            elif polissa['modcontractual_activa']:
                modcon_id = polissa['modcontractual_activa'][0]
            else:
                logger.error("Problema amb la polissa %s" % polissa['name'])
                continue
            modcon = modcon_obj.read(modcon_id)
            modcons_id = polissa['modcontractuals_ids']

            def  get_first(x):
                return x[0] if x else None

            building_id = get_first(building_obj.search([('cups_id', '=', modcon['cups'][0])]))
            profile_id = get_first(profile_obj.search([('modcontractual_id', '=', modcon_id)]))
            service_id = get_first(service_obj.search([('modcontractual_id', '=', modcon_id)]))


            contract = {
                'ownerId': make_uuid('res.partner', modcon['titular'][0]),
                'payerId': make_uuid('res.partner', modcon['pagador'][0]),
                'dateStart': make_utc_timestamp(polissa['data_alta']),
                'dateEnd': make_utc_timestamp(eofday(polissa['data_baixa'])),
                'contractId': polissa['name'],
                'tariffId': modcon['tarifa'][1],
                'tariff_': self.tariff_to_amon(modcons_id),
                'tariffHistory': self.tariffHistory_to_amon(modcons_id),
                'power': int(modcon['potencia'] * 1000),
                'power_': self.power_to_amon(modcons_id),
                'powerHistory': self.powerHistory_to_amon(modcons_id),
                'version': int(modcon['name']),
                'climaticZone': self.cups_to_climaticZone(modcon['cups'][0]),
                'activityCode': modcon['cnae'] and modcon['cnae'][1].split(' - ')[0] or None,
                'customer': {
                    'customerId': make_uuid('res.partner', modcon['titular'][0]),
                    'buildingData': self.building_to_amon(building_id),
                    'profile': self.eprofile_to_amon(profile_id),
                    'customisedServiceParameters': self.service_to_amon(service_id)
                },
                'devices': self.devices_to_amon(polissa['comptadors']),
                'report': self.report_to_amon(polissa['data_alta'], modcon['pagador'][0])
            }
            cups = self.cups_to_amon(modcon['cups'][0])
            recursive_update(contract, cups)
            res.append(remove_none(contract, context))
        return res
 def dump_to_file(self, filename):
     with open(filename, 'w') as data_file:
         json.dump(remove_none(self.root), data_file, indent=4)
 def dump(self):
     return json.dumps(remove_none(self.root))