[MERGE] forward port branch saas-15 up to a27a24c5ed
This commit is contained in:
@@ -289,7 +289,7 @@ class AccountBankStatement(models.Model):
|
||||
WHERE account_id IS NULL AND stl.amount != 0.0 AND not exists (select 1 from account_move_line aml where aml.statement_line_id = stl.id)
|
||||
AND company_id = %s
|
||||
"""
|
||||
params = (self.company_id.id,)
|
||||
params = (self.env.user.company_id.id,)
|
||||
if statements:
|
||||
sql_query += ' AND stl.statement_id IN %s'
|
||||
params += (tuple(statements.ids),)
|
||||
@@ -317,7 +317,7 @@ class AccountBankStatement(models.Model):
|
||||
)
|
||||
AND aml.ref IN %s
|
||||
"""
|
||||
params = (self.company_id.id, (st_lines_left[0].journal_id.default_credit_account_id.id, st_lines_left[0].journal_id.default_debit_account_id.id), tuple(refs))
|
||||
params = (self.env.user.company_id.id, (st_lines_left[0].journal_id.default_credit_account_id.id, st_lines_left[0].journal_id.default_debit_account_id.id), tuple(refs))
|
||||
if statements:
|
||||
sql_query += 'AND stl.id IN %s'
|
||||
params += (tuple(stl_to_assign.ids),)
|
||||
@@ -627,7 +627,7 @@ class AccountBankStatementLine(models.Model):
|
||||
st_line_currency = self.currency_id or self.journal_id.currency_id
|
||||
currency = (st_line_currency and st_line_currency != company_currency) and st_line_currency.id or False
|
||||
precision = st_line_currency and st_line_currency.decimal_places or company_currency.decimal_places
|
||||
params = {'company_id': self.company_id.id,
|
||||
params = {'company_id': self.env.user.company_id.id,
|
||||
'account_payable_receivable': (self.journal_id.default_credit_account_id.id, self.journal_id.default_debit_account_id.id),
|
||||
'amount': float_repr(float_round(amount, precision_digits=precision), precision_digits=precision),
|
||||
'partner_id': self.partner_id.id,
|
||||
@@ -678,7 +678,7 @@ class AccountBankStatementLine(models.Model):
|
||||
st_line_currency = self.currency_id or self.journal_id.currency_id
|
||||
currency = (st_line_currency and st_line_currency != company_currency) and st_line_currency.id or False
|
||||
precision = st_line_currency and st_line_currency.decimal_places or company_currency.decimal_places
|
||||
params = {'company_id': self.company_id.id,
|
||||
params = {'company_id': self.env.user.company_id.id,
|
||||
'account_payable_receivable': (self.journal_id.default_credit_account_id.id, self.journal_id.default_debit_account_id.id),
|
||||
'amount': float_round(amount, precision_digits=precision),
|
||||
'partner_id': self.partner_id.id,
|
||||
|
||||
@@ -1,23 +1,35 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
import json
|
||||
import logging
|
||||
|
||||
import requests
|
||||
|
||||
from odoo import api, fields, models, tools, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
def geo_find(addr):
|
||||
|
||||
def geo_find(addr, apikey=False):
|
||||
if not addr:
|
||||
return None
|
||||
url = 'https://maps.googleapis.com/maps/api/geocode/json'
|
||||
|
||||
if not apikey:
|
||||
raise UserError(_('''API key for GeoCoding (Places) required.\n
|
||||
Save this key in System Parameters with key: google.api_key_geocode, value: <your api key>
|
||||
Visit https://developers.google.com/maps/documentation/geocoding/get-api-key for more information.
|
||||
'''))
|
||||
|
||||
url = "https://maps.googleapis.com/maps/api/geocode/json"
|
||||
try:
|
||||
result = requests.get(url, params={'sensor': 'false', 'address': addr}).json()
|
||||
result = requests.get(url, params={'sensor': 'false', 'address': addr, 'key': apikey}).json()
|
||||
except Exception as e:
|
||||
raise UserError(_('Cannot contact geolocation servers. Please make sure that your Internet connection is up and running (%s).') % e)
|
||||
|
||||
if result['status'] != 'OK':
|
||||
if result.get('error_message'):
|
||||
_logger.error(result['error_message'])
|
||||
return None
|
||||
|
||||
try:
|
||||
@@ -45,22 +57,26 @@ class ResPartner(models.Model):
|
||||
partner_longitude = fields.Float(string='Geo Longitude', digits=(16, 5))
|
||||
date_localization = fields.Date(string='Geolocation Date')
|
||||
|
||||
@classmethod
|
||||
def _geo_localize(cls, apikey, street='', zip='', city='', state='', country=''):
|
||||
search = geo_query_address(street=street, zip=zip, city=city, state=state, country=country)
|
||||
result = geo_find(search, apikey)
|
||||
if result is None:
|
||||
search = geo_query_address(city=city, state=state, country=country)
|
||||
result = geo_find(search, apikey)
|
||||
return result
|
||||
|
||||
@api.multi
|
||||
def geo_localize(self):
|
||||
# We need country names in English below
|
||||
apikey = self.env['ir.config_parameter'].sudo().get_param('google.api_key_geocode')
|
||||
for partner in self.with_context(lang='en_US'):
|
||||
result = geo_find(geo_query_address(street=partner.street,
|
||||
zip=partner.zip,
|
||||
city=partner.city,
|
||||
state=partner.state_id.name,
|
||||
country=partner.country_id.name))
|
||||
if result is None:
|
||||
result = geo_find(geo_query_address(
|
||||
city=partner.city,
|
||||
state=partner.state_id.name,
|
||||
country=partner.country_id.name
|
||||
))
|
||||
|
||||
result = partner._geo_localize(apikey,
|
||||
partner.street,
|
||||
partner.zip,
|
||||
partner.city,
|
||||
partner.state_id.name,
|
||||
partner.country_id.name)
|
||||
if result:
|
||||
partner.write({
|
||||
'partner_latitude': result[0],
|
||||
|
||||
@@ -86,19 +86,10 @@ class CrmLead(models.Model):
|
||||
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 is None:
|
||||
result = geo_find(geo_query_address(
|
||||
city=lead.city,
|
||||
state=lead.state_id.name,
|
||||
country=lead.country_id.name
|
||||
))
|
||||
|
||||
apikey = self.env['ir.config_parameter'].sudo().get_param('google.api_key_geocode')
|
||||
result = self.env['res.partner']._geo_localize(apikey,
|
||||
lead.street, lead.zip, lead.city,
|
||||
lead.state_id.name, lead.country_id.name)
|
||||
if result:
|
||||
lead.write({
|
||||
'partner_latitude': result[0],
|
||||
|
||||
@@ -16,7 +16,7 @@ class TestPartnerAssign(TransactionCase):
|
||||
def setUp(self):
|
||||
super(TestPartnerAssign, self).setUp()
|
||||
|
||||
def geo_find(addr):
|
||||
def geo_find(addr, apikey):
|
||||
return {
|
||||
'Wavre, Belgium': (50.7158956, 4.6128075),
|
||||
'Cannon Hill Park, B46 3AG Birmingham, United Kingdom': (52.45216, -1.898578),
|
||||
|
||||
@@ -21,3 +21,4 @@ Peter Hahn peter.hahn@initos.com https://github.com/codingforfun
|
||||
Claudia Haida claudia.haida@initos.com
|
||||
Andreas Zöllner andreas.zoellner@initos.com https://github.com/azoellner
|
||||
Rami Alwafaie rami.alwafaie@initos.com https://github.com/rami-wafaie
|
||||
Florian Kantelberg florian.kantelberg@initos.com https://github.com/fkantelberg
|
||||
|
||||
Reference in New Issue
Block a user