Exemple #1
0
 def assign_geo_localize(self,
                         cr,
                         uid,
                         ids,
                         latitude=False,
                         longitude=False,
                         context=None):
     if latitude and longitude:
         self.write(cr,
                    uid,
                    ids, {
                        'partner_latitude': latitude,
                        'partner_longitude': longitude
                    },
                    context=context)
         return True
     # Don't pass context to browse()! We need country name in english below
     for lead in self.browse(cr, uid, ids):
         if lead.partner_latitude and lead.partner_longitude:
             continue
         if lead.country_id:
             result = geo_find(
                 geo_query_address(street=lead.street,
                                   zip=lead.zip,
                                   city=lead.city,
                                   state=lead.state_id.name,
                                   country=lead.country_id.name))
             if result:
                 self.write(cr,
                            uid, [lead.id], {
                                'partner_latitude': result[0],
                                'partner_longitude': result[1]
                            },
                            context=context)
     return True
 def assign_geo_localize(self, cr, uid, ids, latitude=False, longitude=False, context=None):
     if latitude and longitude:
         self.write(cr, uid, ids, {"partner_latitude": latitude, "partner_longitude": longitude}, context=context)
         return True
     # Don't pass context to browse()! We need country name in english below
     for lead in self.browse(cr, uid, ids):
         if lead.partner_latitude and lead.partner_longitude:
             continue
         if lead.country_id:
             result = geo_find(
                 geo_query_address(
                     street=lead.street,
                     zip=lead.zip,
                     city=lead.city,
                     state=lead.state_id.name,
                     country=lead.country_id.name,
                 )
             )
             if result:
                 self.write(
                     cr,
                     uid,
                     [lead.id],
                     {"partner_latitude": result[0], "partner_longitude": result[1]},
                     context=context,
                 )
     return True
Exemple #3
0
    def add_geo_localization_details(self, vals):
        """Add geo localization details to the current partner."""
        # skip during dry runs.
        if self.__dryRun__:
            return vals

        street = vals.get('street')
        zip = vals.get('zip')
        city = vals.get('city')
        country_id = vals.get('country_id')

        if street and zip and city and country_id:
            result = geo_find(
                geo_query_address(
                    street=vals.get('street', '').encode(__codec__),
                    zip=vals.get('zip', '').encode(__codec__),
                    city=vals.get('city', '').encode(__codec__),
                    country=self.env['res.country'].browse(
                        vals.get('country_id')).name.encode(__codec__),
                ))
            if result:
                vals['partner_latitude'] = result[0]
                vals['partner_longitude'] = result[1]
                vals['date_localization'] = fields.Date.context_today(self)
        else:
            _logger.debug('Missing details. Skipping.')
        return vals
Exemple #4
0
 def add_geo_localization_details(self, vals):
     result = geo_find(
         geo_query_address(
             street=vals.get('street'),
             zip=vals.get('zip'),
             city=vals.get('city'),
             country=self.env['res.country'].browse(
                 vals.get('country_id')).name,
         )
     )
     if result:
         vals['partner_latitude'] = result[0]
         vals['partner_longitude'] = result[1]
         vals['date_localization'] = fields.Date.context_today(self)
     return vals
Exemple #5
0
 def geo_localize(self):
     for partner in self:
         if not partner:
             continue
         result = geo_find(geo_query_address(
             street=partner.street,
             township=partner.township_id.name,
             district=partner.district_id.name,
             province=partner.province_id.name,
             zip=partner.zip,
             country=partner.country_id.name))
         if result:
             partner.write({
                 'partner_latitude': result[0],
                 'partner_longitude': result[1],
                 'date_localization': fields.Date.context_today(self)
             })
     return True