forked from eyekraft/website_shops_map
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
44 lines (39 loc) · 1.48 KB
/
__init__.py
File metadata and controls
44 lines (39 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
import models
import controllers
def fn_post_init_hook(cr, registry):
from openerp import api, SUPERUSER_ID
env = api.Environment(cr,SUPERUSER_ID,context={})
model_obj = env['stock.warehouse']
warehouses = model_obj.search([('shop_id', '=', False)])
#search for existed warehouses
#convert them in compatible type
for wh in warehouses:
values = {'name': wh.name}
shop_id = env['eyekraft.shop'].create(values)
values = {'shop_id': shop_id.id}
wh.write(values)
if wh.partner_id:
partner_to_delete = wh.shop_id.partner_id
wh.shop_id.partner_id = wh.partner_id
partner_to_delete.sudo().unlink()
#search for partners available for 'snippet_google_partner' module
#and create warehouses with corresponding partners linked
#to show on native module map
partner_model = env['res.partner']
partners_to_stock = partner_model.search([('category_id','!=',False),
('partner_latitude','!=',False),
('partner_longitude','!=',False),
('partner_longitude','!=',False),
('date_localization','!=',False),
])
i = 1
for partner in partners_to_stock:
values = {'name': partner.name,'code':'x_'+str(i)}
warehouse = model_obj.create(values)
warehouse.public = True
warehouse.shop_id.foreign_partner = True
partner_to_delete = warehouse.shop_id.partner_id
warehouse.shop_id.partner_id = partner
partner_to_delete.sudo().unlink()
i += 1