mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Pass records instead of id in arguments
This commit is contained in:
@@ -154,7 +154,7 @@ class CreditControlLine(models.Model):
|
||||
return data
|
||||
|
||||
@api.model
|
||||
def create_or_update_from_mv_lines(self, lines, level_id, controlling_date,
|
||||
def create_or_update_from_mv_lines(self, lines, level, controlling_date,
|
||||
check_tolerance=True):
|
||||
""" Create or update line based on levels
|
||||
|
||||
@@ -164,7 +164,7 @@ class CreditControlLine(models.Model):
|
||||
of open amount.
|
||||
|
||||
:param lines: move.line id recordset
|
||||
:param level_id: credit.control.policy.level id
|
||||
:param level: credit.control.policy.level record
|
||||
:param controlling_date: date string of the credit controlling date.
|
||||
Generally it should be the same
|
||||
as create date
|
||||
@@ -187,7 +187,6 @@ class CreditControlLine(models.Model):
|
||||
tolerance[currency.id] = currency.compute(tolerance_base,
|
||||
user_currency)
|
||||
|
||||
level = level_obj.browse(level_id)
|
||||
new_lines = self.browse()
|
||||
for move_line in lines:
|
||||
open_amount = move_line.amount_residual_currency
|
||||
|
||||
@@ -52,7 +52,7 @@ class ResPartner(models.Model):
|
||||
account = partner.property_account_receivable
|
||||
policy = partner.credit_policy_id
|
||||
try:
|
||||
policy.check_policy_against_account(account.id)
|
||||
policy.check_policy_against_account(account)
|
||||
except api.Warning as err:
|
||||
# constrains should raise ValidationError exceptions
|
||||
raise api.ValidationError(err)
|
||||
|
||||
@@ -194,9 +194,8 @@ class CreditControlPolicy(models.Model):
|
||||
return different_lines
|
||||
|
||||
@api.multi
|
||||
def check_policy_against_account(self, account_id):
|
||||
def check_policy_against_account(self, account):
|
||||
""" Ensure that the policy corresponds to account relation """
|
||||
account = self.env['account.account'].browse(account_id)
|
||||
policies = self.search([])
|
||||
allowed = [x for x in policies
|
||||
if account in x.account_ids or x.do_nothing]
|
||||
|
||||
@@ -114,14 +114,12 @@ class CreditControlRun(models.Model):
|
||||
if lines:
|
||||
# policy levels are sorted by level
|
||||
# so iteration is in the correct order
|
||||
create = cr_line_obj.create_or_update_from_mv_lines
|
||||
for level in reversed(policy.level_ids):
|
||||
level_lines = level.get_level_lines(self.date, lines)
|
||||
policy_lines_generated += \
|
||||
cr_line_obj.create_or_update_from_mv_lines(
|
||||
level_lines,
|
||||
level.id,
|
||||
self.date,
|
||||
)
|
||||
policy_lines_generated += create(level_lines,
|
||||
level,
|
||||
self.date)
|
||||
generated += policy_lines_generated
|
||||
if policy_lines_generated:
|
||||
report += (_("Policy \"%s\" has generated %d Credit "
|
||||
|
||||
Reference in New Issue
Block a user