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
@@ -29,10 +30,22 @@ def setUpClass(cls):
29
30
cls .product_pricelist = cls .env ["product.pricelist" ].create (
30
31
{"name" : "pricelist for sale_financial_risk test" }
31
32
)
32
- cls .sale_order = cls .env ["sale.order" ].create (
33
+ cls .main_currency = cls .env .company .currency_id
34
+ cls .EUR = cls .env .ref ("base.EUR" )
35
+ cls .other_company = cls .env ["res.company" ].create (
36
+ {"name" : "Company 2" , "currency_id" : cls .EUR .id }
37
+ )
38
+ cls .sale_order = cls .create_sale_order (cls .main_currency , cls .env .company )
39
+ cls .env .user .lang = "en_US"
40
+
41
+ @classmethod
42
+ def create_sale_order (cls , currency , company ):
43
+ return cls .env ["sale.order" ].create (
33
44
{
34
45
"partner_id" : cls .partner .id ,
35
46
"pricelist_id" : cls .product_pricelist .id ,
47
+ "currency_id" : currency .id ,
48
+ "company_id" : company .id ,
36
49
"order_line" : [
37
50
(
38
51
0 ,
@@ -43,12 +56,12 @@ def setUpClass(cls):
43
56
"product_uom_qty" : 1 ,
44
57
"product_uom" : cls .product .uom_id .id ,
45
58
"price_unit" : 100.0 ,
59
+ "company_id" : company .id ,
46
60
},
47
61
)
48
62
],
49
63
}
50
64
)
51
- cls .env .user .lang = "en_US"
52
65
53
66
def test_sale_order (self ):
54
67
self .sale_order .action_confirm ()
@@ -178,3 +191,59 @@ def test_open_risk_pivot_info(self):
178
191
self .assertEqual (action ["res_model" ], "sale.order.line" )
179
192
self .assertTrue (action ["view_id" ])
180
193
self .assertTrue (action ["domain" ])
194
+
195
+ def test_manual_currency_risk_not_exceeded (self ):
196
+ self .product_pricelist .currency_id = self .EUR
197
+ self .partner .write (
198
+ {
199
+ "risk_sale_order_limit" : 99 ,
200
+ "credit_limit" : 99 ,
201
+ "risk_sale_order_include" : True ,
202
+ "credit_currency" : "manual" ,
203
+ "manual_credit_currency_id" : self .main_currency .id ,
204
+ }
205
+ )
206
+ self .env ["res.currency.rate" ].create (
207
+ {
208
+ "currency_id" : self .main_currency .id ,
209
+ "name" : fields .Date .today (),
210
+ "rate" : 0.5 ,
211
+ "company_id" : self .other_company .id ,
212
+ }
213
+ )
214
+ sale_order = self .create_sale_order (
215
+ currency = self .EUR , company = self .other_company
216
+ )
217
+ result = sale_order .action_confirm ()
218
+
219
+ # Limit not exceeded
220
+ self .assertEqual (result , True )
221
+
222
+ def test_manual_currency_risk_exceeded (self ):
223
+ self .product_pricelist .currency_id = self .EUR
224
+ self .partner .write (
225
+ {
226
+ "risk_sale_order_limit" : 99 ,
227
+ "credit_limit" : 99 ,
228
+ "risk_sale_order_include" : True ,
229
+ "credit_currency" : "manual" ,
230
+ "manual_credit_currency_id" : self .main_currency .id ,
231
+ }
232
+ )
233
+ self .product_pricelist .currency_id = self .EUR
234
+ self .env ["res.currency.rate" ].create (
235
+ {
236
+ "currency_id" : self .main_currency .id ,
237
+ "name" : fields .Date .today (),
238
+ "rate" : 1.5 ,
239
+ "company_id" : self .other_company .id ,
240
+ }
241
+ )
242
+ sale_order = self .create_sale_order (
243
+ currency = self .EUR , company = self .other_company
244
+ )
245
+ result = sale_order .action_confirm ()
246
+
247
+ # Limit exceeded
248
+ self .assertNotEqual (result , True )
249
+ self .assertEqual (result ["res_model" ], "partner.risk.exceeded.wiz" )
0 commit comments