Skip to content

Commit 799c985

Browse files
author
patryk.bujalla
committed
add query method get by ids
1 parent 1f82878 commit 799c985

10 files changed

Lines changed: 273 additions & 24 deletions

File tree

PortaCapena.OdooJsonRpcClient.Example/OdooClientRequests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public async Task Should_get_products_with_selected_properties_using_query()
187187
public async Task Get_DotNet_model_should_return_string()
188188
{
189189
var odooClient = new OdooClient(Config);
190-
var tableName = "account.account";
190+
var tableName = "account.account.type";
191191
var modelResult = await odooClient.GetModelAsync(tableName);
192192

193193
modelResult.Succeed.Should().BeTrue();

PortaCapena.OdooJsonRpcClient.Example/OdooRepositoryRequests.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Threading.Tasks;
22
using FluentAssertions;
33
using PortaCapena.OdooJsonRpcClient.Consts;
4+
using PortaCapena.OdooJsonRpcClient.Request;
45
using PortaCapena.OdooJsonRpcClient.Shared;
56
using PortaCapena.OdooJsonRpcClient.Shared.Models;
67
using Xunit;
@@ -12,7 +13,7 @@ public class OdooRepositoryRequests : TestBase
1213
[Fact]
1314
public async Task Can_get_all_products()
1415
{
15-
var repository = new OdooRepository<ProductProductOdooDto>(Config);
16+
var repository = new OdooRepository<AccountAccountTypeOdooModel>(Config);
1617
var products = await repository.Query().ToListAsync();
1718

1819
products.Error.Should().BeNull();
@@ -32,6 +33,36 @@ public async Task Can_get_product_by_id()
3233
products.Succeed.Should().BeTrue();
3334
}
3435

36+
[Fact]
37+
public async Task Can_get_product_with_deep_where()
38+
{
39+
var repository = new OdooRepository<ProductProductOdooDto>(Config);
40+
41+
var products = await repository.Query()
42+
.Where<ResCurrencyOdooModel>(x => x.CurrencyId, z => z.Name, OdooOperator.EqualsTo, "Euros")
43+
.ToListAsync();
44+
45+
products.Error.Should().BeNull();
46+
products.Value.Should().NotBeNull();
47+
products.Succeed.Should().BeTrue();
48+
products.Value.Should().NotBeEmpty();
49+
}
50+
51+
[Fact]
52+
public async Task Can_get_product_with_deep_secound_where()
53+
{
54+
var repository = new OdooRepository<ProductProductOdooDto>(Config);
55+
56+
var products = await repository.Query()
57+
.Where<AccountAccountOdooModel, AccountAccountTypeOdooModel>(x => x.PropertyAccountIncomeId, x => x.UserTypeId, x => x.Type, OdooOperator.EqualsTo, TypeAccountAccountTypeOdooEnum.Payable)
58+
.ToListAsync();
59+
60+
products.Error.Should().BeNull();
61+
products.Value.Should().NotBeNull();
62+
products.Succeed.Should().BeTrue();
63+
products.Value.Should().NotBeEmpty();
64+
}
65+
3566
[Fact]
3667
public async Task Can_get_products_with_where_and_select()
3768
{
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using PortaCapena.OdooJsonRpcClient.Attributes;
6+
using PortaCapena.OdooJsonRpcClient.Converters;
7+
using PortaCapena.OdooJsonRpcClient.Models;
8+
9+
namespace PortaCapena.OdooJsonRpcClient.Shared.Models
10+
{
11+
[OdooTableName("account.account.type")]
12+
[JsonConverter(typeof(OdooModelConverter))]
13+
public class AccountAccountTypeOdooModel : IOdooModel
14+
{
15+
16+
// required
17+
[JsonProperty("name")]
18+
public string Name { get; set; }
19+
20+
[JsonProperty("include_initial_balance")]
21+
public bool? IncludeInitialBalance { get; set; }
22+
23+
// required
24+
[JsonProperty("type")]
25+
public TypeAccountAccountTypeOdooEnum Type { get; set; }
26+
27+
// required
28+
[JsonProperty("internal_group")]
29+
public InternalGroupAccountAccountTypeOdooEnum InternalGroup { get; set; }
30+
31+
[JsonProperty("note")]
32+
public string Note { get; set; }
33+
34+
[JsonProperty("id")]
35+
public long Id { get; set; }
36+
37+
[JsonProperty("display_name")]
38+
public string DisplayName { get; set; }
39+
40+
// res.users
41+
[JsonProperty("create_uid")]
42+
public long? CreateUid { get; set; }
43+
44+
[JsonProperty("create_date")]
45+
public DateTime? CreateDate { get; set; }
46+
47+
// res.users
48+
[JsonProperty("write_uid")]
49+
public long? WriteUid { get; set; }
50+
51+
[JsonProperty("write_date")]
52+
public DateTime? WriteDate { get; set; }
53+
54+
[JsonProperty("__last_update")]
55+
public DateTime? LastUpdate { get; set; }
56+
}
57+
58+
59+
// The 'Internal Type' is used for features available on different types of accounts: liquidity type is for cash or bank accounts, payable/receivable is for vendor/customer accounts.
60+
[JsonConverter(typeof(StringEnumConverter))]
61+
public enum TypeAccountAccountTypeOdooEnum
62+
{
63+
[EnumMember(Value = "other")]
64+
Regular = 1,
65+
66+
[EnumMember(Value = "receivable")]
67+
Receivable = 2,
68+
69+
[EnumMember(Value = "payable")]
70+
Payable = 3,
71+
72+
[EnumMember(Value = "liquidity")]
73+
Liquidity = 4,
74+
}
75+
76+
77+
// The 'Internal Group' is used to filter accounts based on the internal group set on the account type.
78+
[JsonConverter(typeof(StringEnumConverter))]
79+
public enum InternalGroupAccountAccountTypeOdooEnum
80+
{
81+
[EnumMember(Value = "equity")]
82+
Equity = 1,
83+
84+
[EnumMember(Value = "asset")]
85+
Asset = 2,
86+
87+
[EnumMember(Value = "liability")]
88+
Liability = 3,
89+
90+
[EnumMember(Value = "income")]
91+
Income = 4,
92+
93+
[EnumMember(Value = "expense")]
94+
Expense = 5,
95+
96+
[EnumMember(Value = "off_balance")]
97+
OffBalance = 6,
98+
}
99+
100+
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
using System;
2+
using System.Runtime.Serialization;
3+
using Newtonsoft.Json;
4+
using Newtonsoft.Json.Converters;
5+
using PortaCapena.OdooJsonRpcClient.Attributes;
6+
using PortaCapena.OdooJsonRpcClient.Converters;
7+
using PortaCapena.OdooJsonRpcClient.Models;
8+
9+
namespace PortaCapena.OdooJsonRpcClient.Shared.Models
10+
{
11+
[OdooTableName("res.currency")]
12+
[JsonConverter(typeof(OdooModelConverter))]
13+
public class ResCurrencyOdooModel : IOdooModel
14+
{
15+
16+
// required
17+
[JsonProperty("name")]
18+
public string Name { get; set; }
19+
20+
// required
21+
[JsonProperty("symbol")]
22+
public string Symbol { get; set; }
23+
24+
[JsonProperty("rate")]
25+
public double? Rate { get; set; }
26+
27+
// res.currency.rate
28+
[JsonProperty("rate_ids")]
29+
public long[] RateIds { get; set; }
30+
31+
[JsonProperty("rounding")]
32+
public double? Rounding { get; set; }
33+
34+
[JsonProperty("decimal_places")]
35+
public int? DecimalPlaces { get; set; }
36+
37+
[JsonProperty("active")]
38+
public bool? Active { get; set; }
39+
40+
[JsonProperty("position")]
41+
public SymbolPositionResCurrencyOdooEnum? Position { get; set; }
42+
43+
[JsonProperty("date")]
44+
public DateTime? Date { get; set; }
45+
46+
[JsonProperty("currency_unit_label")]
47+
public string CurrencyUnitLabel { get; set; }
48+
49+
[JsonProperty("currency_subunit_label")]
50+
public string CurrencySubunitLabel { get; set; }
51+
52+
[JsonProperty("display_rounding_warning")]
53+
public bool? DisplayRoundingWarning { get; set; }
54+
55+
[JsonProperty("id")]
56+
public long Id { get; set; }
57+
58+
[JsonProperty("display_name")]
59+
public string DisplayName { get; set; }
60+
61+
// res.users
62+
[JsonProperty("create_uid")]
63+
public long? CreateUid { get; set; }
64+
65+
[JsonProperty("create_date")]
66+
public DateTime? CreateDate { get; set; }
67+
68+
// res.users
69+
[JsonProperty("write_uid")]
70+
public long? WriteUid { get; set; }
71+
72+
[JsonProperty("write_date")]
73+
public DateTime? WriteDate { get; set; }
74+
75+
[JsonProperty("__last_update")]
76+
public DateTime? LastUpdate { get; set; }
77+
}
78+
79+
80+
// Determines where the currency symbol should be placed after or before the amount.
81+
[JsonConverter(typeof(StringEnumConverter))]
82+
public enum SymbolPositionResCurrencyOdooEnum
83+
{
84+
[EnumMember(Value = "after")]
85+
AfterAmount = 1,
86+
87+
[EnumMember(Value = "before")]
88+
BeforeAmount = 2,
89+
}
90+
91+
}

PortaCapena.OdooJsonRpcClient.Shared/TestBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ namespace PortaCapena.OdooJsonRpcClient.Shared
55
public class TestBase
66
{
77
protected static readonly OdooConfig Config = new OdooConfig(
8-
apiUrl: "https://dbName.dev.odoo.com",
9-
dbName: "dbName",
8+
apiUrl: "https://darling-uat-2324412.dev.odoo.com",
9+
dbName: "darling-uat-2324412",
1010
userName: "admin",
1111
password: "admin"
1212
);

PortaCapena.OdooJsonRpcClient/Request/OdooFilter.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,28 +69,28 @@ public OdooFilter NotEqual(string fieldName, object value)
6969

7070
public OdooFilter GreaterThan(string fieldName, object value)
7171
{
72-
var field = new object[] { fieldName, ">", value };
72+
var field = new object[] { fieldName, OdooOperator.GreaterThan.Description(), value };
7373
Add(field);
7474
return this;
7575
}
7676

7777
public OdooFilter GreaterThanOrEqual(string fieldName, object value)
7878
{
79-
var field = new object[] { fieldName, ">=", value };
79+
var field = new object[] { fieldName, OdooOperator.GreaterThanOrEqualTo.Description(), value };
8080
Add(field);
8181
return this;
8282
}
8383

8484
public OdooFilter LessThan(string fieldName, object value)
8585
{
86-
var field = new object[] { fieldName, "<", value };
86+
var field = new object[] { fieldName, OdooOperator.LessThan.Description(), value };
8787
Add(field);
8888
return this;
8989
}
9090

9191
public OdooFilter LessThanOrEqual(string fieldName, object value)
9292
{
93-
var field = new object[] { fieldName, "<=", value };
93+
var field = new object[] { fieldName, OdooOperator.LessThanOrEqualTo.Description(), value };
9494
Add(field);
9595
return this;
9696
}
@@ -104,56 +104,56 @@ public OdooFilter Between(string fieldName, object value1, object value2)
104104

105105
public OdooFilter In(string fieldName, OdooFilterValue value)
106106
{
107-
var field = new object[] { fieldName, "in", value.ToArray() };
107+
var field = new object[] { fieldName, OdooOperator.In.Description(), value.ToArray() };
108108
Add(field);
109109
return this;
110110
}
111111

112112
public OdooFilter In(string fieldName, object[] values)
113113
{
114-
var field = new object[] { fieldName, "in", values };
114+
var field = new object[] { fieldName, OdooOperator.In.Description(), values };
115115
Add(field);
116116
return this;
117117
}
118118

119119
public OdooFilter In(string fieldName, List<object> values)
120120
{
121-
var field = new object[] { fieldName, "in", values.ToArray() };
121+
var field = new object[] { fieldName, OdooOperator.In.Description(), values.ToArray() };
122122
Add(field);
123123
return this;
124124
}
125125

126-
public OdooFilter In(string fieldName, int[] values)
126+
public OdooFilter In(string fieldName, long[] values)
127127
{
128-
var field = new object[] { fieldName, "in", values };
128+
var field = new object[] { fieldName, OdooOperator.In.Description(), values };
129129
Add(field);
130130
return this;
131131
}
132132

133133
public OdooFilter NotIn(string fieldName, OdooFilterValue value)
134134
{
135-
var field = new object[] { fieldName, "not in", value.ToArray() };
135+
var field = new object[] { fieldName, OdooOperator.NotIn.Description(), value.ToArray() };
136136
Add(field);
137137
return this;
138138
}
139139

140140
public OdooFilter NotIn(string fieldName, object[] values)
141141
{
142-
var field = new object[] { fieldName, "not in", values };
142+
var field = new object[] { fieldName, OdooOperator.NotIn.Description(), values };
143143
Add(field);
144144
return this;
145145
}
146146

147147
public OdooFilter NotIn(string fieldName, List<object> values)
148148
{
149-
var field = new object[] { fieldName, "not in", values.ToArray() };
149+
var field = new object[] { fieldName, OdooOperator.NotIn.Description(), values.ToArray() };
150150
Add(field);
151151
return this;
152152
}
153153

154-
public OdooFilter NotIn(string fieldName, int[] values)
154+
public OdooFilter NotIn(string fieldName, long[] values)
155155
{
156-
var field = new object[] { fieldName, "not in", values };
156+
var field = new object[] { fieldName, OdooOperator.NotIn.Description(), values };
157157
Add(field);
158158
return this;
159159
}
@@ -169,6 +169,19 @@ public OdooFilter Build()
169169
{
170170
return this;
171171
}
172+
173+
public OdooFilter NotBeNull(string fieldName)
174+
{
175+
var field = new object[] { fieldName, OdooOperator.NotEqualsTo.Description(), false };
176+
Add(field);
177+
return this;
178+
}
179+
public OdooFilter BeNull(string fieldName)
180+
{
181+
var field = new object[] { fieldName, OdooOperator.EqualsTo.Description(), false };
182+
Add(field);
183+
return this;
184+
}
172185
}
173186

174187
public class OdooFilterValue : ArrayList

0 commit comments

Comments
 (0)