|
@@ -2,6 +2,28 @@
|
|
from openerp import models, fields
|
|
from openerp import models, fields
|
|
import inspect
|
|
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']
|
|
|
|
+ data = {}
|
|
|
|
+
|
|
|
|
+ for field in dict(attributes[0][1]):
|
|
|
|
+ if field in blacklist:
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ obj_value = getattr(obj, field)
|
|
|
|
+
|
|
|
|
+ if 'class' in str(type(obj_value)):
|
|
|
|
+ data[field] = [o.id for o in obj_value] if obj_value else []
|
|
|
|
+ continue
|
|
|
|
+
|
|
|
|
+ data[field] = getattr(obj, field)
|
|
|
|
+
|
|
|
|
+ return data
|
|
|
|
+
|
|
'''
|
|
'''
|
|
Users class with token field for manage authentication
|
|
Users class with token field for manage authentication
|
|
'''
|
|
'''
|
|
@@ -10,216 +32,68 @@ class res_users(models.Model):
|
|
|
|
|
|
jwt_token = fields.Char(string = 'JWT Authentication Token');
|
|
jwt_token = fields.Char(string = 'JWT Authentication Token');
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'id': self.id,
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'login': self.login,
|
|
|
|
- 'email': self.email,
|
|
|
|
- 'image_small': self.image_small,
|
|
|
|
- 'image_medium': self.image_medium,
|
|
|
|
- 'jwt_token': self.jwt_token,
|
|
|
|
- 'company_id': self.company_id.id,
|
|
|
|
- 'partner_id': self.partner_id.id,
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
|
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class res_partner(models.Model):
|
|
class res_partner(models.Model):
|
|
_inherit = 'res.partner'
|
|
_inherit = 'res.partner'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'id': self.id,
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'display_name': self.display_name,
|
|
|
|
- 'phone': self.phone,
|
|
|
|
- 'mobile': self.mobile,
|
|
|
|
- 'email': self.email,
|
|
|
|
- 'birthdate': self.birthdate,
|
|
|
|
- 'city': self.city,
|
|
|
|
- 'street': self.street,
|
|
|
|
- 'partner_latitude': self.partner_latitude,
|
|
|
|
- 'partner_longitude': self.partner_longitude,
|
|
|
|
- 'image_medium': self.image_medium,
|
|
|
|
- 'image_small': self.image_small,
|
|
|
|
- 'comment': self.comment,
|
|
|
|
- 'phonecall_count': self.phonecall_count,
|
|
|
|
- 'opportunity_count': self.opportunity_count,
|
|
|
|
- 'meeting_count': self.meeting_count,
|
|
|
|
- 'journal_item_count': self.journal_item_count,
|
|
|
|
- 'sale_order_count': self.sale_order_count,
|
|
|
|
- 'contracts_count': self.contracts_count,
|
|
|
|
- 'company_id': self.company_id.id,
|
|
|
|
- 'country_id': self.country_id.id
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
|
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class crm_lead(models.Model):
|
|
class crm_lead(models.Model):
|
|
_inherit = 'crm.lead'
|
|
_inherit = 'crm.lead'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'id': self.id,
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'display_name': self.display_name,
|
|
|
|
- 'phone': self.phone,
|
|
|
|
- 'mobile': self.mobile,
|
|
|
|
- 'city': self.city,
|
|
|
|
- 'street': self.street,
|
|
|
|
- 'street2': self.street2,
|
|
|
|
- 'partner_name': self.partner_name,
|
|
|
|
- 'contact_name': self.contact_name,
|
|
|
|
- 'date_open': self.day_open,
|
|
|
|
- 'day_close': self.day_close,
|
|
|
|
- 'day_open': self.day_open,
|
|
|
|
- 'priority': self.priority,
|
|
|
|
- 'probability': self.probability,
|
|
|
|
- 'planned_cost': self.planned_cost,
|
|
|
|
- 'description': self.description,
|
|
|
|
- 'meeting_count': self.meeting_count,
|
|
|
|
- 'partner_id': self.partner_id.id,
|
|
|
|
- 'company_id': self.company_id.id,
|
|
|
|
- 'stage_id': self.stage_id.id,
|
|
|
|
- 'campaign_id': self.campaign_id.id,
|
|
|
|
- 'country_id': self.country_id.id
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class product_template(models.Model):
|
|
class product_template(models.Model):
|
|
_inherit = 'product.template'
|
|
_inherit = 'product.template'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'active': self.active,
|
|
|
|
- 'alternative_product_ids': [alt.id for alt in self.alternative_product_ids] if self.alternative_product_ids else [],
|
|
|
|
- 'attribute_line_ids': [line.id for line in self.attribute_line_ids] if self.attribute_line_ids else [],
|
|
|
|
- 'color': self.color,
|
|
|
|
- 'company_id': self.company_id.id if self.company_id.id else None,
|
|
|
|
- 'categ_id': self.categ_id.id if self.categ_id.id else None,
|
|
|
|
- 'default_code': self.default_code if self.default_code else None,
|
|
|
|
- 'description': self.description if self.description else None,
|
|
|
|
- 'display_name': self.display_name,
|
|
|
|
- 'ean13': self.ean13 if self.ean13 else None,
|
|
|
|
- 'factory_barcode': self.factory_barcode if self.factory_reference else None,
|
|
|
|
- 'factory_reference': self.factory_reference if self.factory_reference else None,
|
|
|
|
- 'flip_image': self.flip_image if hasattr(self, 'flip_image') else None,
|
|
|
|
- 'image_medium': self.image_medium,
|
|
|
|
- 'image_small': self.image_small,
|
|
|
|
- 'is_flip_image': self.is_flip_image if hasattr(self, 'is_flip_image') else False,
|
|
|
|
- 'is_product_variant': self.is_product_variant,
|
|
|
|
- 'list_price': self.list_price,
|
|
|
|
- 'mes_type': self.mes_type,
|
|
|
|
- 'multiple_image': self.multiple_image if hasattr(self, 'multiple_image') else False,
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'price': self.price,
|
|
|
|
- 'product_variant_count': self.product_variant_count,
|
|
|
|
- 'product_variant_ids': [variant.id for variant in self.product_variant_ids] if self.product_variant_ids else [],
|
|
|
|
- 'purchase_ok': self.purchase_ok if hasattr(self, 'purchase_ok') else False,
|
|
|
|
- 'qty_available': self.qty_available if hasattr(self, 'qty_available') else 0,
|
|
|
|
- 'rental': self.rental if hasattr(self, 'rental') else False,
|
|
|
|
- 'sale_ok': self.sale_ok if hasattr(self, 'sale_ok') else False,
|
|
|
|
- 'type': self.type if hasattr(self, 'type') else None,
|
|
|
|
- 'website_published': self.website_published if hasattr(self, 'website_published') else False
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
|
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class product_attribute_line(models.Model):
|
|
class product_attribute_line(models.Model):
|
|
_inherit = 'product.attribute.line'
|
|
_inherit = 'product.attribute.line'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'attribute_id': self.attribute_id.id if self.attribute_id.id else None,
|
|
|
|
- 'create_date': self.create_date,
|
|
|
|
- 'display_name': self.display_name,
|
|
|
|
- 'id': self.id,
|
|
|
|
- 'product_tmpl_id': self.product_tmpl_id.id if self.product_tmpl_id.id else None,
|
|
|
|
- 'value_ids': [value.id for value in self.value_ids] if self.value_ids else []
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
|
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class product_attribute(models.Model):
|
|
class product_attribute(models.Model):
|
|
_inherit = 'product.attribute'
|
|
_inherit = 'product.attribute'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'active': self.active,
|
|
|
|
- 'create_date': self.create_date,
|
|
|
|
- 'display_name': self.display_name,
|
|
|
|
- 'id': self.id,
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'type': self.type,
|
|
|
|
- 'value_ids': [value.id for value in self.value_ids] if self.value_ids else []
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
|
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class product_attribute_price(models.Model):
|
|
class product_attribute_price(models.Model):
|
|
_inherit = 'product.attribute.price'
|
|
_inherit = 'product.attribute.price'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- attributes = inspect(self, lambda a:not(isroutine(a)))
|
|
|
|
- print '----------------------------------------------------------------'
|
|
|
|
- print attributes
|
|
|
|
- print '----------------------------------------------------------------'
|
|
|
|
-
|
|
|
|
- return {
|
|
|
|
- 'response': 'ok'
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
|
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class product_attribute_value(models.Model):
|
|
class product_attribute_value(models.Model):
|
|
_inherit = 'product.attribute.value'
|
|
_inherit = 'product.attribute.value'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'attribute_id': self.attribute_id.id if self.attribute_id.id else None,
|
|
|
|
- 'color': self.color if self.color else None,
|
|
|
|
- 'create_date': self.create_date,
|
|
|
|
- 'display_name': self.display_name,
|
|
|
|
- 'id': self.id,
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'price_extra': self.price_extra,
|
|
|
|
- 'price_ids': [price.id for price in self.price_ids] if self.price_ids else [],
|
|
|
|
- 'product_ids': [product.id for product in self.product_ids] if self.product_ids else []
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist + DEFAULT_BLACKLIST)
|
|
|
|
|
|
'''
|
|
'''
|
|
'''
|
|
'''
|
|
class product_product(models.Model):
|
|
class product_product(models.Model):
|
|
_inherit = 'product.product'
|
|
_inherit = 'product.product'
|
|
|
|
|
|
- def dump(self):
|
|
|
|
- return {
|
|
|
|
- 'active': self.active,
|
|
|
|
- 'alternative_product_ids': [alternative.id for alternative in self.alternative_product_ids] if self.alternative_product_ids else [],
|
|
|
|
- 'attribute_line_ids': [alt.id for alt in self.attribute_line_ids] if self.attribute_line_ids else [],
|
|
|
|
- 'attribute_value_ids': [value.id for value in self.attribute_value_ids] if self.attribute_value_ids else [],
|
|
|
|
- 'categ_id': self.categ_id.id if self.categ_id else None,
|
|
|
|
- 'code': self.code,
|
|
|
|
- 'company_id': self.company_id.id if self.company_id else None,
|
|
|
|
- 'create_date': self.create_date,
|
|
|
|
- 'default_code': self.default_code if self.default_code else None,
|
|
|
|
- 'description': self.description if self.description else None,
|
|
|
|
- 'display_name': self.display_name,
|
|
|
|
- 'ean13': self.ean13 if self.ean13 else None,
|
|
|
|
- 'factory_barcode': self.factory_barcode if self.factory_barcode else None,
|
|
|
|
- 'factory_reference': self.factory_reference if self.factory_reference else None,
|
|
|
|
- 'image_medium': self.image_medium,
|
|
|
|
- 'image_small': self.image_small,
|
|
|
|
- 'image_variant': self.image_variant,
|
|
|
|
- 'id': self.id,
|
|
|
|
- 'is_product_variant': self.is_product_variant,
|
|
|
|
- 'list_price': self.list_price,
|
|
|
|
- 'name': self.name,
|
|
|
|
- 'name_template': self.name_template,
|
|
|
|
- 'price': self.price,
|
|
|
|
- 'price_extra': self.price_extra,
|
|
|
|
- 'product_tmpl_id': self.product_tmpl_id.id if self.product_tmpl_id else None,
|
|
|
|
- 'product_variant_count': self.product_variant_count,
|
|
|
|
- 'product_variant_ids': [variant.id for variant in self.product_variant_ids] if self.product_variant_ids else []
|
|
|
|
- }
|
|
|
|
|
|
+ def dump(self, blacklist = []):
|
|
|
|
+ return serialize(self, blacklist, DEFAULT_BLACKLIST)
|