|
@ -1,8 +1,7 @@ |
|
|
|
|
|
|
|
|
# © 2016 Julien Coux (Camptocamp) |
|
|
# © 2016 Julien Coux (Camptocamp) |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
|
|
|
from odoo import models, fields, api, _ |
|
|
|
|
|
|
|
|
from odoo import _, api, fields, models |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GeneralLedgerReport(models.TransientModel): |
|
|
class GeneralLedgerReport(models.TransientModel): |
|
@ -21,8 +20,8 @@ class GeneralLedgerReport(models.TransientModel): |
|
|
For receivable/payable and not centralized accounts |
|
|
For receivable/payable and not centralized accounts |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
_name = 'report_general_ledger' |
|
|
|
|
|
_inherit = 'account_financial_report_abstract' |
|
|
|
|
|
|
|
|
_name = "report_general_ledger" |
|
|
|
|
|
_inherit = "account_financial_report_abstract" |
|
|
|
|
|
|
|
|
# Filters fields, used for data computation |
|
|
# Filters fields, used for data computation |
|
|
date_from = fields.Date() |
|
|
date_from = fields.Date() |
|
@ -32,71 +31,60 @@ class GeneralLedgerReport(models.TransientModel): |
|
|
hide_account_at_0 = fields.Boolean() |
|
|
hide_account_at_0 = fields.Boolean() |
|
|
foreign_currency = fields.Boolean() |
|
|
foreign_currency = fields.Boolean() |
|
|
show_analytic_tags = fields.Boolean() |
|
|
show_analytic_tags = fields.Boolean() |
|
|
company_id = fields.Many2one(comodel_name='res.company') |
|
|
|
|
|
filter_account_ids = fields.Many2many(comodel_name='account.account') |
|
|
|
|
|
filter_partner_ids = fields.Many2many(comodel_name='res.partner') |
|
|
|
|
|
filter_cost_center_ids = fields.Many2many( |
|
|
|
|
|
comodel_name='account.analytic.account' |
|
|
|
|
|
) |
|
|
|
|
|
filter_analytic_tag_ids = fields.Many2many( |
|
|
|
|
|
comodel_name='account.analytic.tag', |
|
|
|
|
|
) |
|
|
|
|
|
filter_journal_ids = fields.Many2many( |
|
|
|
|
|
comodel_name='account.journal', |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
company_id = fields.Many2one(comodel_name="res.company") |
|
|
|
|
|
filter_account_ids = fields.Many2many(comodel_name="account.account") |
|
|
|
|
|
filter_partner_ids = fields.Many2many(comodel_name="res.partner") |
|
|
|
|
|
filter_cost_center_ids = fields.Many2many(comodel_name="account.analytic.account") |
|
|
|
|
|
filter_analytic_tag_ids = fields.Many2many(comodel_name="account.analytic.tag",) |
|
|
|
|
|
filter_journal_ids = fields.Many2many(comodel_name="account.journal",) |
|
|
centralize = fields.Boolean() |
|
|
centralize = fields.Boolean() |
|
|
|
|
|
|
|
|
# Flag fields, used for report display |
|
|
# Flag fields, used for report display |
|
|
show_cost_center = fields.Boolean( |
|
|
show_cost_center = fields.Boolean( |
|
|
default=lambda self: self.env.user.has_group( |
|
|
default=lambda self: self.env.user.has_group( |
|
|
'analytic.group_analytic_accounting' |
|
|
|
|
|
|
|
|
"analytic.group_analytic_accounting" |
|
|
) |
|
|
) |
|
|
) |
|
|
) |
|
|
partner_ungrouped = fields.Boolean( |
|
|
partner_ungrouped = fields.Boolean( |
|
|
string='Partner ungrouped', |
|
|
|
|
|
help='If set moves are not grouped by partner in any case' |
|
|
|
|
|
|
|
|
string="Partner ungrouped", |
|
|
|
|
|
help="If set moves are not grouped by partner in any case", |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# Data fields, used to browse report data |
|
|
# Data fields, used to browse report data |
|
|
account_ids = fields.One2many( |
|
|
account_ids = fields.One2many( |
|
|
comodel_name='report_general_ledger_account', |
|
|
|
|
|
inverse_name='report_id' |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger_account", inverse_name="report_id" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# Compute of unaffected earnings account |
|
|
# Compute of unaffected earnings account |
|
|
@api.depends('company_id') |
|
|
|
|
|
|
|
|
@api.depends("company_id") |
|
|
def _compute_unaffected_earnings_account(self): |
|
|
def _compute_unaffected_earnings_account(self): |
|
|
account_type = self.env.ref('account.data_unaffected_earnings') |
|
|
|
|
|
self.unaffected_earnings_account = self.env['account.account'].search( |
|
|
|
|
|
|
|
|
account_type = self.env.ref("account.data_unaffected_earnings") |
|
|
|
|
|
self.unaffected_earnings_account = self.env["account.account"].search( |
|
|
[ |
|
|
[ |
|
|
('user_type_id', '=', account_type.id), |
|
|
|
|
|
('company_id', '=', self.company_id.id) |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
("user_type_id", "=", account_type.id), |
|
|
|
|
|
("company_id", "=", self.company_id.id), |
|
|
|
|
|
] |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
unaffected_earnings_account = fields.Many2one( |
|
|
unaffected_earnings_account = fields.Many2one( |
|
|
comodel_name='account.account', |
|
|
|
|
|
compute='_compute_unaffected_earnings_account', |
|
|
|
|
|
store=True |
|
|
|
|
|
|
|
|
comodel_name="account.account", |
|
|
|
|
|
compute="_compute_unaffected_earnings_account", |
|
|
|
|
|
store=True, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GeneralLedgerReportAccount(models.TransientModel): |
|
|
class GeneralLedgerReportAccount(models.TransientModel): |
|
|
|
|
|
|
|
|
_name = 'report_general_ledger_account' |
|
|
|
|
|
_inherit = 'account_financial_report_abstract' |
|
|
|
|
|
_order = 'code ASC' |
|
|
|
|
|
|
|
|
_name = "report_general_ledger_account" |
|
|
|
|
|
_inherit = "account_financial_report_abstract" |
|
|
|
|
|
_order = "code ASC" |
|
|
|
|
|
|
|
|
report_id = fields.Many2one( |
|
|
report_id = fields.Many2one( |
|
|
comodel_name='report_general_ledger', |
|
|
|
|
|
ondelete='cascade', |
|
|
|
|
|
index=True |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger", ondelete="cascade", index=True |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# Data fields, used to keep link with real object |
|
|
# Data fields, used to keep link with real object |
|
|
account_id = fields.Many2one( |
|
|
|
|
|
'account.account', |
|
|
|
|
|
index=True |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
account_id = fields.Many2one("account.account", index=True) |
|
|
|
|
|
|
|
|
# Data fields, used for report display |
|
|
# Data fields, used for report display |
|
|
code = fields.Char() |
|
|
code = fields.Char() |
|
@ -104,7 +92,7 @@ class GeneralLedgerReportAccount(models.TransientModel): |
|
|
initial_debit = fields.Float(digits=(16, 2)) |
|
|
initial_debit = fields.Float(digits=(16, 2)) |
|
|
initial_credit = fields.Float(digits=(16, 2)) |
|
|
initial_credit = fields.Float(digits=(16, 2)) |
|
|
initial_balance = fields.Float(digits=(16, 2)) |
|
|
initial_balance = fields.Float(digits=(16, 2)) |
|
|
currency_id = fields.Many2one('res.currency') |
|
|
|
|
|
|
|
|
currency_id = fields.Many2one("res.currency") |
|
|
initial_balance_foreign_currency = fields.Float(digits=(16, 2)) |
|
|
initial_balance_foreign_currency = fields.Float(digits=(16, 2)) |
|
|
final_debit = fields.Float(digits=(16, 2)) |
|
|
final_debit = fields.Float(digits=(16, 2)) |
|
|
final_credit = fields.Float(digits=(16, 2)) |
|
|
final_credit = fields.Float(digits=(16, 2)) |
|
@ -116,38 +104,31 @@ class GeneralLedgerReportAccount(models.TransientModel): |
|
|
|
|
|
|
|
|
# Data fields, used to browse report data |
|
|
# Data fields, used to browse report data |
|
|
move_line_ids = fields.One2many( |
|
|
move_line_ids = fields.One2many( |
|
|
comodel_name='report_general_ledger_move_line', |
|
|
|
|
|
inverse_name='report_account_id' |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger_move_line", inverse_name="report_account_id" |
|
|
) |
|
|
) |
|
|
partner_ids = fields.One2many( |
|
|
partner_ids = fields.One2many( |
|
|
comodel_name='report_general_ledger_partner', |
|
|
|
|
|
inverse_name='report_account_id' |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger_partner", inverse_name="report_account_id" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class GeneralLedgerReportPartner(models.TransientModel): |
|
|
class GeneralLedgerReportPartner(models.TransientModel): |
|
|
|
|
|
|
|
|
_name = 'report_general_ledger_partner' |
|
|
|
|
|
_inherit = 'account_financial_report_abstract' |
|
|
|
|
|
|
|
|
_name = "report_general_ledger_partner" |
|
|
|
|
|
_inherit = "account_financial_report_abstract" |
|
|
|
|
|
|
|
|
report_account_id = fields.Many2one( |
|
|
report_account_id = fields.Many2one( |
|
|
comodel_name='report_general_ledger_account', |
|
|
|
|
|
ondelete='cascade', |
|
|
|
|
|
index=True |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger_account", ondelete="cascade", index=True |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# Data fields, used to keep link with real object |
|
|
# Data fields, used to keep link with real object |
|
|
partner_id = fields.Many2one( |
|
|
|
|
|
'res.partner', |
|
|
|
|
|
index=True |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
partner_id = fields.Many2one("res.partner", index=True) |
|
|
|
|
|
|
|
|
# Data fields, used for report display |
|
|
# Data fields, used for report display |
|
|
name = fields.Char() |
|
|
name = fields.Char() |
|
|
initial_debit = fields.Float(digits=(16, 2)) |
|
|
initial_debit = fields.Float(digits=(16, 2)) |
|
|
initial_credit = fields.Float(digits=(16, 2)) |
|
|
initial_credit = fields.Float(digits=(16, 2)) |
|
|
initial_balance = fields.Float(digits=(16, 2)) |
|
|
initial_balance = fields.Float(digits=(16, 2)) |
|
|
currency_id = fields.Many2one('res.currency') |
|
|
|
|
|
|
|
|
currency_id = fields.Many2one("res.currency") |
|
|
initial_balance_foreign_currency = fields.Float(digits=(16, 2)) |
|
|
initial_balance_foreign_currency = fields.Float(digits=(16, 2)) |
|
|
final_debit = fields.Float(digits=(16, 2)) |
|
|
final_debit = fields.Float(digits=(16, 2)) |
|
|
final_credit = fields.Float(digits=(16, 2)) |
|
|
final_credit = fields.Float(digits=(16, 2)) |
|
@ -156,8 +137,7 @@ class GeneralLedgerReportPartner(models.TransientModel): |
|
|
|
|
|
|
|
|
# Data fields, used to browse report data |
|
|
# Data fields, used to browse report data |
|
|
move_line_ids = fields.One2many( |
|
|
move_line_ids = fields.One2many( |
|
|
comodel_name='report_general_ledger_move_line', |
|
|
|
|
|
inverse_name='report_partner_id' |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger_move_line", inverse_name="report_partner_id" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
@ -176,22 +156,18 @@ ORDER BY |
|
|
|
|
|
|
|
|
class GeneralLedgerReportMoveLine(models.TransientModel): |
|
|
class GeneralLedgerReportMoveLine(models.TransientModel): |
|
|
|
|
|
|
|
|
_name = 'report_general_ledger_move_line' |
|
|
|
|
|
_inherit = 'account_financial_report_abstract' |
|
|
|
|
|
|
|
|
_name = "report_general_ledger_move_line" |
|
|
|
|
|
_inherit = "account_financial_report_abstract" |
|
|
|
|
|
|
|
|
report_account_id = fields.Many2one( |
|
|
report_account_id = fields.Many2one( |
|
|
comodel_name='report_general_ledger_account', |
|
|
|
|
|
ondelete='cascade', |
|
|
|
|
|
index=True |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger_account", ondelete="cascade", index=True |
|
|
) |
|
|
) |
|
|
report_partner_id = fields.Many2one( |
|
|
report_partner_id = fields.Many2one( |
|
|
comodel_name='report_general_ledger_partner', |
|
|
|
|
|
ondelete='cascade', |
|
|
|
|
|
index=True |
|
|
|
|
|
|
|
|
comodel_name="report_general_ledger_partner", ondelete="cascade", index=True |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
# Data fields, used to keep link with real object |
|
|
# Data fields, used to keep link with real object |
|
|
move_line_id = fields.Many2one('account.move.line') |
|
|
|
|
|
|
|
|
move_line_id = fields.Many2one("account.move.line") |
|
|
|
|
|
|
|
|
# Data fields, used for report display |
|
|
# Data fields, used for report display |
|
|
date = fields.Date() |
|
|
date = fields.Date() |
|
@ -207,7 +183,7 @@ class GeneralLedgerReportMoveLine(models.TransientModel): |
|
|
debit = fields.Float(digits=(16, 2)) |
|
|
debit = fields.Float(digits=(16, 2)) |
|
|
credit = fields.Float(digits=(16, 2)) |
|
|
credit = fields.Float(digits=(16, 2)) |
|
|
cumul_balance = fields.Float(digits=(16, 2)) |
|
|
cumul_balance = fields.Float(digits=(16, 2)) |
|
|
currency_id = fields.Many2one('res.currency') |
|
|
|
|
|
|
|
|
currency_id = fields.Many2one("res.currency") |
|
|
amount_currency = fields.Float(digits=(16, 2)) |
|
|
amount_currency = fields.Float(digits=(16, 2)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -216,31 +192,34 @@ class GeneralLedgerReportCompute(models.TransientModel): |
|
|
For class fields, go more top at this file. |
|
|
For class fields, go more top at this file. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
_inherit = 'report_general_ledger' |
|
|
|
|
|
|
|
|
_inherit = "report_general_ledger" |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def print_report(self, report_type): |
|
|
def print_report(self, report_type): |
|
|
self.ensure_one() |
|
|
self.ensure_one() |
|
|
if report_type == 'xlsx': |
|
|
|
|
|
report_name = 'a_f_r.report_general_ledger_xlsx' |
|
|
|
|
|
|
|
|
if report_type == "xlsx": |
|
|
|
|
|
report_name = "a_f_r.report_general_ledger_xlsx" |
|
|
else: |
|
|
else: |
|
|
report_name = 'account_financial_report.' \ |
|
|
|
|
|
'report_general_ledger_qweb' |
|
|
|
|
|
return self.env['ir.actions.report'].search( |
|
|
|
|
|
[('report_name', '=', report_name), |
|
|
|
|
|
('report_type', '=', report_type)], |
|
|
|
|
|
limit=1).report_action(self, config=False) |
|
|
|
|
|
|
|
|
report_name = "account_financial_report." "report_general_ledger_qweb" |
|
|
|
|
|
return ( |
|
|
|
|
|
self.env["ir.actions.report"] |
|
|
|
|
|
.search( |
|
|
|
|
|
[("report_name", "=", report_name), ("report_type", "=", report_type)], |
|
|
|
|
|
limit=1, |
|
|
|
|
|
) |
|
|
|
|
|
.report_action(self, config=False) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
def _get_html(self): |
|
|
def _get_html(self): |
|
|
result = {} |
|
|
result = {} |
|
|
rcontext = {} |
|
|
rcontext = {} |
|
|
context = dict(self.env.context) |
|
|
context = dict(self.env.context) |
|
|
report = self.browse(context.get('active_id')) |
|
|
|
|
|
|
|
|
report = self.browse(context.get("active_id")) |
|
|
if report: |
|
|
if report: |
|
|
rcontext['o'] = report |
|
|
|
|
|
result['html'] = self.env.ref( |
|
|
|
|
|
'account_financial_report.report_general_ledger').render( |
|
|
|
|
|
rcontext) |
|
|
|
|
|
|
|
|
rcontext["o"] = report |
|
|
|
|
|
result["html"] = self.env.ref( |
|
|
|
|
|
"account_financial_report.report_general_ledger" |
|
|
|
|
|
).render(rcontext) |
|
|
return result |
|
|
return result |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
@ -248,9 +227,7 @@ class GeneralLedgerReportCompute(models.TransientModel): |
|
|
return self._get_html() |
|
|
return self._get_html() |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def compute_data_for_report(self, |
|
|
|
|
|
with_line_details=True, |
|
|
|
|
|
with_partners=True): |
|
|
|
|
|
|
|
|
def compute_data_for_report(self, with_line_details=True, with_partners=True): |
|
|
self.ensure_one() |
|
|
self.ensure_one() |
|
|
# Compute report data |
|
|
# Compute report data |
|
|
self._inject_account_values() |
|
|
self._inject_account_values() |
|
@ -260,9 +237,10 @@ class GeneralLedgerReportCompute(models.TransientModel): |
|
|
if not self.filter_partner_ids: |
|
|
if not self.filter_partner_ids: |
|
|
self._inject_partner_values(only_empty_partner=True) |
|
|
self._inject_partner_values(only_empty_partner=True) |
|
|
# Add unaffected earnings account |
|
|
# Add unaffected earnings account |
|
|
if (not self.filter_account_ids or |
|
|
|
|
|
self.unaffected_earnings_account.id in |
|
|
|
|
|
self.filter_account_ids.ids): |
|
|
|
|
|
|
|
|
if ( |
|
|
|
|
|
not self.filter_account_ids |
|
|
|
|
|
or self.unaffected_earnings_account.id in self.filter_account_ids.ids |
|
|
|
|
|
): |
|
|
self._inject_unaffected_earnings_account_values() |
|
|
self._inject_unaffected_earnings_account_values() |
|
|
|
|
|
|
|
|
# Call this function even if we don't want line details because, |
|
|
# Call this function even if we don't want line details because, |
|
@ -276,13 +254,14 @@ class GeneralLedgerReportCompute(models.TransientModel): |
|
|
|
|
|
|
|
|
if with_line_details: |
|
|
if with_line_details: |
|
|
self._inject_line_not_centralized_values( |
|
|
self._inject_line_not_centralized_values( |
|
|
is_account_line=False, |
|
|
|
|
|
is_partner_line=True) |
|
|
|
|
|
|
|
|
is_account_line=False, is_partner_line=True |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
self._inject_line_not_centralized_values( |
|
|
self._inject_line_not_centralized_values( |
|
|
is_account_line=False, |
|
|
is_account_line=False, |
|
|
is_partner_line=True, |
|
|
is_partner_line=True, |
|
|
only_empty_partner_line=True) |
|
|
|
|
|
|
|
|
only_empty_partner_line=True, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
if self.centralize: |
|
|
if self.centralize: |
|
|
self._inject_line_centralized_values() |
|
|
self._inject_line_centralized_values() |
|
@ -295,7 +274,8 @@ class GeneralLedgerReportCompute(models.TransientModel): |
|
|
self.invalidate_cache() |
|
|
self.invalidate_cache() |
|
|
|
|
|
|
|
|
def _get_account_sub_subquery_sum_amounts( |
|
|
def _get_account_sub_subquery_sum_amounts( |
|
|
self, include_initial_balance, date_included): |
|
|
|
|
|
|
|
|
self, include_initial_balance, date_included |
|
|
|
|
|
): |
|
|
""" Return subquery used to compute sum amounts on accounts """ |
|
|
""" Return subquery used to compute sum amounts on accounts """ |
|
|
sub_subquery_sum_amounts = """ |
|
|
sub_subquery_sum_amounts = """ |
|
|
SELECT |
|
|
SELECT |
|
@ -339,7 +319,9 @@ class GeneralLedgerReportCompute(models.TransientModel): |
|
|
sub_subquery_sum_amounts += """ |
|
|
sub_subquery_sum_amounts += """ |
|
|
AND |
|
|
AND |
|
|
ml.journal_id IN %s |
|
|
ml.journal_id IN %s |
|
|
""" % (tuple(self.filter_journal_ids.ids,),) |
|
|
|
|
|
|
|
|
""" % ( |
|
|
|
|
|
tuple(self.filter_journal_ids.ids,), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
if self.only_posted_moves: |
|
|
if self.only_posted_moves: |
|
|
sub_subquery_sum_amounts += """ |
|
|
sub_subquery_sum_amounts += """ |
|
@ -425,9 +407,9 @@ WITH |
|
|
account_account a |
|
|
account_account a |
|
|
""" |
|
|
""" |
|
|
if ( |
|
|
if ( |
|
|
self.filter_partner_ids or |
|
|
|
|
|
self.filter_cost_center_ids or |
|
|
|
|
|
self.filter_analytic_tag_ids |
|
|
|
|
|
|
|
|
self.filter_partner_ids |
|
|
|
|
|
or self.filter_cost_center_ids |
|
|
|
|
|
or self.filter_analytic_tag_ids |
|
|
): |
|
|
): |
|
|
query_inject_account += """ |
|
|
query_inject_account += """ |
|
|
INNER JOIN |
|
|
INNER JOIN |
|
@ -473,9 +455,9 @@ WITH |
|
|
p.id IN %s |
|
|
p.id IN %s |
|
|
""" |
|
|
""" |
|
|
if ( |
|
|
if ( |
|
|
self.filter_partner_ids or |
|
|
|
|
|
self.filter_cost_center_ids or |
|
|
|
|
|
self.filter_analytic_tag_ids |
|
|
|
|
|
|
|
|
self.filter_partner_ids |
|
|
|
|
|
or self.filter_cost_center_ids |
|
|
|
|
|
or self.filter_analytic_tag_ids |
|
|
): |
|
|
): |
|
|
query_inject_account += """ |
|
|
query_inject_account += """ |
|
|
GROUP BY |
|
|
GROUP BY |
|
@ -514,9 +496,14 @@ WITH |
|
|
date_included=True |
|
|
date_included=True |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account += """ |
|
|
|
|
|
initial_sum_amounts AS ( """ + init_subquery + """ ), |
|
|
|
|
|
final_sum_amounts AS ( """ + final_subquery + """ ) |
|
|
|
|
|
|
|
|
query_inject_account += ( |
|
|
|
|
|
""" |
|
|
|
|
|
initial_sum_amounts AS ( """ |
|
|
|
|
|
+ init_subquery |
|
|
|
|
|
+ """ ), |
|
|
|
|
|
final_sum_amounts AS ( """ |
|
|
|
|
|
+ final_subquery |
|
|
|
|
|
+ """ ) |
|
|
INSERT INTO |
|
|
INSERT INTO |
|
|
report_general_ledger_account |
|
|
report_general_ledger_account |
|
|
( |
|
|
( |
|
@ -572,6 +559,7 @@ WHERE |
|
|
OR f.balance IS NOT NULL AND f.balance != 0 |
|
|
OR f.balance IS NOT NULL AND f.balance != 0 |
|
|
) |
|
|
) |
|
|
""" |
|
|
""" |
|
|
|
|
|
) |
|
|
if self.hide_account_at_0: |
|
|
if self.hide_account_at_0: |
|
|
query_inject_account += """ |
|
|
query_inject_account += """ |
|
|
AND |
|
|
AND |
|
@ -579,59 +567,37 @@ AND |
|
|
""" |
|
|
""" |
|
|
query_inject_account_params = () |
|
|
query_inject_account_params = () |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_analytic_tag_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_analytic_tag_ids.ids),) |
|
|
query_inject_account_params += ( |
|
|
query_inject_account_params += ( |
|
|
self.company_id.id, |
|
|
self.company_id.id, |
|
|
self.unaffected_earnings_account.id, |
|
|
self.unaffected_earnings_account.id, |
|
|
) |
|
|
) |
|
|
if self.filter_account_ids: |
|
|
if self.filter_account_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_account_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_account_ids.ids),) |
|
|
if self.filter_partner_ids: |
|
|
if self.filter_partner_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_partner_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_partner_ids.ids),) |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_analytic_tag_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_analytic_tag_ids.ids),) |
|
|
query_inject_account_params += ( |
|
|
query_inject_account_params += ( |
|
|
self.date_from, |
|
|
self.date_from, |
|
|
self.fy_start_date, |
|
|
self.fy_start_date, |
|
|
) |
|
|
) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
query_inject_account_params += ( |
|
|
|
|
|
self.date_from, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
|
|
|
query_inject_account_params += (self.date_from,) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
query_inject_account_params += ( |
|
|
query_inject_account_params += ( |
|
|
self.date_to, |
|
|
self.date_to, |
|
|
self.fy_start_date, |
|
|
self.fy_start_date, |
|
|
) |
|
|
) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
query_inject_account_params += ( |
|
|
|
|
|
self.date_to, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
|
|
|
query_inject_account_params += (self.date_to,) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_account_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_account_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
query_inject_account_params += ( |
|
|
query_inject_account_params += ( |
|
|
self.id, |
|
|
self.id, |
|
|
self.env.uid, |
|
|
self.env.uid, |
|
@ -639,7 +605,7 @@ AND |
|
|
self.env.cr.execute(query_inject_account, query_inject_account_params) |
|
|
self.env.cr.execute(query_inject_account, query_inject_account_params) |
|
|
|
|
|
|
|
|
def _get_partner_sub_subquery_sum_amounts( |
|
|
def _get_partner_sub_subquery_sum_amounts( |
|
|
self, only_empty_partner, include_initial_balance, date_included |
|
|
|
|
|
|
|
|
self, only_empty_partner, include_initial_balance, date_included |
|
|
): |
|
|
): |
|
|
""" Return subquery used to compute sum amounts on partners """ |
|
|
""" Return subquery used to compute sum amounts on partners """ |
|
|
sub_subquery_sum_amounts = """ |
|
|
sub_subquery_sum_amounts = """ |
|
@ -713,8 +679,9 @@ AND |
|
|
""" |
|
|
""" |
|
|
return sub_subquery_sum_amounts |
|
|
return sub_subquery_sum_amounts |
|
|
|
|
|
|
|
|
def _get_final_partner_sub_subquery_sum_amounts(self, only_empty_partner, |
|
|
|
|
|
date_included): |
|
|
|
|
|
|
|
|
def _get_final_partner_sub_subquery_sum_amounts( |
|
|
|
|
|
self, only_empty_partner, date_included |
|
|
|
|
|
): |
|
|
"""Return final subquery used to compute sum amounts on partners""" |
|
|
"""Return final subquery used to compute sum amounts on partners""" |
|
|
|
|
|
|
|
|
subquery_sum_amounts = """ |
|
|
subquery_sum_amounts = """ |
|
@ -733,7 +700,7 @@ AND |
|
|
subquery_sum_amounts += self._get_partner_sub_subquery_sum_amounts( |
|
|
subquery_sum_amounts += self._get_partner_sub_subquery_sum_amounts( |
|
|
only_empty_partner, |
|
|
only_empty_partner, |
|
|
include_initial_balance=False, |
|
|
include_initial_balance=False, |
|
|
date_included=date_included |
|
|
|
|
|
|
|
|
date_included=date_included, |
|
|
) |
|
|
) |
|
|
subquery_sum_amounts += """ |
|
|
subquery_sum_amounts += """ |
|
|
UNION |
|
|
UNION |
|
@ -741,7 +708,7 @@ AND |
|
|
subquery_sum_amounts += self._get_partner_sub_subquery_sum_amounts( |
|
|
subquery_sum_amounts += self._get_partner_sub_subquery_sum_amounts( |
|
|
only_empty_partner, |
|
|
only_empty_partner, |
|
|
include_initial_balance=True, |
|
|
include_initial_balance=True, |
|
|
date_included=date_included |
|
|
|
|
|
|
|
|
date_included=date_included, |
|
|
) |
|
|
) |
|
|
subquery_sum_amounts += """ |
|
|
subquery_sum_amounts += """ |
|
|
) sub |
|
|
) sub |
|
@ -756,7 +723,8 @@ AND |
|
|
Only for "partner" accounts (payable and receivable). |
|
|
Only for "partner" accounts (payable and receivable). |
|
|
""" |
|
|
""" |
|
|
# pylint: disable=sql-injection |
|
|
# pylint: disable=sql-injection |
|
|
query_inject_partner = """ |
|
|
|
|
|
|
|
|
query_inject_partner = ( |
|
|
|
|
|
""" |
|
|
WITH |
|
|
WITH |
|
|
accounts_partners AS |
|
|
accounts_partners AS |
|
|
( |
|
|
( |
|
@ -773,7 +741,9 @@ WITH |
|
|
THEN p.name || ' (' || p.ref || ')' |
|
|
THEN p.name || ' (' || p.ref || ')' |
|
|
ELSE p.name |
|
|
ELSE p.name |
|
|
END, |
|
|
END, |
|
|
'""" + _('No partner allocated') + """' |
|
|
|
|
|
|
|
|
'""" |
|
|
|
|
|
+ _("No partner allocated") |
|
|
|
|
|
+ """' |
|
|
) AS partner_name |
|
|
) AS partner_name |
|
|
FROM |
|
|
FROM |
|
|
report_general_ledger_account ra |
|
|
report_general_ledger_account ra |
|
@ -786,6 +756,7 @@ WITH |
|
|
LEFT JOIN |
|
|
LEFT JOIN |
|
|
res_partner p ON ml.partner_id = p.id |
|
|
res_partner p ON ml.partner_id = p.id |
|
|
""" |
|
|
""" |
|
|
|
|
|
) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_partner += """ |
|
|
query_inject_partner += """ |
|
|
INNER JOIN |
|
|
INNER JOIN |
|
@ -834,12 +805,10 @@ WITH |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
init_subquery = self._get_final_partner_sub_subquery_sum_amounts( |
|
|
init_subquery = self._get_final_partner_sub_subquery_sum_amounts( |
|
|
only_empty_partner, |
|
|
|
|
|
date_included=False |
|
|
|
|
|
|
|
|
only_empty_partner, date_included=False |
|
|
) |
|
|
) |
|
|
final_subquery = self._get_final_partner_sub_subquery_sum_amounts( |
|
|
final_subquery = self._get_final_partner_sub_subquery_sum_amounts( |
|
|
only_empty_partner, |
|
|
|
|
|
date_included=True |
|
|
|
|
|
|
|
|
only_empty_partner, date_included=True |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner += """ |
|
|
query_inject_partner += """ |
|
@ -873,9 +842,14 @@ WITH |
|
|
), |
|
|
), |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
query_inject_partner += """ |
|
|
|
|
|
initial_sum_amounts AS ( """ + init_subquery + """ ), |
|
|
|
|
|
final_sum_amounts AS ( """ + final_subquery + """ ) |
|
|
|
|
|
|
|
|
query_inject_partner += ( |
|
|
|
|
|
""" |
|
|
|
|
|
initial_sum_amounts AS ( """ |
|
|
|
|
|
+ init_subquery |
|
|
|
|
|
+ """ ), |
|
|
|
|
|
final_sum_amounts AS ( """ |
|
|
|
|
|
+ final_subquery |
|
|
|
|
|
+ """ ) |
|
|
INSERT INTO |
|
|
INSERT INTO |
|
|
report_general_ledger_partner |
|
|
report_general_ledger_partner |
|
|
( |
|
|
( |
|
@ -916,6 +890,7 @@ LEFT JOIN |
|
|
ON |
|
|
ON |
|
|
( |
|
|
( |
|
|
""" |
|
|
""" |
|
|
|
|
|
) |
|
|
if not only_empty_partner: |
|
|
if not only_empty_partner: |
|
|
query_inject_partner += """ |
|
|
query_inject_partner += """ |
|
|
ap.partner_id = i.partner_id |
|
|
ap.partner_id = i.partner_id |
|
@ -960,65 +935,42 @@ AND |
|
|
""" |
|
|
""" |
|
|
query_inject_partner_params = () |
|
|
query_inject_partner_params = () |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_analytic_tag_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
query_inject_partner_params += ( |
|
|
|
|
|
self.id, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_analytic_tag_ids.ids),) |
|
|
|
|
|
query_inject_partner_params += (self.id,) |
|
|
if self.filter_partner_ids: |
|
|
if self.filter_partner_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_partner_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_partner_ids.ids),) |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_analytic_tag_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_analytic_tag_ids.ids),) |
|
|
query_inject_partner_params += ( |
|
|
query_inject_partner_params += ( |
|
|
self.date_from, |
|
|
self.date_from, |
|
|
self.fy_start_date, |
|
|
self.fy_start_date, |
|
|
) |
|
|
) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
query_inject_partner_params += ( |
|
|
|
|
|
self.date_from, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
|
|
|
query_inject_partner_params += (self.date_from,) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
query_inject_partner_params += ( |
|
|
query_inject_partner_params += ( |
|
|
self.date_to, |
|
|
self.date_to, |
|
|
self.fy_start_date, |
|
|
self.fy_start_date, |
|
|
) |
|
|
) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
query_inject_partner_params += ( |
|
|
|
|
|
self.date_to, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
|
|
|
query_inject_partner_params += (self.date_to,) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_partner_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
query_inject_partner_params += ( |
|
|
|
|
|
self.env.uid, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_partner_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
|
|
|
query_inject_partner_params += (self.env.uid,) |
|
|
self.env.cr.execute(query_inject_partner, query_inject_partner_params) |
|
|
self.env.cr.execute(query_inject_partner, query_inject_partner_params) |
|
|
|
|
|
|
|
|
def _inject_line_not_centralized_values( |
|
|
def _inject_line_not_centralized_values( |
|
|
self, |
|
|
|
|
|
is_account_line=True, |
|
|
|
|
|
is_partner_line=False, |
|
|
|
|
|
only_empty_partner_line=False, |
|
|
|
|
|
only_unaffected_earnings_account=False): |
|
|
|
|
|
|
|
|
self, |
|
|
|
|
|
is_account_line=True, |
|
|
|
|
|
is_partner_line=False, |
|
|
|
|
|
only_empty_partner_line=False, |
|
|
|
|
|
only_unaffected_earnings_account=False, |
|
|
|
|
|
): |
|
|
""" Inject report values for report_general_ledger_move_line. |
|
|
""" Inject report values for report_general_ledger_move_line. |
|
|
|
|
|
|
|
|
If centralized option have been chosen, |
|
|
If centralized option have been chosen, |
|
@ -1151,9 +1103,13 @@ SELECT |
|
|
END AS partner, |
|
|
END AS partner, |
|
|
""" |
|
|
""" |
|
|
elif only_empty_partner_line: |
|
|
elif only_empty_partner_line: |
|
|
query_inject_move_line += """ |
|
|
|
|
|
'""" + _('No partner allocated') + """' AS partner, |
|
|
|
|
|
|
|
|
query_inject_move_line += ( |
|
|
|
|
|
""" |
|
|
|
|
|
'""" |
|
|
|
|
|
+ _("No partner allocated") |
|
|
|
|
|
+ """' AS partner, |
|
|
""" |
|
|
""" |
|
|
|
|
|
) |
|
|
query_inject_move_line += """ |
|
|
query_inject_move_line += """ |
|
|
CONCAT_WS(' - ', NULLIF(ml.ref, ''), NULLIF(ml.name, '')) AS label, |
|
|
CONCAT_WS(' - ', NULLIF(ml.ref, ''), NULLIF(ml.name, '')) AS label, |
|
|
aa.name AS cost_center, |
|
|
aa.name AS cost_center, |
|
@ -1243,7 +1199,7 @@ LEFT JOIN |
|
|
account_analytic_account aa ON ml.analytic_account_id = aa.id |
|
|
account_analytic_account aa ON ml.analytic_account_id = aa.id |
|
|
""" |
|
|
""" |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_inject_move_line += """ |
|
|
|
|
|
|
|
|
query_inject_move_line += """ |
|
|
INNER JOIN |
|
|
INNER JOIN |
|
|
move_lines_on_tags ON ml.id = move_lines_on_tags.ml_id |
|
|
move_lines_on_tags ON ml.id = move_lines_on_tags.ml_id |
|
|
""" |
|
|
""" |
|
@ -1313,32 +1269,19 @@ ORDER BY |
|
|
self.id, |
|
|
self.id, |
|
|
tuple(self.filter_analytic_tag_ids.ids), |
|
|
tuple(self.filter_analytic_tag_ids.ids), |
|
|
) |
|
|
) |
|
|
query_inject_move_line_params += ( |
|
|
|
|
|
self.env.uid, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_move_line_params += (self.env.uid,) |
|
|
if self.filter_cost_center_ids: |
|
|
if self.filter_cost_center_ids: |
|
|
query_inject_move_line_params += ( |
|
|
|
|
|
tuple(self.filter_cost_center_ids.ids), |
|
|
|
|
|
) |
|
|
|
|
|
query_inject_move_line_params += ( |
|
|
|
|
|
self.id, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_move_line_params += (tuple(self.filter_cost_center_ids.ids),) |
|
|
|
|
|
query_inject_move_line_params += (self.id,) |
|
|
if only_unaffected_earnings_account: |
|
|
if only_unaffected_earnings_account: |
|
|
query_inject_move_line_params += ( |
|
|
|
|
|
self.unaffected_earnings_account.id, |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_move_line_params += (self.unaffected_earnings_account.id,) |
|
|
query_inject_move_line_params += ( |
|
|
query_inject_move_line_params += ( |
|
|
self.date_from, |
|
|
self.date_from, |
|
|
self.date_to, |
|
|
self.date_to, |
|
|
) |
|
|
) |
|
|
if self.filter_journal_ids: |
|
|
if self.filter_journal_ids: |
|
|
query_inject_move_line_params += (tuple( |
|
|
|
|
|
self.filter_journal_ids.ids, |
|
|
|
|
|
),) |
|
|
|
|
|
self.env.cr.execute( |
|
|
|
|
|
query_inject_move_line, |
|
|
|
|
|
query_inject_move_line_params |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
query_inject_move_line_params += (tuple(self.filter_journal_ids.ids,),) |
|
|
|
|
|
self.env.cr.execute(query_inject_move_line, query_inject_move_line_params) |
|
|
|
|
|
|
|
|
def _inject_line_centralized_values(self): |
|
|
def _inject_line_centralized_values(self): |
|
|
""" Inject report values for report_general_ledger_move_line. |
|
|
""" Inject report values for report_general_ledger_move_line. |
|
@ -1423,7 +1366,8 @@ WITH |
|
|
AND |
|
|
AND |
|
|
m.state = 'posted' |
|
|
m.state = 'posted' |
|
|
""" |
|
|
""" |
|
|
query_inject_move_line_centralized += """ |
|
|
|
|
|
|
|
|
query_inject_move_line_centralized += ( |
|
|
|
|
|
""" |
|
|
GROUP BY |
|
|
GROUP BY |
|
|
ra.id, ml.account_id, a.code, 2, ml.currency_id, ml.journal_id |
|
|
ra.id, ml.account_id, a.code, 2, ml.currency_id, ml.journal_id |
|
|
) |
|
|
) |
|
@ -1448,7 +1392,9 @@ SELECT |
|
|
ml.date, |
|
|
ml.date, |
|
|
a.code AS account, |
|
|
a.code AS account, |
|
|
j.code AS journal, |
|
|
j.code AS journal, |
|
|
'""" + _('Centralized Entries') + """' AS label, |
|
|
|
|
|
|
|
|
'""" |
|
|
|
|
|
+ _("Centralized Entries") |
|
|
|
|
|
+ """' AS label, |
|
|
ml.debit AS debit, |
|
|
ml.debit AS debit, |
|
|
ml.credit AS credit, |
|
|
ml.credit AS credit, |
|
|
ra.initial_balance + ( |
|
|
ra.initial_balance + ( |
|
@ -1470,6 +1416,7 @@ WHERE |
|
|
AND |
|
|
AND |
|
|
(a.centralized IS NOT NULL AND a.centralized = TRUE) |
|
|
(a.centralized IS NOT NULL AND a.centralized = TRUE) |
|
|
""" |
|
|
""" |
|
|
|
|
|
) |
|
|
if self.filter_journal_ids: |
|
|
if self.filter_journal_ids: |
|
|
query_inject_move_line_centralized += """ |
|
|
query_inject_move_line_centralized += """ |
|
|
AND |
|
|
AND |
|
@ -1498,12 +1445,12 @@ ORDER BY |
|
|
self.id, |
|
|
self.id, |
|
|
) |
|
|
) |
|
|
if self.filter_journal_ids: |
|
|
if self.filter_journal_ids: |
|
|
query_inject_move_line_centralized_params += (tuple( |
|
|
|
|
|
self.filter_journal_ids.ids, |
|
|
|
|
|
),) |
|
|
|
|
|
|
|
|
query_inject_move_line_centralized_params += ( |
|
|
|
|
|
tuple(self.filter_journal_ids.ids,), |
|
|
|
|
|
) |
|
|
self.env.cr.execute( |
|
|
self.env.cr.execute( |
|
|
query_inject_move_line_centralized, |
|
|
query_inject_move_line_centralized, |
|
|
query_inject_move_line_centralized_params |
|
|
|
|
|
|
|
|
query_inject_move_line_centralized_params, |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
def _compute_analytic_tags(self): |
|
|
def _compute_analytic_tags(self): |
|
@ -1572,7 +1519,7 @@ WHERE |
|
|
report_general_ledger_move_line.id = tags_values.report_id |
|
|
report_general_ledger_move_line.id = tags_values.report_id |
|
|
""" |
|
|
""" |
|
|
params = { |
|
|
params = { |
|
|
'report_id': self.id, |
|
|
|
|
|
|
|
|
"report_id": self.id, |
|
|
} |
|
|
} |
|
|
self.env.cr.execute(query_update_analytic_tags, params) |
|
|
self.env.cr.execute(query_update_analytic_tags, params) |
|
|
|
|
|
|
|
@ -1589,20 +1536,21 @@ WHERE |
|
|
""" |
|
|
""" |
|
|
self.env.cr.execute(query_unaffected_earnings_account_ids) |
|
|
self.env.cr.execute(query_unaffected_earnings_account_ids) |
|
|
pl_account_ids = [r[0] for r in self.env.cr.fetchall()] |
|
|
pl_account_ids = [r[0] for r in self.env.cr.fetchall()] |
|
|
unaffected_earnings_account_ids = \ |
|
|
|
|
|
pl_account_ids + [self.unaffected_earnings_account.id] |
|
|
|
|
|
|
|
|
unaffected_earnings_account_ids = pl_account_ids + [ |
|
|
|
|
|
self.unaffected_earnings_account.id |
|
|
|
|
|
] |
|
|
# Fetch the current fiscal year start date |
|
|
# Fetch the current fiscal year start date |
|
|
date = fields.Datetime.from_string(self.date_from) |
|
|
date = fields.Datetime.from_string(self.date_from) |
|
|
res = self.company_id.compute_fiscalyear_dates(date) |
|
|
res = self.company_id.compute_fiscalyear_dates(date) |
|
|
fy_start_date = res['date_from'] |
|
|
|
|
|
|
|
|
fy_start_date = res["date_from"] |
|
|
query_select_previous_fy_unaffected_earnings_params = { |
|
|
query_select_previous_fy_unaffected_earnings_params = { |
|
|
'date_to': fy_start_date, |
|
|
|
|
|
'company_id': self.company_id.id, |
|
|
|
|
|
'account_ids': tuple(unaffected_earnings_account_ids), |
|
|
|
|
|
'analytic_tag_ids': tuple(self.filter_analytic_tag_ids.ids), |
|
|
|
|
|
|
|
|
"date_to": fy_start_date, |
|
|
|
|
|
"company_id": self.company_id.id, |
|
|
|
|
|
"account_ids": tuple(unaffected_earnings_account_ids), |
|
|
|
|
|
"analytic_tag_ids": tuple(self.filter_analytic_tag_ids.ids), |
|
|
} |
|
|
} |
|
|
query_select_previous_fy_unaffected_earnings = '' |
|
|
|
|
|
q_analytic_tags = '' |
|
|
|
|
|
|
|
|
query_select_previous_fy_unaffected_earnings = "" |
|
|
|
|
|
q_analytic_tags = "" |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
q_analytic_tags = """ |
|
|
q_analytic_tags = """ |
|
|
WITH move_lines_on_tags AS |
|
|
WITH move_lines_on_tags AS |
|
@ -1642,7 +1590,8 @@ WITH move_lines_on_tags AS |
|
|
AND aa.id IN %(cost_center_ids)s |
|
|
AND aa.id IN %(cost_center_ids)s |
|
|
""" |
|
|
""" |
|
|
query_select_previous_fy_unaffected_earnings_params[ |
|
|
query_select_previous_fy_unaffected_earnings_params[ |
|
|
'cost_center_ids'] = tuple(self.filter_cost_center_ids.ids) |
|
|
|
|
|
|
|
|
"cost_center_ids" |
|
|
|
|
|
] = tuple(self.filter_cost_center_ids.ids) |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_select_previous_fy_unaffected_earnings += """ |
|
|
query_select_previous_fy_unaffected_earnings += """ |
|
|
INNER JOIN move_lines_on_tags ON ml.id = |
|
|
INNER JOIN move_lines_on_tags ON ml.id = |
|
@ -1657,27 +1606,29 @@ WITH move_lines_on_tags AS |
|
|
query_select_previous_fy_unaffected_earnings += """ |
|
|
query_select_previous_fy_unaffected_earnings += """ |
|
|
AND j.id IN %(journal_ids)s |
|
|
AND j.id IN %(journal_ids)s |
|
|
""" |
|
|
""" |
|
|
query_select_previous_fy_unaffected_earnings_params[ |
|
|
|
|
|
'journal_ids'] = tuple(self.filter_journal_ids.ids) |
|
|
|
|
|
|
|
|
query_select_previous_fy_unaffected_earnings_params["journal_ids"] = tuple( |
|
|
|
|
|
self.filter_journal_ids.ids |
|
|
|
|
|
) |
|
|
if self.only_posted_moves: |
|
|
if self.only_posted_moves: |
|
|
query_select_previous_fy_unaffected_earnings += """ |
|
|
query_select_previous_fy_unaffected_earnings += """ |
|
|
AND am.state = 'posted' |
|
|
AND am.state = 'posted' |
|
|
""" |
|
|
""" |
|
|
self.env.cr.execute( |
|
|
self.env.cr.execute( |
|
|
query_select_previous_fy_unaffected_earnings, |
|
|
query_select_previous_fy_unaffected_earnings, |
|
|
query_select_previous_fy_unaffected_earnings_params) |
|
|
|
|
|
|
|
|
query_select_previous_fy_unaffected_earnings_params, |
|
|
|
|
|
) |
|
|
res = self.env.cr.fetchone() |
|
|
res = self.env.cr.fetchone() |
|
|
unaffected_earnings_initial_balance = res[0] or 0.0 |
|
|
unaffected_earnings_initial_balance = res[0] or 0.0 |
|
|
# Now select the current period unaffected earnings, |
|
|
# Now select the current period unaffected earnings, |
|
|
# excluding the current period P&L. |
|
|
# excluding the current period P&L. |
|
|
query_select_period_unaffected_earnings_params = { |
|
|
query_select_period_unaffected_earnings_params = { |
|
|
'date_from': self.date_from, |
|
|
|
|
|
'date_to': self.date_to, |
|
|
|
|
|
'company_id': self.company_id.id, |
|
|
|
|
|
'unaffected_earnings_id': self.unaffected_earnings_account.id, |
|
|
|
|
|
'analytic_tag_ids': tuple(self.filter_analytic_tag_ids.ids), |
|
|
|
|
|
|
|
|
"date_from": self.date_from, |
|
|
|
|
|
"date_to": self.date_to, |
|
|
|
|
|
"company_id": self.company_id.id, |
|
|
|
|
|
"unaffected_earnings_id": self.unaffected_earnings_account.id, |
|
|
|
|
|
"analytic_tag_ids": tuple(self.filter_analytic_tag_ids.ids), |
|
|
} |
|
|
} |
|
|
query_select_period_unaffected_earnings = '' |
|
|
|
|
|
|
|
|
query_select_period_unaffected_earnings = "" |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_select_period_unaffected_earnings += q_analytic_tags |
|
|
query_select_period_unaffected_earnings += q_analytic_tags |
|
|
query_select_period_unaffected_earnings += """ |
|
|
query_select_period_unaffected_earnings += """ |
|
@ -1697,8 +1648,9 @@ WITH move_lines_on_tags AS |
|
|
ON ml.analytic_account_id = aa.id |
|
|
ON ml.analytic_account_id = aa.id |
|
|
AND aa.id IN %(cost_center_ids)s |
|
|
AND aa.id IN %(cost_center_ids)s |
|
|
""" |
|
|
""" |
|
|
query_select_period_unaffected_earnings_params[ |
|
|
|
|
|
'cost_center_ids'] = tuple(self.filter_cost_center_ids.ids) |
|
|
|
|
|
|
|
|
query_select_period_unaffected_earnings_params["cost_center_ids"] = tuple( |
|
|
|
|
|
self.filter_cost_center_ids.ids |
|
|
|
|
|
) |
|
|
if self.filter_analytic_tag_ids: |
|
|
if self.filter_analytic_tag_ids: |
|
|
query_select_period_unaffected_earnings += """ |
|
|
query_select_period_unaffected_earnings += """ |
|
|
INNER JOIN move_lines_on_tags |
|
|
INNER JOIN move_lines_on_tags |
|
@ -1714,14 +1666,17 @@ WITH move_lines_on_tags AS |
|
|
query_select_period_unaffected_earnings += """ |
|
|
query_select_period_unaffected_earnings += """ |
|
|
AND j.id IN %(journal_ids)s |
|
|
AND j.id IN %(journal_ids)s |
|
|
""" |
|
|
""" |
|
|
query_select_period_unaffected_earnings_params[ |
|
|
|
|
|
'journal_ids'] = tuple(self.filter_journal_ids.ids) |
|
|
|
|
|
|
|
|
query_select_period_unaffected_earnings_params["journal_ids"] = tuple( |
|
|
|
|
|
self.filter_journal_ids.ids |
|
|
|
|
|
) |
|
|
if self.only_posted_moves: |
|
|
if self.only_posted_moves: |
|
|
query_select_period_unaffected_earnings += """ |
|
|
query_select_period_unaffected_earnings += """ |
|
|
AND am.state = 'posted' |
|
|
AND am.state = 'posted' |
|
|
""" |
|
|
""" |
|
|
self.env.cr.execute(query_select_period_unaffected_earnings, |
|
|
|
|
|
query_select_period_unaffected_earnings_params) |
|
|
|
|
|
|
|
|
self.env.cr.execute( |
|
|
|
|
|
query_select_period_unaffected_earnings, |
|
|
|
|
|
query_select_period_unaffected_earnings_params, |
|
|
|
|
|
) |
|
|
res = self.env.cr.fetchone() |
|
|
res = self.env.cr.fetchone() |
|
|
unaffected_earnings_period_debit = res[0] or 0.0 |
|
|
unaffected_earnings_period_debit = res[0] or 0.0 |
|
|
unaffected_earnings_period_credit = res[1] or 0.0 |
|
|
unaffected_earnings_period_credit = res[1] or 0.0 |
|
@ -1760,24 +1715,30 @@ WITH move_lines_on_tags AS |
|
|
%(final_balance)s |
|
|
%(final_balance)s |
|
|
) |
|
|
) |
|
|
""" |
|
|
""" |
|
|
initial_debit = unaffected_earnings_initial_balance >= 0 and \ |
|
|
|
|
|
unaffected_earnings_initial_balance or 0 |
|
|
|
|
|
initial_credit = unaffected_earnings_initial_balance < 0 and \ |
|
|
|
|
|
-1 * unaffected_earnings_initial_balance or 0 |
|
|
|
|
|
final_balance = unaffected_earnings_initial_balance + \ |
|
|
|
|
|
unaffected_earnings_period_balance |
|
|
|
|
|
|
|
|
initial_debit = ( |
|
|
|
|
|
unaffected_earnings_initial_balance >= 0 |
|
|
|
|
|
and unaffected_earnings_initial_balance |
|
|
|
|
|
or 0 |
|
|
|
|
|
) |
|
|
|
|
|
initial_credit = ( |
|
|
|
|
|
unaffected_earnings_initial_balance < 0 |
|
|
|
|
|
and -1 * unaffected_earnings_initial_balance |
|
|
|
|
|
or 0 |
|
|
|
|
|
) |
|
|
|
|
|
final_balance = ( |
|
|
|
|
|
unaffected_earnings_initial_balance + unaffected_earnings_period_balance |
|
|
|
|
|
) |
|
|
query_inject_account_params = { |
|
|
query_inject_account_params = { |
|
|
'report_id': self.id, |
|
|
|
|
|
'user_id': self.env.uid, |
|
|
|
|
|
'account_id': self.unaffected_earnings_account.id, |
|
|
|
|
|
'code': self.unaffected_earnings_account.code, |
|
|
|
|
|
'name': self.unaffected_earnings_account.name, |
|
|
|
|
|
'initial_debit': initial_debit, |
|
|
|
|
|
'initial_credit': initial_credit, |
|
|
|
|
|
'initial_balance': unaffected_earnings_initial_balance, |
|
|
|
|
|
'final_debit': initial_debit + unaffected_earnings_period_debit, |
|
|
|
|
|
'final_credit': initial_credit + unaffected_earnings_period_credit, |
|
|
|
|
|
'final_balance': final_balance, |
|
|
|
|
|
|
|
|
"report_id": self.id, |
|
|
|
|
|
"user_id": self.env.uid, |
|
|
|
|
|
"account_id": self.unaffected_earnings_account.id, |
|
|
|
|
|
"code": self.unaffected_earnings_account.code, |
|
|
|
|
|
"name": self.unaffected_earnings_account.name, |
|
|
|
|
|
"initial_debit": initial_debit, |
|
|
|
|
|
"initial_credit": initial_credit, |
|
|
|
|
|
"initial_balance": unaffected_earnings_initial_balance, |
|
|
|
|
|
"final_debit": initial_debit + unaffected_earnings_period_debit, |
|
|
|
|
|
"final_credit": initial_credit + unaffected_earnings_period_credit, |
|
|
|
|
|
"final_balance": final_balance, |
|
|
} |
|
|
} |
|
|
self.env.cr.execute(query_inject_account, |
|
|
|
|
|
query_inject_account_params) |
|
|
|
|
|
|
|
|
self.env.cr.execute(query_inject_account, query_inject_account_params) |