error when add product barcode to Odoo excel report

Viewed 44

trying to add product barcode to Odoo excel report but not successful as it is shown below in this line:

aml.product_id.barcode AS product_barcode

could you please help where's the wrong section in the code?

    def _sql_get_line_for_report(self, type_l, report_object=None):
        self.env['account.move.line'].check_access_rights('read')
        query = """SELECT
                    raml.report_object_id AS report_object_id,
                    raml.view_type AS view_type,
                    CASE
                        WHEN %s = 'account' THEN acc.code
                        WHEN %s = 'journal' THEN acj.code
                        WHEN %s = 'analytic' THEN an_acc.code
                        ELSE rep.ref
                    END AS code,
                    CASE
                        WHEN %s = 'account' THEN acc.name
                        WHEN %s = 'journal' THEN acj.name
                        WHEN %s = 'analytic' THEN an_acc.name
                        ELSE rep.name
                    END AS name,
                    acj.code AS j_code,
                    ml.name AS move_name,
                    aml.ref AS displayed_ref,
                    aml.quantity AS product_qty,
                    aml.product_id.barcode AS product_barcode,
                    CASE
                        WHEN raml.full_reconcile_id IS NOT NULL THEN (CASE WHEN raml.reconciled = TRUE THEN afr.name ELSE '*' END)
                        ELSE ''
                    END AS matching_number
                FROM
                    account_report_standard_ledger_line raml
                    LEFT JOIN account_account acc ON (acc.id = raml.account_id)
                    LEFT JOIN account_journal acj ON (acj.id = raml.journal_id)
                    LEFT JOIN res_partner rep ON (rep.id = raml.partner_id)
                    LEFT JOIN account_move ml ON (ml.id = raml.move_id)
                    LEFT JOIN account_move_line aml ON (aml.id = raml.move_line_id)
                WHERE
                    raml.report_id = %s
                    AND (%s OR raml.report_object_id = %s)
                    AND raml.line_type IN %s
                ORDER BY
                    raml.id
                """
        params = [
            self.report_type, self.report_type, self.report_type, self.report_type, self.report_type, self.report_type,
            self.report_id.id,
            True if report_object is None else False,
            report_object,
            type_l
        ]

        self.env.cr.execute(query, tuple(params))
        return self.env.cr.dictfetchall()
1 Answers

We simply can not use two level field values inside a query. First, we need to add LEFT JOIN for the product table and then access 'barcode' value. For example,

LEFT JOIN:

LEFT JOIN product_product variant ON (variant.id = aml.product_id)

Access value:

variant.barcode AS product_barcode,
Related