Skip to Content
Menu
This question has been flagged
1 Reply
3322 Views

Hello good morning, some member who is a developer in Odoo who knows about reports based on custom SQL reports, I am making a query from python to the account_move_line table and it throws me this error TypeError: not all arguments converted during string formatting

code snippet:

def _inject_move_line(self):
""" Inject report values for report_trial_balance_move_line.
"""
query_inject_move_line = """
INSERT INTO
report_trial_balance_move_line
(
report_account_id,
create_uid,
create_date,
date,
account,
journal,
partner,
label,
debit,
credit,
cumul_balance
currency_id,
amount_currency
)
SELECT
ra.id AS report_account_id,
%s AS create_uid,
NOW() AS create_date,
ml.date,
a.code AS account,
j.code AS journal,
p.name AS partner,
ml.debit AS debit,
ml.credit AS credit,
ra.initial_balance + (
SUM(ml.balance)
OVER (PARTITION BY a.code ORDER BY ml.date)
) AS cumul_balance
c.id AS currency_id,
ml.amount_currency
FROM
report_general_ledger_account ra
INNER JOIN
move_lines ml ON ra.account_id = ml.account_id
INNER JOIN
account_account a ON ml.account_id = a.id
INNER JOIN
account_journal j ON ml.journal_id = j.id
LEFT JOIN
res_currency c ON ml.currency_id = c.id
WHERE
ra.report_id = %s
AND
j.id in %s
ORDER BY
a.code, ml.date
"""
query_inject_move_line_params = (
self.id,
self.date_from,
self.date_to,
self.env.uid,
self.id,
)
self.env.cr.execute(
query_inject_move_line,
query_inject_move_line_params
)


Avatar
Discard

i think some of your %s sign must be in '%s'

Best Answer

There is a mismatching between the strings to be formatted in your query and parameters (3 of %s Vs 5 params) You probably don't need these two: self.date_from, self.date_to.

Try it like this:

query_inject_move_line = """ INSERT INTO report_trial_balance_move_line (report_account_id, create_uid, create_date, date, account, journal, partner, label, debit, credit, cumul_balance, currency_id, amount_currency )
SELECT ra.id AS report_account_id, %s AS create_uid, NOW() AS create_date, ml.date, a.code AS account, j.code AS journal,p.name AS partner, ml.debit AS debit, ml.credit AS credit, ra.initial_balance + (SUM(ml.balance) OVER (PARTITION BY a.code ORDER BY ml.date)) AS cumul_balance, c.id AS currency_id, ml.amount_currency
FROM report_general_ledger_account ra
INNER JOIN move_lines ml ON ra.account_id = ml.account_id
INNER JOIN account_account a ON ml.account_id = a.id
INNER JOIN account_journal j ON ml.journal_id = j.id
LEFT JOIN res_currency c ON ml.currency_id = c.id
WHERE ra.report_id = %s AND j.id in %s
"""
query_inject_move_line_params = (self._uid, self.id, self.id)

Avatar
Discard
Related Posts Replies Views Activity
1
Nov 22
1982
1
Oct 21
1855
0
Jul 19
3318
1
Dec 18
3010
2
Nov 18
8791