mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Remove required on the currency and fallback to company's currency...
... on the policy level if it is empty. Also, it fixes a bug when a credit line had no currency and the level had the company's currency. As False is different than any currency, it entered in res_currency.compute() with a False currency. It must just fallback on the company's currency if the credit line's currency is empty.
This commit is contained in:
@@ -108,12 +108,14 @@ class FeesComputer(models.BaseModel):
|
||||
:return: fees amount float (in credit line currency)
|
||||
|
||||
"""
|
||||
credit_currency = credit_line.currency_id
|
||||
credit_currency = (credit_line.currency_id or
|
||||
credit_line.company_id.currency_id)
|
||||
level = credit_line.policy_level_id
|
||||
fees_amount = level.dunning_fixed_amount
|
||||
if not fees_amount:
|
||||
return 0.0
|
||||
fees_currency = level.dunning_currency_id
|
||||
fees_currency = (level.dunning_currency_id or
|
||||
level.policy_id.company_id.currency_id)
|
||||
if fees_currency == credit_currency:
|
||||
return fees_amount
|
||||
else:
|
||||
|
||||
@@ -31,8 +31,12 @@ class CreditControlPolicy(models.Model):
|
||||
|
||||
dunning_fixed_amount = fields.Float(string='Fees Fixed Amount')
|
||||
|
||||
dunning_currency_id = fields.Many2one('res.currency',
|
||||
string='Fees currency')
|
||||
dunning_currency_id = fields.Many2one(
|
||||
'res.currency',
|
||||
string='Fees currency',
|
||||
help="Currency of the dunning fees. If empty, it takes the "
|
||||
"company's currency."
|
||||
)
|
||||
|
||||
# planned type are fixed, percent, compound
|
||||
dunning_fees_type = fields.Selection([('fixed', 'Fixed')],
|
||||
|
||||
@@ -84,6 +84,38 @@ class FixedFeesTester(common.TransactionCase):
|
||||
fees = self.dunning_model.compute_fixed_fees(credit_line)
|
||||
self.assertNotEqual(fees, self.euro_level.dunning_fixed_amount)
|
||||
|
||||
def test_computation_credit_currency_empty(self):
|
||||
"""Test that fees are correctly computed with empty credit currency"""
|
||||
credit_line = self.line_model.new({
|
||||
'policy_level_id': self.euro_level,
|
||||
'currency_id': False,
|
||||
'company_id': self.company,
|
||||
})
|
||||
fees = self.dunning_model.compute_fixed_fees(credit_line)
|
||||
self.assertEqual(fees, self.euro_level.dunning_fixed_amount)
|
||||
|
||||
def test_computation_level_currency_empty(self):
|
||||
"""Test that fees are correctly computed with empty level currency"""
|
||||
credit_line = self.line_model.new({
|
||||
'policy_level_id': self.euro_level,
|
||||
'currency_id': self.euro,
|
||||
'company_id': self.company,
|
||||
})
|
||||
self.euro_level.currency_id = False
|
||||
fees = self.dunning_model.compute_fixed_fees(credit_line)
|
||||
self.assertEqual(fees, self.euro_level.dunning_fixed_amount)
|
||||
|
||||
def test_computation_all_currency_empty(self):
|
||||
"""Test that fees are correctly computed with empty currencies"""
|
||||
credit_line = self.line_model.new({
|
||||
'policy_level_id': self.euro_level,
|
||||
'currency_id': False,
|
||||
'company_id': self.company,
|
||||
})
|
||||
self.euro_level.currency_id = False
|
||||
fees = self.dunning_model.compute_fixed_fees(credit_line)
|
||||
self.assertEqual(fees, self.euro_level.dunning_fixed_amount)
|
||||
|
||||
def test_no_fees(self):
|
||||
"""Test that fees are not generated if no amount defined on level"""
|
||||
credit_line = self.line_model.new({
|
||||
|
||||
@@ -11,10 +11,8 @@
|
||||
<group>
|
||||
<group>
|
||||
<field name="dunning_fixed_amount"/>
|
||||
<field name="dunning_product_id"
|
||||
attrs="{'required': [('dunning_fixed_amount', '!=', False)]}"/>
|
||||
<field name="dunning_currency_id"
|
||||
attrs="{'required': [('dunning_fixed_amount', '!=', False)]}"/>
|
||||
<field name="dunning_product_id"/>
|
||||
<field name="dunning_currency_id"/>
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
|
||||
Reference in New Issue
Block a user