Skip to content

Commit 0ab7932

Browse files
committed
Merge PR OCA#361 into 15.0
Signed-off-by pedrobaeza
2 parents f2fc15f + b97ec26 commit 0ab7932

File tree

2 files changed

+73
-4
lines changed

2 files changed

+73
-4
lines changed

sale_financial_risk/models/sale.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def evaluate_risk_message(self, partner):
1717
self.ensure_one()
1818
risk_amount = self.currency_id._convert(
1919
self.amount_total,
20-
self.company_id.currency_id,
20+
partner.risk_currency_id,
2121
self.company_id,
2222
self.date_order
2323
and self.date_order.date()
@@ -128,7 +128,7 @@ def _compute_risk_amount(self):
128128
risk_amount = line.price_reduce_taxinc * risk_qty
129129
line.risk_amount = line.order_id.currency_id._convert(
130130
risk_amount,
131-
line.company_id.currency_id,
131+
line.order_id.partner_id.risk_currency_id,
132132
line.company_id,
133133
line.order_id.date_order
134134
and line.order_id.date_order.date()

sale_financial_risk/tests/test_partner_sale_risk.py

+71-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2016-2018 Tecnativa - Carlos Dauden
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
33

4+
from odoo import fields
45
from odoo.tests import TransactionCase
56

67

@@ -29,10 +30,22 @@ def setUpClass(cls):
2930
cls.product_pricelist = cls.env["product.pricelist"].create(
3031
{"name": "pricelist for sale_financial_risk test"}
3132
)
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(
3344
{
3445
"partner_id": cls.partner.id,
3546
"pricelist_id": cls.product_pricelist.id,
47+
"currency_id": currency.id,
48+
"company_id": company.id,
3649
"order_line": [
3750
(
3851
0,
@@ -43,12 +56,12 @@ def setUpClass(cls):
4356
"product_uom_qty": 1,
4457
"product_uom": cls.product.uom_id.id,
4558
"price_unit": 100.0,
59+
"company_id": company.id,
4660
},
4761
)
4862
],
4963
}
5064
)
51-
cls.env.user.lang = "en_US"
5265

5366
def test_sale_order(self):
5467
self.sale_order.action_confirm()
@@ -178,3 +191,59 @@ def test_open_risk_pivot_info(self):
178191
self.assertEqual(action["res_model"], "sale.order.line")
179192
self.assertTrue(action["view_id"])
180193
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

Comments
 (0)