1
1
# Copyright 2016-2018 Tecnativa - Carlos Dauden
2
2
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3
3
4
+ from odoo import fields
4
5
from odoo .tests import TransactionCase
5
6
6
7
from odoo .addons .base .tests .common import DISABLED_MAIL_CONTEXT
@@ -22,10 +23,20 @@ def setUpClass(cls):
22
23
cls .product_pricelist = cls .env ["product.pricelist" ].create (
23
24
{"name" : "pricelist for sale_financial_risk test" }
24
25
)
25
- cls .sale_order = cls .env ["sale.order" ].create (
26
+ cls .main_currency = cls .env .company .currency_id
27
+ cls .EUR = cls .env .ref ("base.EUR" )
28
+ cls .USD = cls .env .ref ("base.USD" )
29
+ cls .sale_order = cls .create_sale_order (cls .main_currency , cls .env .company )
30
+ cls .env .user .lang = "en_US"
31
+
32
+ @classmethod
33
+ def create_sale_order (cls , currency , company ):
34
+ return cls .env ["sale.order" ].create (
26
35
{
27
36
"partner_id" : cls .partner .id ,
28
37
"pricelist_id" : cls .product_pricelist .id ,
38
+ "currency_id" : currency .id ,
39
+ "company_id" : company .id ,
29
40
"order_line" : [
30
41
(
31
42
0 ,
@@ -36,12 +47,12 @@ def setUpClass(cls):
36
47
"product_uom_qty" : 1 ,
37
48
"product_uom" : cls .product .uom_id .id ,
38
49
"price_unit" : 100.0 ,
50
+ "company_id" : company .id ,
39
51
},
40
52
)
41
53
],
42
54
}
43
55
)
44
- cls .env .user .lang = "en_US"
45
56
46
57
def test_sale_order (self ):
47
58
self .sale_order .action_confirm ()
@@ -171,3 +182,64 @@ def test_open_risk_pivot_info(self):
171
182
self .assertEqual (action ["res_model" ], "sale.order.line" )
172
183
self .assertTrue (action ["view_id" ])
173
184
self .assertTrue (action ["domain" ])
185
+
186
+ def test_manual_currency_risk_not_exceeded (self ):
187
+ if self .env .company .currency_id == self .EUR :
188
+ self .product_pricelist .currency_id = self .USD
189
+ currency = self .USD
190
+ else :
191
+ self .product_pricelist .currency_id = self .EUR
192
+ currency = self .EUR
193
+ self .partner .write (
194
+ {
195
+ "risk_sale_order_limit" : 99 ,
196
+ "credit_limit" : 99 ,
197
+ "risk_sale_order_include" : True ,
198
+ "credit_currency" : "manual" ,
199
+ "manual_credit_currency_id" : self .main_currency .id ,
200
+ }
201
+ )
202
+ self .env ["res.currency.rate" ].create (
203
+ {
204
+ "currency_id" : self .main_currency .id ,
205
+ "name" : fields .Date .today (),
206
+ "rate" : 0.5 ,
207
+ "company_id" : self .env .company .id ,
208
+ }
209
+ )
210
+ sale_order = self .create_sale_order (currency = currency , company = self .env .company )
211
+ result = sale_order .action_confirm ()
212
+
213
+ # Limit not exceeded
214
+ self .assertEqual (result , True )
215
+
216
+ def test_manual_currency_risk_exceeded (self ):
217
+ if self .env .company .currency_id == self .EUR :
218
+ self .product_pricelist .currency_id = self .USD
219
+ currency = self .USD
220
+ else :
221
+ self .product_pricelist .currency_id = self .EUR
222
+ currency = self .EUR
223
+ self .partner .write (
224
+ {
225
+ "risk_sale_order_limit" : 99 ,
226
+ "credit_limit" : 99 ,
227
+ "risk_sale_order_include" : True ,
228
+ "credit_currency" : "manual" ,
229
+ "manual_credit_currency_id" : self .main_currency .id ,
230
+ }
231
+ )
232
+ self .env ["res.currency.rate" ].create (
233
+ {
234
+ "currency_id" : self .main_currency .id ,
235
+ "name" : fields .Date .today (),
236
+ "rate" : 2.0 ,
237
+ "company_id" : self .env .company .id ,
238
+ }
239
+ )
240
+ sale_order = self .create_sale_order (currency = currency , company = self .env .company )
241
+ result = sale_order .action_confirm ()
242
+
243
+ # Limit exceeded
244
+ self .assertNotEqual (result , True )
245
+ self .assertEqual (result ["res_model" ], "partner.risk.exceeded.wiz" )
0 commit comments