Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
427 views
in Technique[技术] by (71.8m points)

python 3.x - missing FROM-clause entry for table "account"

hi am working on odoo 11 accounting and am trying to devlop consolidate trial balance in multi company this is my sql code that show my trial balance with all account

     query_inject_account = """
INSERT INTO
    l10n_ro_report_trial_balance_account
    (
    report_id,
    create_uid,
    create_date,
    account_id,
    code,
    name,
    debit_opening,
    credit_opening,
    debit_initial,
    credit_initial,
    debit,
    credit,
    debit_total,
    credit_total,
    debit_balance,
    credit_balance)

SELECT
    %s AS report_id,
    %s AS create_uid,
    NOW() AS create_date,
    accounts.*,
    CASE WHEN accounts.debit_total > accounts.credit_total
        THEN accounts.debit_total - accounts.credit_total
        ELSE 0
    END AS debit_balance,
    CASE WHEN accounts.credit_total > accounts.debit_total
        THEN accounts.credit_total - accounts.debit_total
        ELSE 0
    END AS credit_balance,
    SUM(accounts.debit_total) as total1,
    SUM(accounts.credit_total) as total2
FROM
    (
    SELECT
        acc.id, acc.code, acc.name,
        coalesce(sum(open.debit),0) AS debit_opening,
        coalesce(sum(open.credit),0) AS credit_opening,
        coalesce(sum(init.debit),0) AS debit_initial,
        coalesce(sum(init.credit),0) AS credit_initial,
        coalesce(sum(current.debit),0) AS debit,
        coalesce(sum(current.credit),0) AS credit,
        coalesce(sum(open.debit),0) + coalesce(sum(init.debit),0) +
            coalesce(sum(current.debit),0) AS debit_total,
        coalesce(sum(open.credit),0) + coalesce(sum(init.credit),0) +
            coalesce(sum(current.credit),0) AS credit_total
    FROM
        account_account acc
        LEFT OUTER JOIN account_move_line AS open
            ON open.account_id = acc.id AND open.date < %s
        LEFT OUTER JOIN account_move_line AS init
            ON init.account_id = acc.id AND init.date >= %s AND init.date < %s
        LEFT OUTER JOIN account_move_line AS current
            ON current.account_id = acc.id AND current.date >= %s
                AND current.date <= %s
        LEFT JOIN account_move AS move
            ON open.move_id = move.id AND move.state in (%s)
        LEFT JOIN account_move AS init_move
            ON init.move_id = init_move.id AND init_move.state in (%s)
        LEFT JOIN account_move AS current_move
            ON current.move_id = current_move.id AND current_move.state in (%s)
    WHERE acc.id in %s
    GROUP BY acc.id,acc.code,accounts.*
    ORDER BY acc.id) as accounts"""

this code make me to sum debit, credit of account and i want to sum the total of each result and i got this error can anyone help me, please


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...