48 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
			
		
		
	
	
			48 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Python
		
	
	
| # Copyright 2018-Today datenpol gmbh (<http://www.datenpol.at>)
 | |
| # License OPL-1 or later (https://www.odoo.com/documentation/user/11.0/legal/licenses/licenses.html#licenses).
 | |
| 
 | |
| from odoo import api, fields, models, _
 | |
| import urllib.parse
 | |
| 
 | |
| 
 | |
| class WizardRouteMaps(models.TransientModel):
 | |
|     _name = 'wizard.routemaps'
 | |
|     _description = 'Routenplaner'
 | |
| 
 | |
|     name = fields.Char()
 | |
| 
 | |
|     @api.multi
 | |
|     def button_routemaps(self):
 | |
| #        home_address = r'Neugasse 36, 2244 Spannberg'
 | |
|         myCompany=self.env.user.company_id
 | |
|         home_address = urllib.parse.quote(myCompany.street,safe='')+","+myCompany.zip+","+myCompany.city+","+myCompany.country_id.name
 | |
|         for wizard in self:
 | |
|             active_ids = self.env.context.get('active_ids', [])
 | |
|             sale_orders = self.env['sale.order'].browse(active_ids)
 | |
|             if sale_orders.exists():
 | |
|                 address = ""
 | |
|                 sid = set()
 | |
|                 for so in sale_orders:
 | |
|                     if (so.partner_shipping_id.id not in sid):
 | |
|                         sid.add(so.partner_shipping_id.id)
 | |
|                         si = so.partner_shipping_id
 | |
| 
 | |
|                         street = si.street + ',' if si.street else ''
 | |
|                         zip = ' ' + si.zip + ',' if si.zip else ''
 | |
|                         city = ' ' + si.city + ',' if si.city else ''
 | |
|                         country_code = ' ' + si.country_id.code + ',' if si.country_id.code else ''
 | |
| 
 | |
|                         address += "/"+urllib.parse.quote(street,safe='') + zip + urllib.parse.quote(city,safe='') + country_code
 | |
| 
 | |
|             gomaps_link = "https://www.google.at/maps/dir/"+home_address+address
 | |
| #            print(gomaps_link)
 | |
|             # action = self.env.ref('sale.action_orders').read()[0]
 | |
|             # action['domain'] = [('id', 'in', active_ids)]
 | |
|             # return action
 | |
|         return {
 | |
|             'type': 'ir.actions.act_url',
 | |
|             'url': '%s' % gomaps_link,
 | |
|             'target':'new',
 | |
| #            'domain': [('id', 'in', active_ids)],
 | |
|         }
 |