Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 21 additions & 53 deletions accounting_pdf_reports/models/account_move_line.py
Original file line number Diff line number Diff line change
@@ -1,50 +1,10 @@
import ast
from odoo.osv import expression
from odoo import api, models, fields
from odoo import api, models


class AccountMoveLine(models.Model):
_inherit = "account.move.line"

@api.model
def _where_calc(self, domain, active_test=True):
"""Computes the WHERE clause needed to implement an OpenERP domain.

:param list domain: the domain to compute
:param bool active_test: whether the default filtering of records with
``active`` field set to ``False`` should be applied.
:return: the query expressing the given domain as provided in domain
:rtype: Query
"""
# if the object has an active field ('active', 'x_active'), filter out all
# inactive records unless they were explicitly asked for
if self._active_name and active_test and self.env.context.get('active_test', True):
# the item[0] trick below works for domain items and '&'/'|'/'!'
# operators too
if not any(item[0] == self._active_name for item in domain):
domain = [(self._active_name, '=', 1)] + domain

if domain:
return expression.expression(domain, self).query
else:
return Query(self.env, self._table, self._table_sql)

@api.model
def _apply_ir_rules(self, query, mode='read'):
"""Add what's missing in ``query`` to implement all appropriate ir.rules
(using the ``model_name``'s rules or the current model's rules if ``model_name`` is None)

:param query: the current query object
"""
if self.env.su:
return

# apply main rules on the object
Rule = self.env['ir.rule']
domain = Rule._compute_domain(self._name, mode)
if domain:
expression.expression(domain, self.sudo(), self._table, query)

@api.model
def _query_get(self, domain=None):
self.check_access('read')
Expand All @@ -61,7 +21,8 @@ def _query_get(self, domain=None):
domain += [(date_field, '<=', context['date_to'])]
if context.get('date_from'):
if not context.get('strict_range'):
domain += ['|', (date_field, '>=', context['date_from']), ('account_id.include_initial_balance', '=', True)]
domain += ['|', (date_field, '>=', context['date_from']),
('account_id.include_initial_balance', '=', True)]
elif context.get('initial_bal'):
domain += [(date_field, '<', context['date_from'])]
else:
Expand All @@ -82,17 +43,16 @@ def _query_get(self, domain=None):
domain += [('company_id', '=', self.env.company.id)]

if context.get('reconcile_date'):
domain += ['|', ('reconciled', '=', False), '|', ('matched_debit_ids.max_date', '>', context['reconcile_date']), ('matched_credit_ids.max_date', '>', context['reconcile_date'])]
domain += ['|', ('reconciled', '=', False), '|',
('matched_debit_ids.max_date', '>', context['reconcile_date']),
('matched_credit_ids.max_date', '>', context['reconcile_date'])]

if context.get('account_tag_ids'):
domain += [('account_id.tag_ids', 'in', context['account_tag_ids'].ids)]

if context.get('account_ids'):
domain += [('account_id', 'in', context['account_ids'].ids)]

if context.get('analytic_tag_ids'):
domain += [('analytic_tag_ids', 'in', context['analytic_tag_ids'].ids)]

if context.get('analytic_account_ids'):
domain += [('analytic_distribution', 'in', context['analytic_account_ids'].ids)]

Expand All @@ -102,16 +62,24 @@ def _query_get(self, domain=None):
if context.get('partner_categories'):
domain += [('partner_id.category_id', 'in', context['partner_categories'].ids)]

tables = '"account_move_line"'
where_clause = ""
where_clause_params = []
tables = ''

if domain:
domain.append(('display_type', 'not in', ('line_section', 'line_note')))
domain.append(('parent_state', '!=', 'cancel'))

query = self._where_calc(domain)
self._apply_ir_rules(query)
from_string, from_params = query.from_clause
where_string, where_params = query.where_clause
tables, where_clause, where_clause_params = from_string, where_string, from_params + where_params
return tables, where_clause, where_clause_params
# Use _search() to get matching IDs, then build a simple WHERE
# This avoids touching the unstable Query object API entirely
record_ids = self._search(domain)

if record_ids:
where_clause = '"account_move_line".id IN %s'
where_clause_params = [tuple(record_ids)]
else:
# No records match — return impossible condition
where_clause = '"account_move_line".id IS NULL'
where_clause_params = []

return tables, where_clause, where_clause_params
4 changes: 1 addition & 3 deletions om_account_asset/models/account_asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,6 @@ def _return_disposal_view(self, move_ids):
view_mode = 'tree,form'
return {
'name': name,
'view_type': 'form',
'view_mode': view_mode,
'res_model': 'account.move',
'type': 'ir.actions.act_window',
Expand Down Expand Up @@ -461,7 +460,7 @@ def onchange_date_first_depreciation(self):
@api.depends('depreciation_line_ids.move_id')
def _entry_count(self):
for asset in self:
res = self.env['account.asset.depreciation.line'].search_count([('asset_id', '=', asset.id), ('move_id', '!=', False)])
res = self.env['account.asset.depreciation.line'].search_count([('asset_id', 'in', asset.ids), ('move_id', '!=', False)])
asset.entry_count = res or 0

@api.constrains('prorata', 'method_time')
Expand Down Expand Up @@ -536,7 +535,6 @@ def open_entries(self):
move_ids.append(depreciation_line.move_id.id)
return {
'name': _('Journal Entries'),
'view_type': 'form',
'view_mode': 'list,form',
'res_model': 'account.move',
'view_id': False,
Expand Down
4 changes: 2 additions & 2 deletions om_account_asset/views/account_asset_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@
<field name="method_period" readonly="state != 'draft'"/>
<field name="method_end"
readonly="state != 'draft'"
invisible="method_time == 'end'"
required="method_time == 'number'"/>
invisible="method_time == 'number'"
required="method_time == 'end'"/>
</group>
</page>
</notebook>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ def asset_compute(self):

return {
'name': _('Created Asset Moves') if context.get('asset_type') == 'purchase' else _('Created Revenue Moves'),
'view_type': 'form',
'view_mode': 'list,form',
'res_model': 'account.move',
'view_id': False,
Expand Down
44 changes: 22 additions & 22 deletions om_account_budget/models/account_analytic_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,26 @@ class AccountAnalyticAccount(models.Model):
class AccountAnalyticLine(models.Model):
_inherit = 'account.analytic.line'

@api.model
def _where_calc(self, domain, active_test=True):
"""Computes the WHERE clause needed to implement an OpenERP domain.

:param list domain: the domain to compute
:param bool active_test: whether the default filtering of records with
``active`` field set to ``False`` should be applied.
:return: the query expressing the given domain as provided in domain
:rtype: Query
"""
# if the object has an active field ('active', 'x_active'), filter out all
# inactive records unless they were explicitly asked for
if self._active_name and active_test and self._context.get('active_test', True):
# the item[0] trick below works for domain items and '&'/'|'/'!'
# operators too
if not any(item[0] == self._active_name for item in domain):
domain = [(self._active_name, '=', 1)] + domain

if domain:
return expression.expression(domain, self).query
else:
return Query(self.env, self._table, self._table_sql)
# @api.model
# def _where_calc(self, domain, active_test=True):
# """Computes the WHERE clause needed to implement an OpenERP domain.
#
# :param list domain: the domain to compute
# :param bool active_test: whether the default filtering of records with
# ``active`` field set to ``False`` should be applied.
# :return: the query expressing the given domain as provided in domain
# :rtype: Query
# """
# # if the object has an active field ('active', 'x_active'), filter out all
# # inactive records unless they were explicitly asked for
# if self._active_name and active_test and self._context.get('active_test', True):
# # the item[0] trick below works for domain items and '&'/'|'/'!'
# # operators too
# if not any(item[0] == self._active_name for item in domain):
# domain = [(self._active_name, '=', 1)] + domain
#
# if domain:
# return expression.expression(domain, self).query
# else:
# return Query(self.env, self._table, self._table_sql)

107 changes: 80 additions & 27 deletions om_account_budget/models/account_budget.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,41 +163,94 @@ def _compute_practical_amount(self):
acc_ids = line.general_budget_id.account_ids.ids
date_to = line.date_to
date_from = line.date_from

if line.analytic_account_id.id:
analytic_line_obj = self.env['account.analytic.line']
domain = [('account_id', '=', line.analytic_account_id.id),
('date', '>=', date_from),
('date', '<=', date_to),
]
domain = [
('account_id', '=', line.analytic_account_id.id),
('date', '>=', date_from),
('date', '<=', date_to),
]
if acc_ids:
domain += [('general_account_id', 'in', acc_ids)]

where_query = analytic_line_obj._where_calc(domain)
analytic_line_obj._apply_ir_rules(where_query, 'read')
from_string, from_params = where_query.from_clause
where_string, where_params = where_query.where_clause
from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params

select = "SELECT SUM(amount) from " + from_clause + " where " + where_clause
self.env.cr.execute("""
SELECT SUM(amount)
FROM account_analytic_line aal
WHERE aal.account_id = %s
AND aal.date >= %s
AND aal.date <= %s
{acc_filter}
""".format(
acc_filter="AND aal.general_account_id IN %s" if acc_ids else ""
), (
line.analytic_account_id.id,
date_from,
date_to,
*((tuple(acc_ids),) if acc_ids else ()),
))

else:
aml_obj = self.env['account.move.line']
domain = [('account_id', 'in',
line.general_budget_id.account_ids.ids),
('date', '>=', date_from),
('date', '<=', date_to)
]
where_query = aml_obj._where_calc(domain)
aml_obj._apply_ir_rules(where_query, 'read')
from_string, from_params = where_query.from_clause
where_string, where_params = where_query.where_clause
from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params

select = "SELECT sum(credit)-sum(debit) from " + from_clause + " where " + where_clause

self.env.cr.execute(select, where_clause_params)
account_ids = line.general_budget_id.account_ids.ids
if not account_ids:
line.practical_amount = 0.0
continue

self.env.cr.execute("""
SELECT SUM(credit) - SUM(debit)
FROM account_move_line aml
INNER JOIN account_move am ON am.id = aml.move_id
WHERE aml.account_id IN %s
AND aml.date >= %s
AND aml.date <= %s
AND am.state = 'posted'
""", (
tuple(account_ids),
date_from,
date_to,
))

line.practical_amount = self.env.cr.fetchone()[0] or 0.0

# def _compute_practical_amount(self):
# for line in self:
# acc_ids = line.general_budget_id.account_ids.ids
# date_to = line.date_to
# date_from = line.date_from
# if line.analytic_account_id.id:
# analytic_line_obj = self.env['account.analytic.line']
# domain = [('account_id', '=', line.analytic_account_id.id),
# ('date', '>=', date_from),
# ('date', '<=', date_to),
# ]
# if acc_ids:
# domain += [('general_account_id', 'in', acc_ids)]
#
# where_query = analytic_line_obj._where_calc(domain)
# analytic_line_obj._apply_ir_rules(where_query, 'read')
# from_string, from_params = where_query.from_clause
# where_string, where_params = where_query.where_clause
# from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params
#
# select = "SELECT SUM(amount) from " + from_clause + " where " + where_clause
#
# else:
# aml_obj = self.env['account.move.line']
# domain = [('account_id', 'in',
# line.general_budget_id.account_ids.ids),
# ('date', '>=', date_from),
# ('date', '<=', date_to)
# ]
# where_query = aml_obj._where_calc(domain)
# aml_obj._apply_ir_rules(where_query, 'read')
# from_string, from_params = where_query.from_clause
# where_string, where_params = where_query.where_clause
# from_clause, where_clause, where_clause_params = from_string, where_string, from_params + where_params
#
# select = "SELECT sum(credit)-sum(debit) from " + from_clause + " where " + where_clause
#
# self.env.cr.execute(select, where_clause_params)
# line.practical_amount = self.env.cr.fetchone()[0] or 0.0

def _compute_theoritical_amount(self):
# beware: 'today' variable is mocked in the python tests and thus, its implementation matter
today = fields.Date.today()
Expand Down
2 changes: 2 additions & 0 deletions om_account_daily_reports/report/report_cashbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def _get_account_move_entry(self, accounts, init_balance, sortby, display_accoun
'move_lines': list of move line
}
"""
if not accounts:
return []
cr = self.env.cr
MoveLine = self.env['account.move.line']
move_lines = {x: [] for x in accounts.ids}
Expand Down
3 changes: 1 addition & 2 deletions om_account_followup/wizard/followup_print.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def _get_followup(self):
related='followup_id.company_id')
email_conf = fields.Boolean('Send Email Confirmation')
email_subject = fields.Char('Email Subject', size=64,
default=_('Invoices Reminder'))
default=lambda self: self.env._('Invoices Reminder'))
partner_lang = fields.Boolean(
'Send Email in Partner Language', default=True,
help='Do not change message text, if you want to send email in '
Expand Down Expand Up @@ -148,7 +148,6 @@ def do_process(self):
'report_data': restot['action']})
return {
'name': _('Send Letters and Emails: Actions Summary'),
'view_type': 'form',
'context': context,
'view_mode': 'list,form',
'res_model': 'followup.sending.results',
Expand Down
Loading