public async Task Can_get_product_with_selected_language_uning_query()
        {
            var repository = new OdooRepository <ProductProductOdooModel>(TestConfig);

            var context = new OdooContext
            {
                Language = "nl_BE",
            };

            var product = await repository.Query()
                          .ById(282)
                          .WithContext(context)
                          .FirstOrDefaultAsync();

            product.Error.Should().BeNull();
            product.Value.Should().NotBeNull();
            product.Succeed.Should().BeTrue();
            product.Value.Name.Should().Contain("Dutch");

            var productWithoutLanguage = await repository.Query()
                                         .ById(282)
                                         .FirstOrDefaultAsync();

            productWithoutLanguage.Error.Should().BeNull();
            productWithoutLanguage.Value.Should().NotBeNull();
            productWithoutLanguage.Succeed.Should().BeTrue();
            productWithoutLanguage.Value.Name.Should().NotContain("Dutch");
        }
        public async Task<OdooResult<bool>> DeleteRangeAsync(IOdooModel[] models, OdooContext context = null)
        {
            var tableName = models.First().OdooTableName();
            if (models.Any(x => !string.Equals(x.OdooTableName(), tableName)))
                throw new ArgumentException("Models are not from the same odoo table");

            return await DeleteRangeAsync(tableName, models.Select(x => x.Id).ToArray(), SelectContext(context , Config.Context));
        }
示例#3
0
        public void Can_create_with_lang_param()
        {
            var context = new OdooContext("pl_PL");

            context.Count.Should().Be(1);
            context.First().Key.Should().Be("lang");
            context.First().Value.Should().Be("pl_PL");
        }
 public OdooConfig(string apiUrl, string dbName, string userName, string password)
 {
     this.ApiUrl   = apiUrl;
     this.DbName   = dbName;
     this.UserName = userName;
     this.Password = password;
     this.Context  = new OdooContext();
 }
示例#5
0
 public OdooQueryBuilder <T> WithContext(string key, object value)
 {
     if (_odooContext == null)
     {
         _odooContext = new OdooContext();
     }
     _odooContext[key] = value;
     return(this);
 }
示例#6
0
        public void Can_set_null_to_remove_value()
        {
            var context = new OdooContext("pl_PL", "time1");

            context.Timezone = null;

            context.Count.Should().Be(1);
            context.First().Key.Should().Be("lang");
            context.First().Value.Should().Be("pl_PL");
        }
示例#7
0
        public void Can_create_with_lang_and_timezone_param()
        {
            var context = new OdooContext("pl_PL", "time1");

            context.Count.Should().Be(2);
            context.First().Key.Should().Be("lang");
            context.First().Value.Should().Be("pl_PL");

            context.Skip(1).First().Key.Should().Be("tz");
            context.Skip(1).First().Value.Should().Be("time1");
        }
示例#8
0
        public void Can_update_one_prop()
        {
            var context = new OdooContext("pl_PL", "time1");

            context.Language = "new Language";

            context.Count.Should().Be(2);
            context.First().Key.Should().Be("lang");
            context.First().Value.Should().Be("new Language");

            context.Skip(1).First().Key.Should().Be("tz");
            context.Skip(1).First().Value.Should().Be("time1");
        }
示例#9
0
        public void Can_create_with_lang_param_ctor_and_with_dict()
        {
            var context = new OdooContext("pl_PL")
            {
                { "test_prop", "test value" }
            };

            context.Count.Should().Be(2);
            context.First().Key.Should().Be("lang");
            context.First().Value.Should().Be("pl_PL");

            context.Skip(1).First().Key.Should().Be("test_prop");
            context.Skip(1).First().Value.Should().Be("test value");
        }
        protected static Dictionary <string, object> MapQuery(OdooContext context, OdooQuery query = null)
        {
            if (query == null && (context == null || !context.Any()))
            {
                return(null);
            }

            var result = new Dictionary <string, object>();

            if (context != null && context.Any())
            {
                result["context"] = context;
            }

            if (query == null)
            {
                return(result);
            }

            if (query.Limit.HasValue)
            {
                result["limit"] = query.Limit;
            }

            if (!string.IsNullOrWhiteSpace(query.Order))
            {
                result["order"] = query.Order;
            }

            if (query.Offset.HasValue)
            {
                result["offset"] = query.Offset;
            }

            if (query.ReturnFields.Any())
            {
                result["fields"] = query.ReturnFields.ToArray();
            }

            if (!result.Any())
            {
                return(null);
            }

            return(result);
        }
示例#11
0
        static void Main(string[] args)
        {
            var cred = new OdooConnectionCredentials(
                "serverUrl",
                "dbName",
                "dbUser",
                "dbPassword");

            var api     = new Odoo.Odoo.OdooRpc(cred);
            var context = new OdooContext(api);


            var resPartner = context.ResPartner;

            resPartner.Filter.Equal("vat", "TR28163539052");

            resPartner
            .AddField("id")
            .AddField("name")
            .AddField("child_ids");


            var data = resPartner.Execute(true, 1, 100);

            //Result to XML
            var xml = resPartner.ToXml();

            //Dynamic Access Entity
            data.ForEach(x =>
            {
                Console.WriteLine(((dynamic)x).name);
            });

            //Thread
            var data1 = resPartner.ExecuteAsync(5, 10);

            var data2 = resPartner.ExecuteThread(10, 500);
        }
        public static OdooRequestModel Read(OdooConfig config, int uid, string tableName, long[] ids, OdooQuery query = null, OdooContext context = null)
        {
            var param = new OdooRequestParams(config.ApiUrlJson, "object", "execute_kw", config.DbName, uid, config.Password, tableName, OdooOperation.Read, ids, MapQuery(context, query));

            return(new OdooRequestModel(param));
        }
        public static OdooRequestModel Metadata(OdooConfig config, int uid, string tableName, long[] ids, OdooContext context = null)
        {
            var param = new OdooRequestParams(config.ApiUrlJson, "object", "execute_kw", config.DbName, uid, config.Password, tableName, OdooOperation.GetMetadata, new object[] { ids }, MapQuery(context));

            return(new OdooRequestModel(param));
        }
 public static async Task<OdooResult<long>> CreateAsync(OdooConfig odooConfig, int userUid, OdooDictionaryModel model, OdooContext context = null)
 {
     var request = OdooRequestModel.Create(odooConfig, userUid, GetTableName(model), model, context);
     var result = await CallAndDeserializeAsync<long>(request);
     return result.Succeed ? result.ToResult(result.Value) : OdooResult<long>.FailedResult(result);
 }
 public async Task <OdooResult <bool> > DeleteRangeAsync(T[] models, OdooContext context = null)
 {
     return(await OdooClient.DeleteRangeAsync(models as IOdooModel[], context));
 }
 public async Task <OdooResult <bool> > DeleteAsync(T model, OdooContext context = null)
 {
     return(await OdooClient.DeleteAsync(model, context));
 }
 public async Task <OdooResult <long> > CreateAsync(OdooDictionaryModel model, OdooContext context = null)
 {
     return(await OdooClient.CreateAsync(model, context));
 }
 public async Task<OdooResult<bool>> UpdateAsync(IOdooCreateModel model, long id, OdooContext context = null)
 {
     return await UpdateRangeAsync(model, new[] { id }, SelectContext(context , Config.Context));
 }
        public static OdooRequestModel SearchCount(OdooConfig config, int uid, string tableName, OdooQuery query = null, OdooContext context = null)
        {
            var param = new OdooRequestParams(config.ApiUrlJson, "object", "execute_kw", config.DbName, uid, config.Password, tableName, OdooOperation.SearchCount, GetRequestFilters(query), MapQuery(context, query));

            return(new OdooRequestModel(param));
        }
 public async Task <OdooResult <bool> > UpdateAsync(OdooDictionaryModel model, long id, OdooContext context = null)
 {
     return(await OdooClient.UpdateAsync(model, id, context));
 }
        public static OdooRequestModel Create(OdooConfig config, int uid, string tableName, object model, OdooContext context = null)
        {
            var param = new OdooRequestParams(config.ApiUrlJson, "object", "execute_kw", config.DbName, uid, config.Password, tableName, OdooOperation.Create, new[] { model }, MapQuery(context));

            return(new OdooRequestModel(param));
        }
 public static async Task<OdooResult<bool>> UpdateAsync(OdooConfig odooConfig, int userUid, IOdooCreateModel model, long id, OdooContext context = null)
 {
     return await UpdateRangeAsync(odooConfig, userUid, model, new[] { id }, context);
 }
 public async Task <OdooResult <bool> > UpdateRangeAsync(IOdooCreateModel model, long[] ids, OdooContext context = null)
 {
     return(await OdooClient.UpdateRangeAsync(model, ids, context));
 }
 public OdooConfig(string apiUrl, string dbName, string userName, string password, OdooContext context) : this(apiUrl, dbName, userName, password)
 {
     this.Context = new OdooContext(context);
 }
 public async Task <OdooResult <bool> > UpdateRangeAsync(OdooDictionaryModel model, long[] ids, OdooContext context = null)
 {
     model.TableName = TableName;
     return(await OdooClient.UpdateRangeAsync(model, ids, context));
 }
 public OdooConfig(string apiUrl, string dbName, string userName, string password, string language, string timezone) : this(apiUrl, dbName, userName, password)
 {
     this.Context = new OdooContext(language, timezone);
 }
 public async Task <OdooResult <bool> > DeleteAsync(long id, OdooContext context = null)
 {
     return(await OdooClient.DeleteAsync(TableName, id, context));
 }
 public static async Task<OdooResult<long>> GetCountAsync<T>(OdooConfig odooConfig, int userUid, OdooQuery query = null, OdooContext context = null) where T : IOdooModel, new()
 {
     var tableName = OdooExtensions.GetOdooTableName<T>();
     var request = OdooRequestModel.SearchCount(odooConfig, userUid, tableName, query, context);
     return await CallAndDeserializeAsync<long>(request);
 }
示例#29
0
 public OdooQueryBuilder <T> WithContext(OdooContext context)
 {
     _odooContext = new OdooContext(context);
     return(this);
 }
 public async Task<OdooResult<long>> CreateAsync(OdooDictionaryModel model, OdooContext context = null)
 {
     return await ExecuteWitrAccesDenideRetryAsync(userUid => CreateAsync(Config, userUid, model, SelectContext(context , Config.Context)));
 }