Skip to content

Commit 87b1a04

Browse files
committed
Merge PR OCA#371 into 16.0
Signed-off-by pedrobaeza
2 parents 592c915 + 8f8e508 commit 87b1a04

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-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

+74-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
from odoo.addons.base.tests.common import DISABLED_MAIL_CONTEXT
@@ -22,10 +23,20 @@ def setUpClass(cls):
2223
cls.product_pricelist = cls.env["product.pricelist"].create(
2324
{"name": "pricelist for sale_financial_risk test"}
2425
)
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(
2635
{
2736
"partner_id": cls.partner.id,
2837
"pricelist_id": cls.product_pricelist.id,
38+
"currency_id": currency.id,
39+
"company_id": company.id,
2940
"order_line": [
3041
(
3142
0,
@@ -36,12 +47,12 @@ def setUpClass(cls):
3647
"product_uom_qty": 1,
3748
"product_uom": cls.product.uom_id.id,
3849
"price_unit": 100.0,
50+
"company_id": company.id,
3951
},
4052
)
4153
],
4254
}
4355
)
44-
cls.env.user.lang = "en_US"
4556

4657
def test_sale_order(self):
4758
self.sale_order.action_confirm()
@@ -171,3 +182,64 @@ def test_open_risk_pivot_info(self):
171182
self.assertEqual(action["res_model"], "sale.order.line")
172183
self.assertTrue(action["view_id"])
173184
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

Comments
 (0)