将产品条码添加到 Odoo excel 报告时出错
error when add product barcode to Odoo excel report
尝试将产品条码添加到 Odoo excel 报告但未成功,如下所示:
aml.product_id.barcode AS product_barcode
你能帮忙看看代码哪里出错了吗?
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()
我们根本无法在查询中使用两个级别的字段值。首先,我们需要为产品 table 添加 LEFT JOIN,然后访问 'barcode' 值。例如,
左连接:
LEFT JOIN product_product variant ON (variant.id = aml.product_id)
访问值:
variant.barcode AS product_barcode,
尝试将产品条码添加到 Odoo excel 报告但未成功,如下所示:
aml.product_id.barcode AS product_barcode
你能帮忙看看代码哪里出错了吗?
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()
我们根本无法在查询中使用两个级别的字段值。首先,我们需要为产品 table 添加 LEFT JOIN,然后访问 'barcode' 值。例如,
左连接:
LEFT JOIN product_product variant ON (variant.id = aml.product_id)
访问值:
variant.barcode AS product_barcode,