Browse Source

[ADD] foreign currency total in xlsx General ledger report

pull/424/head
Simone Rubino 7 years ago
committed by hveficent
parent
commit
a8db3831ac
  1. 49
      account_financial_report_qweb/report/abstract_report_xlsx.py
  2. 58
      account_financial_report_qweb/report/general_ledger.py
  3. 9
      account_financial_report_qweb/report/general_ledger_xlsx.py
  4. 228
      account_financial_report_qweb/report/open_items.py
  5. 8
      account_financial_report_qweb/report/open_items_xlsx.py
  6. 18
      account_financial_report_qweb/report/templates/general_ledger.xml
  7. 14
      account_financial_report_qweb/report/templates/open_items.xml
  8. 6
      account_financial_report_qweb/report/templates/trial_balance.xml
  9. 12
      account_financial_report_qweb/report/trial_balance.py

49
account_financial_report_qweb/report/abstract_report_xlsx.py

@ -108,6 +108,22 @@ class AbstractReportXslx(ReportXlsx):
) )
self.format_percent_bold_italic.set_num_format('#,##0.00%') self.format_percent_bold_italic.set_num_format('#,##0.00%')
def _get_currency_amt_format(self, line_object):
""" Return amount format specific for each currency. """
format_amt = getattr(self, 'format_amount')
if line_object.currency_id:
field_name = \
'format_amount_%s' % line_object.currency_id.name
if hasattr(self, field_name):
format_amt = getattr(self, field_name)
else:
format_amt = self.workbook.add_format()
setattr(self, 'field_name', format_amt)
format_amount = \
'#,##0.' + ('0' * line_object.currency_id.decimal_places)
format_amt.set_num_format(format_amount)
return format_amt
def _set_column_width(self): def _set_column_width(self):
"""Set width for all defined columns. """Set width for all defined columns.
Columns are defined with `_get_report_columns` method. Columns are defined with `_get_report_columns` method.
@ -189,6 +205,14 @@ class AbstractReportXslx(ReportXlsx):
self.sheet.write_number( self.sheet.write_number(
self.row_pos, col_pos, float(value), self.format_amount self.row_pos, col_pos, float(value), self.format_amount
) )
elif cell_type == 'amount_currency':
if line_object.currency_id:
format_amt = self._get_currency_amt_format(line_object)
self.sheet.write_number(
self.row_pos, col_pos, float(value), format_amt)
elif cell_type == 'many2one':
self.sheet.write_string(
self.row_pos, col_pos, value.name or '', self.format_right)
self.row_pos += 1 self.row_pos += 1
def write_initial_balance(self, my_object, label): def write_initial_balance(self, my_object, label):
@ -209,6 +233,19 @@ class AbstractReportXslx(ReportXlsx):
self.sheet.write_number( self.sheet.write_number(
self.row_pos, col_pos, float(value), self.format_amount self.row_pos, col_pos, float(value), self.format_amount
) )
elif cell_type == 'amount_currency':
if my_object.currency_id:
format_amt = self._get_currency_amt_format(
my_object)
self.sheet.write_number(
self.row_pos, col_pos,
float(value), format_amt
)
elif cell_type == 'many2one':
self.sheet.write_string(
self.row_pos, col_pos, value.name or '',
self.format_header_right)
self.row_pos += 1 self.row_pos += 1
def write_ending_balance(self, my_object, name, label): def write_ending_balance(self, my_object, name, label):
@ -239,6 +276,18 @@ class AbstractReportXslx(ReportXlsx):
self.row_pos, col_pos, float(value), self.row_pos, col_pos, float(value),
self.format_header_amount self.format_header_amount
) )
elif cell_type == 'amount_currency':
if my_object.currency_id:
format_amt = self._get_currency_amt_format(
my_object)
self.sheet.write_number(
self.row_pos, col_pos,
float(value), format_amt
)
elif cell_type == 'many2one':
self.sheet.write_string(
self.row_pos, col_pos, value.name or '',
self.format_header_right)
self.row_pos += 1 self.row_pos += 1
def _generate_report_content(self, workbook, report): def _generate_report_content(self, workbook, report):

58
account_financial_report_qweb/report/general_ledger.py

@ -91,7 +91,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_name = fields.Char()
currency_id = fields.Many2one(comodel_name='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))
@ -133,7 +133,7 @@ class GeneralLedgerReportPartner(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_name = fields.Char()
currency_id = fields.Many2one(comodel_name='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))
@ -191,7 +191,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_name = fields.Char()
currency_id = fields.Many2one(comodel_name='res.currency')
amount_currency = fields.Float(digits=(16, 2)) amount_currency = fields.Float(digits=(16, 2))
@ -271,8 +271,12 @@ class GeneralLedgerReportCompute(models.TransientModel):
SUM(ml.debit) AS debit, SUM(ml.debit) AS debit,
SUM(ml.credit) AS credit, SUM(ml.credit) AS credit,
SUM(ml.balance) AS balance, SUM(ml.balance) AS balance,
c.name AS currency_name,
SUM(ml.amount_currency) AS balance_currency
c.id AS currency_id,
CASE
WHEN c.id IS NOT NULL
THEN SUM(ml.amount_currency)
ELSE NULL
END AS balance_currency
FROM FROM
accounts a accounts a
INNER JOIN INNER JOIN
@ -319,7 +323,7 @@ class GeneralLedgerReportCompute(models.TransientModel):
""" """
sub_subquery_sum_amounts += """ sub_subquery_sum_amounts += """
GROUP BY GROUP BY
a.id, c.name
a.id, c.id
""" """
return sub_subquery_sum_amounts return sub_subquery_sum_amounts
@ -331,7 +335,7 @@ class GeneralLedgerReportCompute(models.TransientModel):
SUM(COALESCE(sub.debit, 0.0)) AS debit, SUM(COALESCE(sub.debit, 0.0)) AS debit,
SUM(COALESCE(sub.credit, 0.0)) AS credit, SUM(COALESCE(sub.credit, 0.0)) AS credit,
SUM(COALESCE(sub.balance, 0.0)) AS balance, SUM(COALESCE(sub.balance, 0.0)) AS balance,
MAX(sub.currency_name) AS currency_name,
MAX(sub.currency_id) AS currency_id,
SUM(COALESCE(sub.balance_currency, 0.0)) AS balance_currency SUM(COALESCE(sub.balance_currency, 0.0)) AS balance_currency
FROM FROM
( (
@ -431,7 +435,7 @@ INSERT INTO
initial_debit, initial_debit,
initial_credit, initial_credit,
initial_balance, initial_balance,
currency_name,
currency_id,
initial_balance_foreign_currency, initial_balance_foreign_currency,
final_debit, final_debit,
final_credit, final_credit,
@ -449,7 +453,7 @@ SELECT
COALESCE(i.debit, 0.0) AS initial_debit, COALESCE(i.debit, 0.0) AS initial_debit,
COALESCE(i.credit, 0.0) AS initial_credit, COALESCE(i.credit, 0.0) AS initial_credit,
COALESCE(i.balance, 0.0) AS initial_balance, COALESCE(i.balance, 0.0) AS initial_balance,
c.name AS currency_name,
a.currency_id,
COALESCE(i.balance_currency, 0.0) AS initial_balance_foreign_currency, COALESCE(i.balance_currency, 0.0) AS initial_balance_foreign_currency,
COALESCE(f.debit, 0.0) AS final_debit, COALESCE(f.debit, 0.0) AS final_debit,
COALESCE(f.credit, 0.0) AS final_credit, COALESCE(f.credit, 0.0) AS final_credit,
@ -462,8 +466,6 @@ LEFT JOIN
initial_sum_amounts i ON a.id = i.account_id initial_sum_amounts i ON a.id = i.account_id
LEFT JOIN LEFT JOIN
final_sum_amounts f ON a.id = f.account_id final_sum_amounts f ON a.id = f.account_id
LEFT JOIN
res_currency c ON c.id = a.currency_id
WHERE WHERE
( (
i.debit IS NOT NULL AND i.debit != 0 i.debit IS NOT NULL AND i.debit != 0
@ -543,14 +545,18 @@ AND
SUM(ml.debit) AS debit, SUM(ml.debit) AS debit,
SUM(ml.credit) AS credit, SUM(ml.credit) AS credit,
SUM(ml.balance) AS balance, SUM(ml.balance) AS balance,
c.name as currency_name,
SUM(ml.amount_currency) AS balance_currency
c.id as currency_id,
CASE
WHEN c.id IS NOT NULL
THEN SUM(ml.amount_currency)
ELSE NULL
END AS balance_currency
FROM FROM
accounts_partners ap accounts_partners ap
INNER JOIN account_account ac INNER JOIN account_account ac
ON ac.id = ap.account_id ON ac.id = ap.account_id
LEFT JOIN LEFT JOIN
res_currency c ON ap.account_id = c.id
res_currency c ON ac.currency_id = c.id
INNER JOIN INNER JOIN
account_move_line ml account_move_line ml
ON ap.account_id = ml.account_id ON ap.account_id = ml.account_id
@ -594,7 +600,7 @@ AND
""" """
sub_subquery_sum_amounts += """ sub_subquery_sum_amounts += """
GROUP BY GROUP BY
ap.account_id, ap.partner_id, c.name
ap.account_id, ap.partner_id, c.id
""" """
return sub_subquery_sum_amounts return sub_subquery_sum_amounts
@ -610,7 +616,7 @@ AND
SUM(COALESCE(sub.debit, 0.0)) AS debit, SUM(COALESCE(sub.debit, 0.0)) AS debit,
SUM(COALESCE(sub.credit, 0.0)) AS credit, SUM(COALESCE(sub.credit, 0.0)) AS credit,
SUM(COALESCE(sub.balance, 0.0)) AS balance, SUM(COALESCE(sub.balance, 0.0)) AS balance,
MAX(sub.currency_name) AS currency_name,
MAX(sub.currency_id) AS currency_id,
SUM(COALESCE(sub.balance_currency, 0.0)) AS balance_currency SUM(COALESCE(sub.balance_currency, 0.0)) AS balance_currency
FROM FROM
( (
@ -736,7 +742,7 @@ INSERT INTO
initial_debit, initial_debit,
initial_credit, initial_credit,
initial_balance, initial_balance,
currency_name,
currency_id,
initial_balance_foreign_currency, initial_balance_foreign_currency,
final_debit, final_debit,
final_credit, final_credit,
@ -752,7 +758,7 @@ SELECT
COALESCE(i.debit, 0.0) AS initial_debit, COALESCE(i.debit, 0.0) AS initial_debit,
COALESCE(i.credit, 0.0) AS initial_credit, COALESCE(i.credit, 0.0) AS initial_credit,
COALESCE(i.balance, 0.0) AS initial_balance, COALESCE(i.balance, 0.0) AS initial_balance,
i.currency_name AS currency_name,
i.currency_id AS currency_id,
COALESCE(i.balance_currency, 0.0) AS initial_balance_foreign_currency, COALESCE(i.balance_currency, 0.0) AS initial_balance_foreign_currency,
COALESCE(f.debit, 0.0) AS final_debit, COALESCE(f.debit, 0.0) AS final_debit,
COALESCE(f.credit, 0.0) AS final_credit, COALESCE(f.credit, 0.0) AS final_credit,
@ -900,7 +906,7 @@ INSERT INTO
debit, debit,
credit, credit,
cumul_balance, cumul_balance,
currency_name,
currency_id,
amount_currency amount_currency
) )
SELECT SELECT
@ -989,7 +995,7 @@ SELECT
) AS cumul_balance, ) AS cumul_balance,
""" """
query_inject_move_line += """ query_inject_move_line += """
c.name AS currency_name,
c.id AS currency_id,
ml.amount_currency ml.amount_currency
FROM FROM
""" """
@ -1252,7 +1258,7 @@ SET
ON l.report_account_id = a.id ON l.report_account_id = a.id
WHERE WHERE
a.report_id = %s a.report_id = %s
AND l.currency_name IS NOT NULL
AND l.currency_id IS NOT NULL
LIMIT 1 LIMIT 1
) )
OR OR
@ -1269,7 +1275,7 @@ SET
ON p.report_account_id = a.id ON p.report_account_id = a.id
WHERE WHERE
a.report_id = %s a.report_id = %s
AND l.currency_name IS NOT NULL
AND l.currency_id IS NOT NULL
LIMIT 1 LIMIT 1
) )
WHERE id = %s WHERE id = %s
@ -1391,7 +1397,7 @@ WHERE id = %s
is_partner_account, is_partner_account,
initial_balance, initial_balance,
final_balance, final_balance,
currency_name
currency_id
) )
SELECT SELECT
%(report_id)s AS report_id, %(report_id)s AS report_id,
@ -1403,9 +1409,11 @@ WHERE id = %s
False AS is_partner_account, False AS is_partner_account,
COALESCE(i.initial_balance, 0.0) AS initial_balance, COALESCE(i.initial_balance, 0.0) AS initial_balance,
COALESCE(i.final_balance, 0.0) AS final_balance, COALESCE(i.final_balance, 0.0) AS final_balance,
''
c.id as currency_id
FROM FROM
account_account a,
account_account a
LEFT JOIN
res_currency c ON c.id = a.currency_id,
sum_amounts i sum_amounts i
WHERE WHERE
a.company_id = %(company_id)s a.company_id = %(company_id)s

9
account_financial_report_qweb/report/general_ledger_xlsx.py

@ -54,9 +54,16 @@ class GeneralLedgerXslx(abstract_report_xlsx.AbstractReportXslx):
'field_final_balance': 'final_balance', 'field_final_balance': 'final_balance',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
12: {'header': _('Cur.'), 'field': 'currency_name', 'width': 7},
12: {'header': _('Cur.'),
'field': 'currency_id',
'field_initial_balance': 'currency_id',
'field_final_balance': 'currency_id',
'type': 'many2one',
'width': 7},
13: {'header': _('Amount cur.'), 13: {'header': _('Amount cur.'),
'field': 'amount_currency', 'field': 'amount_currency',
'field_initial_balance': 'initial_balance_foreign_currency',
'field_final_balance': 'final_balance_foreign_currency',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
} }

228
account_financial_report_qweb/report/open_items.py

@ -26,9 +26,6 @@ class OpenItemsReport(models.TransientModel):
filter_account_ids = fields.Many2many(comodel_name='account.account') filter_account_ids = fields.Many2many(comodel_name='account.account')
filter_partner_ids = fields.Many2many(comodel_name='res.partner') filter_partner_ids = fields.Many2many(comodel_name='res.partner')
# Flag fields, used for report display
has_second_currency = fields.Boolean()
# 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_open_items_qweb_account', comodel_name='report_open_items_qweb_account',
@ -56,7 +53,11 @@ class OpenItemsReportAccount(models.TransientModel):
# Data fields, used for report display # Data fields, used for report display
code = fields.Char() code = fields.Char()
name = fields.Char() name = fields.Char()
currency_name = fields.Char()
final_amount_residual = fields.Float(digits=(16, 2)) final_amount_residual = fields.Float(digits=(16, 2))
final_amount_total_due = fields.Float(digits=(16, 2))
final_amount_residual_currency = fields.Float(digits=(16, 2))
final_amount_total_due_currency = fields.Float(digits=(16, 2))
# Data fields, used to browse report data # Data fields, used to browse report data
partner_ids = fields.One2many( partner_ids = fields.One2many(
@ -83,7 +84,11 @@ class OpenItemsReportPartner(models.TransientModel):
# Data fields, used for report display # Data fields, used for report display
name = fields.Char() name = fields.Char()
currency_name = fields.Char()
final_amount_residual = fields.Float(digits=(16, 2)) final_amount_residual = fields.Float(digits=(16, 2))
final_amount_total_due = fields.Float(digits=(16, 2))
final_amount_residual_currency = fields.Float(digits=(16, 2))
final_amount_total_due_currency = fields.Float(digits=(16, 2))
# Data fields, used to browse report data # Data fields, used to browse report data
move_line_ids = fields.One2many( move_line_ids = fields.One2many(
@ -167,8 +172,6 @@ class OpenItemsReportCompute(models.TransientModel):
self._clean_partners_and_accounts( self._clean_partners_and_accounts(
only_delete_account_balance_at_0=True only_delete_account_balance_at_0=True
) )
# Compute display flag
self._compute_has_second_currency()
# Refresh cache because all data are computed with SQL requests # Refresh cache because all data are computed with SQL requests
self.invalidate_cache() self.invalidate_cache()
@ -182,11 +185,14 @@ WITH
a.id, a.id,
a.code, a.code,
a.name, a.name,
a.user_type_id
a.user_type_id,
c.name as currency_name
FROM FROM
account_account a account_account a
INNER JOIN INNER JOIN
account_move_line ml ON a.id = ml.account_id AND ml.date <= %s account_move_line ml ON a.id = ml.account_id AND ml.date <= %s
LEFT JOIN
res_currency c ON a.currency_id = c.id
""" """
if self.filter_partner_ids: if self.filter_partner_ids:
query_inject_account += """ query_inject_account += """
@ -215,7 +221,7 @@ WITH
""" """
query_inject_account += """ query_inject_account += """
GROUP BY GROUP BY
a.id
a.id, c.name
) )
INSERT INTO INSERT INTO
report_open_items_qweb_account report_open_items_qweb_account
@ -224,6 +230,7 @@ INSERT INTO
create_uid, create_uid,
create_date, create_date,
account_id, account_id,
currency_name,
code, code,
name name
) )
@ -232,6 +239,7 @@ SELECT
%s AS create_uid, %s AS create_uid,
NOW() AS create_date, NOW() AS create_date,
a.id AS account_id, a.id AS account_id,
a.currency_name,
a.code, a.code,
a.name a.name
FROM FROM
@ -606,7 +614,25 @@ ORDER BY
""" Compute cumulative amount for """ Compute cumulative amount for
report_open_items_qweb_partner and report_open_items_qweb_account. report_open_items_qweb_partner and report_open_items_qweb_account.
""" """
query_compute_partners_cumul = """
self._compute_partner_cumul()
self._compute_account_cumul()
def _compute_partner_cumul(self):
where_condition_partner_by_account = """
WHERE
id IN
(
SELECT
rp.id
FROM
report_open_items_qweb_account ra
INNER JOIN
report_open_items_qweb_partner rp
ON ra.id = rp.report_account_id
WHERE
ra.report_id = %s
)"""
query_compute_partners_residual_cumul = """
UPDATE UPDATE
report_open_items_qweb_partner report_open_items_qweb_partner
SET SET
@ -619,6 +645,31 @@ SET
WHERE WHERE
rml.report_partner_id = report_open_items_qweb_partner.id rml.report_partner_id = report_open_items_qweb_partner.id
) )
""" + where_condition_partner_by_account
params_compute_partners_residual_cumul = (self.id,)
self.env.cr.execute(query_compute_partners_residual_cumul,
params_compute_partners_residual_cumul)
query_compute_partners_due_cumul = """
UPDATE
report_open_items_qweb_partner
SET
final_amount_total_due =
(
SELECT
SUM(rml.amount_total_due) AS final_amount_total_due
FROM
report_open_items_qweb_move_line rml
WHERE
rml.report_partner_id = report_open_items_qweb_partner.id
)
""" + where_condition_partner_by_account
params_compute_partners_due_cumul = (self.id,)
self.env.cr.execute(query_compute_partners_due_cumul,
params_compute_partners_due_cumul)
# Manage currency in partner
where_condition_partner_by_account_cur = """
WHERE WHERE
id IN id IN
( (
@ -630,13 +681,66 @@ WHERE
report_open_items_qweb_partner rp report_open_items_qweb_partner rp
ON ra.id = rp.report_account_id ON ra.id = rp.report_account_id
WHERE WHERE
ra.report_id = %s
ra.report_id = %s AND ra.currency_name IS NOT NULL
)"""
query_compute_partners_cur_name_cumul = """
UPDATE
report_open_items_qweb_partner
SET
currency_name =
(
SELECT
MAX(currency_name) as currency_name
FROM
report_open_items_qweb_move_line rml
WHERE
rml.report_partner_id = report_open_items_qweb_partner.id
) )
"""
params_compute_partners_cumul = (self.id,)
self.env.cr.execute(query_compute_partners_cumul,
params_compute_partners_cumul)
query_compute_accounts_cumul = """
""" + where_condition_partner_by_account_cur
params_compute_partners_cur_name_cumul = (self.id,)
self.env.cr.execute(query_compute_partners_cur_name_cumul,
params_compute_partners_cur_name_cumul)
query_compute_partners_cur_residual_cumul = """
UPDATE
report_open_items_qweb_partner
SET
final_amount_residual_currency =
(
SELECT
SUM(rml.amount_residual_currency)
AS final_amount_residual_currency
FROM
report_open_items_qweb_move_line rml
WHERE
rml.report_partner_id = report_open_items_qweb_partner.id
)
""" + where_condition_partner_by_account_cur
params_compute_partners_cur_residual_cumul = (self.id,)
self.env.cr.execute(query_compute_partners_cur_residual_cumul,
params_compute_partners_cur_residual_cumul)
query_compute_partners_cur_due_cumul = """
UPDATE
report_open_items_qweb_partner
SET
final_amount_total_due_currency =
(
SELECT
SUM(rml.amount_total_due_currency)
AS final_amount_total_due_currency
FROM
report_open_items_qweb_move_line rml
WHERE
rml.report_partner_id = report_open_items_qweb_partner.id
)
""" + where_condition_partner_by_account_cur
params_compute_partners_cur_due_cumul = (self.id,)
self.env.cr.execute(query_compute_partners_cur_due_cumul,
params_compute_partners_cur_due_cumul)
def _compute_account_cumul(self):
query_compute_accounts_residual_cumul = """
UPDATE UPDATE
report_open_items_qweb_account report_open_items_qweb_account
SET SET
@ -652,9 +756,71 @@ SET
WHERE WHERE
report_id = %s report_id = %s
""" """
params_compute_accounts_cumul = (self.id,)
self.env.cr.execute(query_compute_accounts_cumul,
params_compute_accounts_cumul)
params_compute_accounts_residual_cumul = (self.id,)
self.env.cr.execute(query_compute_accounts_residual_cumul,
params_compute_accounts_residual_cumul)
query_compute_accounts_cur_residual_cumul = """
UPDATE
report_open_items_qweb_account
SET
final_amount_residual_currency =
(
SELECT
SUM(rp.final_amount_residual_currency)
AS final_amount_residual_currency
FROM
report_open_items_qweb_partner rp
WHERE
rp.report_account_id = report_open_items_qweb_account.id
)
WHERE
report_id = %s
"""
params_compute_accounts_cur_residual_cumul = (self.id,)
self.env.cr.execute(query_compute_accounts_cur_residual_cumul,
params_compute_accounts_cur_residual_cumul)
query_compute_accounts_due_cumul = """
UPDATE
report_open_items_qweb_account
SET
final_amount_total_due =
(
SELECT
SUM(rp.final_amount_total_due) AS final_amount_total_due
FROM
report_open_items_qweb_partner rp
WHERE
rp.report_account_id = report_open_items_qweb_account.id
)
WHERE
report_id = %s
"""
params_compute_accounts_due_cumul = (self.id,)
self.env.cr.execute(query_compute_accounts_due_cumul,
params_compute_accounts_due_cumul)
query_compute_accounts_cur_due_cumul = """
UPDATE
report_open_items_qweb_account
SET
final_amount_total_due_currency =
(
SELECT
SUM(rp.final_amount_total_due_currency)
AS final_amount_total_due_currency
FROM
report_open_items_qweb_partner rp
WHERE
rp.report_account_id = report_open_items_qweb_account.id
)
WHERE
report_id = %s
"""
params_compute_accounts_cur_due_cumul = (self.id,)
self.env.cr.execute(query_compute_accounts_cur_due_cumul,
params_compute_accounts_cur_due_cumul)
def _clean_partners_and_accounts(self, def _clean_partners_and_accounts(self,
only_delete_account_balance_at_0=False): only_delete_account_balance_at_0=False):
@ -731,31 +897,3 @@ WHERE
""" """
params_clean_accounts = (self.id,) params_clean_accounts = (self.id,)
self.env.cr.execute(query_clean_accounts, params_clean_accounts) self.env.cr.execute(query_clean_accounts, params_clean_accounts)
def _compute_has_second_currency(self):
""" Compute "has_second_currency" flag which will used for display."""
query_update_has_second_currency = """
UPDATE
report_open_items_qweb
SET
has_second_currency =
(
SELECT
TRUE
FROM
report_open_items_qweb_move_line l
INNER JOIN
report_open_items_qweb_partner p
ON l.report_partner_id = p.id
INNER JOIN
report_open_items_qweb_account a
ON p.report_account_id = a.id
WHERE
a.report_id = %s
AND l.currency_name IS NOT NULL
LIMIT 1
)
WHERE id = %s
"""
params = (self.id,) * 2
self.env.cr.execute(query_update_has_second_currency, params)

8
account_financial_report_qweb/report/open_items_xlsx.py

@ -29,6 +29,7 @@ class OpenItemsXslx(abstract_report_xlsx.AbstractReportXslx):
6: {'header': _('Due date'), 'field': 'date_due', 'width': 11}, 6: {'header': _('Due date'), 'field': 'date_due', 'width': 11},
7: {'header': _('Original'), 7: {'header': _('Original'),
'field': 'amount_total_due', 'field': 'amount_total_due',
'field_final_balance': 'final_amount_total_due',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
8: {'header': _('Residual'), 8: {'header': _('Residual'),
@ -36,13 +37,18 @@ class OpenItemsXslx(abstract_report_xlsx.AbstractReportXslx):
'field_final_balance': 'final_amount_residual', 'field_final_balance': 'final_amount_residual',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
9: {'header': _('Cur.'), 'field': 'currency_name', 'width': 7},
9: {'header': _('Cur.'),
'field': 'currency_name',
'field_final_balance': 'currency_name',
'width': 7},
10: {'header': _('Cur. Original'), 10: {'header': _('Cur. Original'),
'field': 'amount_total_due_currency', 'field': 'amount_total_due_currency',
'field_final_balance': 'final_amount_total_due_currency',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
11: {'header': _('Cur. Residual'), 11: {'header': _('Cur. Residual'),
'field': 'amount_residual_currency', 'field': 'amount_residual_currency',
'field_final_balance': 'final_amount_residual_currency',
'type': 'amount', 'type': 'amount',
'width': 14}, 'width': 14},
} }

18
account_financial_report_qweb/report/templates/general_ledger.xml

@ -164,12 +164,12 @@
<!--## balance cumulated--> <!--## balance cumulated-->
<div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance"/></div> <div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance"/></div>
<!--## currency_name--> <!--## currency_name-->
<div class="act_as_cell"><span t-field="account_or_partner_object.currency_name"/></div>
<t t-if="account_or_partner_object.currency_name">
<div class="act_as_cell"><span t-field="account_or_partner_object.currency_id.name"/></div>
<t t-if="account_or_partner_object.currency_id">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance_foreign_currency"/></div> <div class="act_as_cell amount"><span t-field="account_or_partner_object.initial_balance_foreign_currency"/></div>
</t> </t>
<t t-if="not account_or_partner_object.currency_name">
<t t-if="not account_or_partner_object.currency_id">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell"></div> <div class="act_as_cell"></div>
</t> </t>
@ -206,12 +206,12 @@
<!--## balance cumulated--> <!--## balance cumulated-->
<div class="act_as_cell amount"><span t-field="line.cumul_balance"/></div> <div class="act_as_cell amount"><span t-field="line.cumul_balance"/></div>
<!--## currency_name--> <!--## currency_name-->
<div class="act_as_cell"><span t-field="line.currency_name"/></div>
<t t-if="line.currency_name">
<div class="act_as_cell"><span t-field="line.currency_id.name"/></div>
<t t-if="line.currency_id">
<!--## amount_currency--> <!--## amount_currency-->
<div class="act_as_cell amount"><span t-field="line.amount_currency"/></div> <div class="act_as_cell amount"><span t-field="line.amount_currency"/></div>
</t> </t>
<t t-if="not line.currency_name">
<t t-if="not line.currency_id">
<!--## amount_currency--> <!--## amount_currency-->
<div class="act_as_cell"></div> <div class="act_as_cell"></div>
</t> </t>
@ -246,12 +246,12 @@
<!--## balance cumulated--> <!--## balance cumulated-->
<div class="act_as_cell amount" style="width: 75px; padding-right: 1px;"><span t-field="account_or_partner_object.final_balance"/></div> <div class="act_as_cell amount" style="width: 75px; padding-right: 1px;"><span t-field="account_or_partner_object.final_balance"/></div>
<!--## currency_name--> <!--## currency_name-->
<div class="act_as_cell" style="width: 35px;"><span t-field="account_or_partner_object.currency_name"/></div>
<t t-if="account_or_partner_object.currency_name">
<div class="act_as_cell" style="width: 35px;"><span t-field="account_or_partner_object.currency_id.name"/></div>
<t t-if="account_or_partner_object.currency_id">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_balance_foreign_currency"/></div> <div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_balance_foreign_currency"/></div>
</t> </t>
<t t-if="not account_or_partner_object.currency_name">
<t t-if="not account_or_partner_object.currency_id">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell" style="width: 75px;"/> <div class="act_as_cell" style="width: 75px;"/>
</t> </t>

14
account_financial_report_qweb/report/templates/open_items.xml

@ -4,8 +4,6 @@
<template id="account_financial_report_qweb.report_open_items_qweb"> <template id="account_financial_report_qweb.report_open_items_qweb">
<t t-call="report.html_container"> <t t-call="report.html_container">
<t t-foreach="docs" t-as="o"> <t t-foreach="docs" t-as="o">
<!-- Saved flag fields into variables, used to define columns display -->
<t t-set="has_second_currency" t-value="o.has_second_currency"/>
<t t-call="account_financial_report_qweb.internal_layout"> <t t-call="account_financial_report_qweb.internal_layout">
<!-- Defines global variables used by internal layout --> <!-- Defines global variables used by internal layout -->
@ -169,11 +167,21 @@
<!--## date_due--> <!--## date_due-->
<div class="act_as_cell" style="width: 60px;"></div> <div class="act_as_cell" style="width: 60px;"></div>
<!--## amount_total_due--> <!--## amount_total_due-->
<div class="act_as_cell amount" style="width: 75px;"></div>
<div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_amount_total_due"/></div>
<!--## amount_currency--> <!--## amount_currency-->
<div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_amount_residual"/></div> <div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_amount_residual"/></div>
<t t-if="account_or_partner_object.currency_name">
<!--## currency_name-->
<div class="act_as_cell" style="width: 35px;"><span t-field="account_or_partner_object.currency_name"/></div>
<!--## amount_total_due_currency-->
<div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_amount_total_due_currency"/></div>
<!--## amount_residual_currency-->
<div class="act_as_cell amount" style="width: 75px;"><span t-field="account_or_partner_object.final_amount_residual_currency"/></div>
</t>
<t t-if="not account_or_partner_object.currency_name">
<!--## currency_name + amount_total_due_currency + amount_residual_currency --> <!--## currency_name + amount_total_due_currency + amount_residual_currency -->
<div class="act_as_cell" style="width: 185px;"></div> <div class="act_as_cell" style="width: 185px;"></div>
</t>
</div> </div>
</div> </div>
</template> </template>

6
account_financial_report_qweb/report/templates/trial_balance.xml

@ -136,14 +136,14 @@
<!--## Ending balance--> <!--## Ending balance-->
<div class="act_as_cell amount"><span t-field="line.final_balance"/></div> <div class="act_as_cell amount"><span t-field="line.final_balance"/></div>
<!--## currency_name--> <!--## currency_name-->
<div class="act_as_cell"><span t-field="line.currency_name"/></div>
<t t-if="line.currency_name">
<div class="act_as_cell"><span t-field="line.currency_id.name"/></div>
<t t-if="line.currency_id">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell amount"><span t-field="line.initial_balance_foreign_currency"/></div> <div class="act_as_cell amount"><span t-field="line.initial_balance_foreign_currency"/></div>
<div class="act_as_cell amount"><span <div class="act_as_cell amount"><span
t-field="line.final_balance_foreign_currency"/></div> t-field="line.final_balance_foreign_currency"/></div>
</t> </t>
<t t-if="not line.currency_name">
<t t-if="not line.currency_id">
<!--## balance_currency--> <!--## balance_currency-->
<div class="act_as_cell"/> <div class="act_as_cell"/>
<div class="act_as_cell"/> <div class="act_as_cell"/>

12
account_financial_report_qweb/report/trial_balance.py

@ -67,7 +67,7 @@ class TrialBalanceReportAccount(models.TransientModel):
initial_balance_foreign_currency = fields.Float(digits=(16, 2)) initial_balance_foreign_currency = fields.Float(digits=(16, 2))
debit = fields.Float(digits=(16, 2)) debit = fields.Float(digits=(16, 2))
credit = fields.Float(digits=(16, 2)) credit = fields.Float(digits=(16, 2))
currency_name = fields.Char()
currency_id = fields.Many2one(comodel_name='res.currency')
final_balance = fields.Float(digits=(16, 2)) final_balance = fields.Float(digits=(16, 2))
final_balance_foreign_currency = fields.Float(digits=(16, 2)) final_balance_foreign_currency = fields.Float(digits=(16, 2))
@ -100,7 +100,7 @@ class TrialBalanceReportPartner(models.TransientModel):
initial_balance = fields.Float(digits=(16, 2)) initial_balance = fields.Float(digits=(16, 2))
debit = fields.Float(digits=(16, 2)) debit = fields.Float(digits=(16, 2))
credit = fields.Float(digits=(16, 2)) credit = fields.Float(digits=(16, 2))
currency_name = fields.Char()
currency_id = fields.Many2one(comodel_name='res.currency')
final_balance = fields.Float(digits=(16, 2)) final_balance = fields.Float(digits=(16, 2))
@api.model @api.model
@ -187,7 +187,7 @@ INSERT INTO
debit, debit,
credit, credit,
final_balance, final_balance,
currency_name,
currency_id,
initial_balance_foreign_currency, initial_balance_foreign_currency,
final_balance_foreign_currency final_balance_foreign_currency
) )
@ -202,7 +202,7 @@ SELECT
rag.final_debit - rag.initial_debit AS debit, rag.final_debit - rag.initial_debit AS debit,
rag.final_credit - rag.initial_credit AS credit, rag.final_credit - rag.initial_credit AS credit,
rag.final_balance AS final_balance, rag.final_balance AS final_balance,
rag.currency_name AS currency_name,
rag.currency_id,
rag.initial_balance_foreign_currency AS initial_balance_foreign_currency, rag.initial_balance_foreign_currency AS initial_balance_foreign_currency,
rag.final_balance_foreign_currency AS final_balance_foreign_currency rag.final_balance_foreign_currency AS final_balance_foreign_currency
FROM FROM
@ -232,7 +232,7 @@ INSERT INTO
debit, debit,
credit, credit,
final_balance, final_balance,
currency_name
currency_id
) )
SELECT SELECT
ra.id AS report_account_id, ra.id AS report_account_id,
@ -244,7 +244,7 @@ SELECT
rpg.final_debit - rpg.initial_debit AS debit, rpg.final_debit - rpg.initial_debit AS debit,
rpg.final_credit - rpg.initial_credit AS credit, rpg.final_credit - rpg.initial_credit AS credit,
rpg.final_balance AS final_balance, rpg.final_balance AS final_balance,
rpg.currency_name AS currency_name
rpg.currency_id
FROM FROM
report_general_ledger_qweb_partner rpg report_general_ledger_qweb_partner rpg
INNER JOIN INNER JOIN

Loading…
Cancel
Save