/
magento_referential.py
81 lines (74 loc) · 2.61 KB
/
magento_referential.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# This file is part magento module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import Pool
__all__ = ['MagentoExternalReferential']
class MagentoExternalReferential(ModelSQL, ModelView):
'Magento External Referential'
__name__ = 'magento.external.referential'
magento_app = fields.Many2One('magento.app', 'Magento App', required=True)
model = fields.Many2One('ir.model', 'Tryton Model', required=True,
select=True)
try_id = fields.Integer('Tryton ID', required=True)
mgn_id = fields.Integer('Magento ID', required=True)
@classmethod
def set_external_referential(cls, app, model, try_id, mgn_id):
'''
Create external referential
:param app: object
:param model: str name model
:param try_id: int Tryton ID
:param mgn_id: int Magento ID
:return magento_external_referential browseable record
'''
models = Pool().get('ir.model').search([('model', '=', model)],
limit=1)
values = {
'magento_app': app.id,
'model': models[0],
'try_id': try_id,
'mgn_id': mgn_id,
}
magento_external_referential = cls.create([values])[0]
return magento_external_referential
@classmethod
def get_mgn2try(cls, app, model, mgn_id):
'''
Search magento app, model and magento ID exist in other syncronizations
:param app: object
:param model: str name model
:param mgn_id: int Magento ID
:return id or None
'''
models = Pool().get('ir.model').search([('model', '=', model)],
limit=1)
values = cls.search([
('magento_app', '=', app.id),
('model', '=', models[0]),
('mgn_id', '=', mgn_id),
], limit=1)
if values:
return values[0]
else:
return None
@classmethod
def get_try2mgn(cls, app, model, try_id):
'''
Search magento app, model and tryton ID
:param app: object
:param model: str name model
:param try_id: int Tryton ID
:return id or None
'''
models = Pool().get('ir.model').search([('model', '=', model)],
limit=1)
values = cls.search([
('magento_app', '=', app.id),
('model', '=', models[0]),
('try_id', '=', try_id),
], limit=1)
if values:
return values[0]
else:
return None