|
@@ -2,98 +2,55 @@
|
|
|
from openerp import models, fields
|
|
|
import inspect
|
|
|
|
|
|
-DEFAULT_BLACKLIST = ['create_uid', '__last_update', 'sequence', 'write_uid', 'write_date']
|
|
|
-
|
|
|
-'''
|
|
|
-'''
|
|
|
-def serialize(obj, blacklist = []):
|
|
|
- attributes = [a for a in inspect.getmembers(obj, lambda a:not(inspect.isroutine(a))) if a[0] == '_fields']
|
|
|
+DEFAULT_FIELDS_EXCLUDED = [
|
|
|
+ 'self',
|
|
|
+ 'function',
|
|
|
+ 'create_uid',
|
|
|
+ '__last_update',
|
|
|
+ 'sequence',
|
|
|
+ 'write_uid',
|
|
|
+ 'write_date',
|
|
|
+ 'tz',
|
|
|
+ 'lang'
|
|
|
+]
|
|
|
+
|
|
|
+'''
|
|
|
+'''
|
|
|
+def serialize(self, exclude = []):
|
|
|
+ fields = self.fields_get()
|
|
|
data = {}
|
|
|
|
|
|
- for field in dict(attributes[0][1]):
|
|
|
- if field in blacklist:
|
|
|
+ for field in fields:
|
|
|
+ if field in (exclude + DEFAULT_FIELDS_EXCLUDED):
|
|
|
continue
|
|
|
|
|
|
- obj_value = getattr(obj, field)
|
|
|
+ definition = fields[field]
|
|
|
|
|
|
- if 'class' in str(type(obj_value)):
|
|
|
- data[field] = [o.id for o in obj_value] if obj_value else []
|
|
|
+ if 'exportable' in definition or definition['readonly']:
|
|
|
continue
|
|
|
|
|
|
- data[field] = getattr(obj, field)
|
|
|
-
|
|
|
- return data
|
|
|
-
|
|
|
-'''
|
|
|
- Users class with token field for manage authentication
|
|
|
-'''
|
|
|
-class res_users(models.Model):
|
|
|
- _inherit = 'res.users'
|
|
|
-
|
|
|
- jwt_token = fields.Char(string = 'JWT Authentication Token');
|
|
|
-
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
-
|
|
|
-'''
|
|
|
-'''
|
|
|
-class res_partner(models.Model):
|
|
|
- _inherit = 'res.partner'
|
|
|
-
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
-
|
|
|
-'''
|
|
|
-'''
|
|
|
-class crm_lead(models.Model):
|
|
|
- _inherit = 'crm.lead'
|
|
|
-
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
-'''
|
|
|
-'''
|
|
|
-class product_template(models.Model):
|
|
|
- _inherit = 'product.template'
|
|
|
-
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
+ value = getattr(self, field)
|
|
|
|
|
|
-'''
|
|
|
-'''
|
|
|
-class product_attribute_line(models.Model):
|
|
|
- _inherit = 'product.attribute.line'
|
|
|
-
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
-
|
|
|
-'''
|
|
|
-'''
|
|
|
-class product_attribute(models.Model):
|
|
|
- _inherit = 'product.attribute'
|
|
|
+ if definition['type'] in ('char', 'text', 'html', 'date', 'datetime'):
|
|
|
+ data[field] = value if type(value) is not bool else None
|
|
|
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
+ if definition['type'] in ('many2one'):
|
|
|
+ data[field] = value.id if value.id else None
|
|
|
|
|
|
-'''
|
|
|
-'''
|
|
|
-class product_attribute_price(models.Model):
|
|
|
- _inherit = 'product.attribute.price'
|
|
|
+ if definition['type'] in ('one2many', 'many2many'):
|
|
|
+ data[field] = [obj.id for obj in value] if value else []
|
|
|
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
+ if definition['type'] in ('integer', 'float', 'boolean', 'selection', 'binary'):
|
|
|
+ data[field] = value
|
|
|
|
|
|
-'''
|
|
|
-'''
|
|
|
-class product_attribute_value(models.Model):
|
|
|
- _inherit = 'product.attribute.value'
|
|
|
+ return data
|
|
|
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
+models.Model.serialize = serialize
|
|
|
|
|
|
'''
|
|
|
+ Users class with token field for manage authentication
|
|
|
'''
|
|
|
-class product_product(models.Model):
|
|
|
- _inherit = 'product.product'
|
|
|
+class res_users(models.Model):
|
|
|
+ _inherit = 'res.users'
|
|
|
|
|
|
- def dump(self, blacklist = []):
|
|
|
- return serialize(self, blacklist, DEFAULT_BLACKLIST)
|
|
|
+ jwt_token = fields.Char(string = 'JWT Authentication Token');
|