Skip to content

Commit

Permalink
[IMP] Add amount residual currency in _search_filter_amount
Browse files Browse the repository at this point in the history
  • Loading branch information
maq-adhoc committed Nov 8, 2023
1 parent 63085de commit db3ff99
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions account_accountant_ux/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
from odoo import models, fields
from odoo import models, fields, osv


class AccountMovetLine(models.Model):

_inherit = 'account.move.line'

filter_amount = fields.Float(compute="compute_filter_amout", search='_search_filter_amount')

def compute_filter_amout(self):
self.filter_amount = False

def _search_filter_amount(self, operator, value):
res = []
if self.env.context.get('default_st_line_id'):
amount = self.env['account.bank.statement.line'].browse(self.env.context.get('default_st_line_id'))['amount']
statement_line = self.env['account.bank.statement.line'].browse(self.env.context.get('default_st_line_id'))

if statement_line.company_id.currency_id == statement_line.journal_id.currency_id:
amount = statement_line['amount']
amount_currency = statement_line['amount_currency']
else:
amount = statement_line['amount_currency']
amount_currency = statement_line['amount']

if value != 0 and operator == '=':
base_amount = ((100 - value)/100) * amount
top_amount = ((100 + value)/100) * amount
res.append(('amount_residual', '>', base_amount))
res.append(('amount_residual', '<', top_amount))
base_amount_currency = ((100 - value)/100) * amount_currency
top_amount_currency = ((100 + value)/100) * amount_currency
res += osv.expression.OR([
[('amount_residual', '>', base_amount),('amount_residual', '<', top_amount)],
[('amount_residual_currency', '>', base_amount_currency),('amount_residual_currency', '<', top_amount_currency)]
])
else:
amount = ((100 - value)/100) * amount
amount_currency = ((100 - value)/100) * amount_currency
res.append('|')
res.append(('amount_residual', operator, amount))
res.append(('amount_residual_currency', operator, amount_currency))
return res

0 comments on commit db3ff99

Please sign in to comment.