def create(user_id, password, model, vals): _check_user(user_id, password) odoo_id = vals["odoo_id"] if model not in MODELS_CLASS.keys(): raise Fault("unknown_model", "Reference model does not exist!") mod_class = MODELS_CLASS[model] parse_many2one_vals(mod_class, vals) mod_class.create(**vals) return True
def create(user_id, password, model, vals): _check_user(user_id, password) odoo_id = vals["odoo_id"] if model not in MODELS_CLASS.keys(): raise Fault("unknown_model", "Reference model does not exist!") mod_class = MODELS_CLASS[model] parse_many2one_vals(mod_class, vals) mod_class.create(**vals) return True
def create(cls, **query): from sync_log import SyncLog from implemented_models import MODELS_CLASS res = super(SyncModel, cls).create(**query) if cls.MOD_NAME in MODELS_CLASS.keys(): sync_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') log = SyncLog.create(odoo_id=query['odoo_id'], model=cls.MOD_NAME, operation='create', sync_date=sync_date, to_sync=True) #log.launch_sync() return res
def delete_instance(self, *args, **kwargs): from sync_log import SyncLog from implemented_models import MODELS_CLASS if self.MOD_NAME in MODELS_CLASS.keys(): sync_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') log = SyncLog.create(odoo_id=self.odoo_id, model=self.MOD_NAME, operation='delete', sync_date=sync_date, to_sync=True) res = super(SyncModel, self).delete_instance(*args, **kwargs) #if self.MOD_NAME in MODELS_CLASS.keys(): # log.launch_sync() return res
def create(cls, **query): from sync_log import SyncLog from implemented_models import MODELS_CLASS res = super(SyncModel, cls).create(**query) if cls.MOD_NAME in list(MODELS_CLASS.keys()): sync_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') log = SyncLog.create(odoo_id=query['odoo_id'], model=cls.MOD_NAME, operation='create', sync_date=sync_date, to_sync=True) #log.launch_sync() return res
def delete_instance(self, *args, **kwargs): from sync_log import SyncLog from implemented_models import MODELS_CLASS if self.MOD_NAME in list(MODELS_CLASS.keys()): sync_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') log = SyncLog.create(odoo_id=self.odoo_id, model=self.MOD_NAME, operation='delete', sync_date=sync_date, to_sync=True) res = super(SyncModel, self).delete_instance(*args, **kwargs) #if self.MOD_NAME in MODELS_CLASS.keys(): # log.launch_sync() return res
def save(self, force_insert=False, only=None, is_update=False): from sync_log import SyncLog from implemented_models import MODELS_CLASS if is_update and self.MOD_NAME in MODELS_CLASS.keys(): exist_id = SyncLog.select().where(SyncLog.to_sync == True, SyncLog.operation == "update", SyncLog.odoo_id == self.odoo_id, SyncLog.model == self.MOD_NAME).limit(1) if not exist_id: sync_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') log = SyncLog.create(odoo_id=self.odoo_id, model=self.MOD_NAME, operation='update', sync_date=sync_date, to_sync=True) res = super(SyncModel, self).save(force_insert, only) #if is_update and self.MOD_NAME in MODELS_CLASS.keys(): # log.launch_sync() return res
def unlink(user_id, password, model, odoo_id): _check_user(user_id, password) if model not in MODELS_CLASS.keys(): raise Fault("unknown_model", "Reference model does not exist!") mod_class = MODELS_CLASS[model] try: rec = mod_class.get(mod_class.odoo_id == odoo_id) except mod_class.DoesNotExist: pass else: if model == "customer": for invoice in Invoice.select().where(Invoice.partner_id == rec.id): invoice.delete_instance() for rma in Rma.select().where(Rma.partner_id == rec.id): for rma_product in RmaProduct.select().where( RmaProduct.id_rma == rma.id): rma_product.delete_instance() rma.delete_instance() elif model == 'product': for rma_product in RmaProduct.select().where( RmaProduct.product_id == rec.id): rma_product.delete_instance() elif model == 'rma': for rma_product in RmaProduct.select().where( RmaProduct.id_rma == rec.id): rma_product.delete_instance() elif model == 'rmastatus': for rma_product in RmaProduct.select().where( RmaProduct.status_id == rec.id): rma_product.delete_instance() elif model == 'rmastage': for rma in Rma.select().where( Rma.stage_id == rec.id): rma.delete_instance() elif model == 'customertagcustomerrel': for customertagcustomerrel in CustomerTagCustomerRel.select().where( CustomerTagCustomerRel.odoo_id == rec.odoo_id): customertagcustomerrel.delete_instance() elif model == 'producttagproductrel': for producttagproductrel in ProductTagProductRel.select().where( ProductTagProductRel.odoo_id == rec.odoo_id): producttagproductrel.delete_instance() elif model == 'order': for order in Order.select().where( Order.partner_id == rec.id): order.delete_instance() rec.delete_instance() return True
def unlink(user_id, password, model, odoo_id): _check_user(user_id, password) if model not in MODELS_CLASS.keys(): raise Fault("unknown_model", "Reference model does not exist!") mod_class = MODELS_CLASS[model] try: rec = mod_class.get(mod_class.odoo_id == odoo_id) except mod_class.DoesNotExist: pass else: if model == "customer": for invoice in Invoice.select().where( Invoice.partner_id == rec.id): invoice.delete_instance() for rma in Rma.select().where(Rma.partner_id == rec.id): for rma_product in RmaProduct.select().where( RmaProduct.id_rma == rma.id): rma_product.delete_instance() rma.delete_instance() elif model == 'product': for rma_product in RmaProduct.select().where( RmaProduct.product_id == rec.id): rma_product.delete_instance() elif model == 'rma': for rma_product in RmaProduct.select().where( RmaProduct.id_rma == rec.id): rma_product.delete_instance() elif model == 'rmastatus': for rma_product in RmaProduct.select().where( RmaProduct.status_id == rec.id): rma_product.delete_instance() elif model == 'rmastage': for rma in Rma.select().where(Rma.stage_id == rec.id): rma.delete_instance() elif model == 'customertagcustomerrel': for customertagcustomerrel in CustomerTagCustomerRel.select( ).where(CustomerTagCustomerRel.odoo_id == rec.odoo_id): customertagcustomerrel.delete_instance() elif model == 'producttagproductrel': for producttagproductrel in ProductTagProductRel.select().where( ProductTagProductRel.odoo_id == rec.odoo_id): producttagproductrel.delete_instance() elif model == 'order': for order in Order.select().where(Order.partner_id == rec.id): order.delete_instance() rec.delete_instance() return True
def write(user_id, password, model, odoo_id, vals): _check_user(user_id, password) if model not in MODELS_CLASS.keys(): raise Fault("unknown_model", "Reference model does not exist!") mod_class = MODELS_CLASS[model] try: reg = mod_class.get(mod_class.odoo_id == odoo_id) except mod_class.DoesNotExist: raise Fault("unknown_registry", "%s not found!" % model) parse_many2one_vals(mod_class, vals) for field_name in vals.keys(): value = vals[field_name] if isinstance(value, basestring): value = value.replace('"','\\"') value = '"%s"' % value exec('reg.%s = %s' % (field_name, value)) reg.save(is_update=True) return True
def write(user_id, password, model, odoo_id, vals): _check_user(user_id, password) if model not in MODELS_CLASS.keys(): raise Fault("unknown_model", "Reference model does not exist!") mod_class = MODELS_CLASS[model] try: reg = mod_class.get(mod_class.odoo_id == odoo_id) except mod_class.DoesNotExist: raise Fault("unknown_registry", "%s not found!" % model) parse_many2one_vals(mod_class, vals) for field_name in vals.keys(): value = vals[field_name] if isinstance(value, basestring): value = value.replace('"', '\\"') value = '"%s"' % value exec('reg.%s = %s' % (field_name, value)) reg.save(is_update=True) return True
def save(self, force_insert=False, only=None, is_update=False): from sync_log import SyncLog from implemented_models import MODELS_CLASS if is_update and self.MOD_NAME in list(MODELS_CLASS.keys()): exist_id = SyncLog.select().where( SyncLog.to_sync == True, SyncLog.operation == "update", SyncLog.odoo_id == self.odoo_id, SyncLog.model == self.MOD_NAME).limit(1) if not exist_id: sync_date = datetime.now().strftime('%Y-%m-%d %H:%M:%S') log = SyncLog.create(odoo_id=self.odoo_id, model=self.MOD_NAME, operation='update', sync_date=sync_date, to_sync=True) res = super(SyncModel, self).save(force_insert, only) #if is_update and self.MOD_NAME in MODELS_CLASS.keys(): # log.launch_sync() return res
from implemented_models import MODELS_CLASS from decimal import Decimal user_auth = UserAuthentication(auth, protected_methods=['GET', 'POST', 'PUT', 'DELETE']) api = RestAPI(app, default_auth=user_auth) class ApiResource(RestResource): def check_post(self, obj=None): return False def check_put(self, obj): return False def check_delete(self, obj): return False def prepare_data(self, obj, data): for field in data: if isinstance(data[field], Decimal): data[field] = str(data[field]) return data for mod_class in list(MODELS_CLASS.keys()): api.register(MODELS_CLASS[mod_class], ApiResource) api.register(SyncLog, ApiResource) api.setup()
from flask_peewee.rest import RestAPI, RestResource, UserAuthentication from app import app from sync_log import SyncLog from auth import auth from implemented_models import MODELS_CLASS user_auth = UserAuthentication(auth, protected_methods=['GET', 'POST', 'PUT', 'DELETE']) api = RestAPI(app, default_auth=user_auth) class ApiResource(RestResource): def check_post(self, obj=None): return False def check_put(self, obj): return False def check_delete(self, obj): return False for mod_class in MODELS_CLASS.keys(): api.register(MODELS_CLASS[mod_class], ApiResource) api.register(SyncLog, ApiResource) api.setup()