【问题标题】:odoo 10 custom report ..sum lines qty..by product_idodoo 10 自定义报告 ..sum 行 qty..by product_id
【发布时间】:2018-11-15 08:27:37
【问题描述】:

odoo 10 报告...问题... 为什么 get_qty 不能向 docargs 发送数据? 我想要行数据...数量总和...按 product_id 相同... 为什么 xml t-foreach="data" 可以为我获取任何数据

class ReportStockInventorySummary(models.AbstractModel):
            _name = 'report.stock.inventory.summary'

            def get_qty(self, docids):
                docs = self.env["stock.inventory"].browse(docids)
                lines = self.env["stock.inventory.line"].search([('inventory_id', '=', docs.id)])
                data = list()
                show_data = list()
                for x in lines:
                    data.append({
                        "line_location_id": x.location_id,
                        "line_product_id": x.product_id,
                        "line_product_qty": x.product_qty,
                    })

                for i, g in groupby(sorted(data), key=lambda x: x['line_product_id']):
                    show_data.append([i, sum(v['line_product_qty'] for v in g)])

            @api.multi
            def render_html(self, docids, data):
                report = self.env['report']
                self.model = self.env.context.get('active_model')
                docs = self.env["stock.inventory"].browse(docids)


                docargs = {
                    'doc_ids': docids,
                    'doc_model': self.model,
                    'docs': docs,
                    'data': self.get_qty //* i want sum product_qty by product_id *//
                }
                return report.render("stock_inventory_report.report_stock_inventory_template", docargs)

            <?xml version="1.0"?>
        <odoo>
            <data>
                <template id="report_stock_inventory_template">
                    <t t-call="report.html_container">
                        <t t-foreach="docs" t-as="o">
                            <div class="page">
                                <h2>Report title</h2>
                                <p>This object's name is
                                    <span t-field="o.name"/>
                                </p>
                                <table class="table table-condensed">
                                        <thead>
                                            <tr>
                                                <th><strong>Location</strong></th>
                                                <th><strong>Product</strong></th>
                                                <th class="text-right"><strong>Quantity</strong></th>
                                            </tr>
                                        </thead>
    <!---- why t-foreach="data" cant show any data for me -->
                                        <tr t-foreach="data" t-as="line">
                                            <td><span t-esc="line['line_location_id']" /></td>
                                            <td><span t-esc="line['line_product_id']" /></td>
                                            <td><span t-esc="line['line_product_qty']" /></td>
                                        </tr>


                                        <tr>
                                            <td></td>
                                        </tr>
                                    </table>
                            </div>
                        </t>
                    </t>
                </template>
            </data>
        </odoo>

我想从 qweb 中的 stock.inventory.lines 显示数据和字段(location_id、product_id、product_qty)我需要在上面的 py 中更改什么以及如何创建视图? 初学者有类似的例子吗?

【问题讨论】:

    标签: python odoo odoo-10


    【解决方案1】:

    您将方法 get_qty 绑定到 data,但您应该调用它。

    'data': self.get_qty(doc_ids)

    最好不要使用data 键,因为它已经被另一个进程使用了​​。只需制作自己的密钥并在报告模板中使用它而不是数据:

    'get_qty': self.get_qty(doc_ids)

    你的方法没有返回任何东西。 None。我认为show_data 是您的返回结果,所以只需返回它。

    def get_qty(self, docids):
        show_data = []
        # ...
        return show_data
    

    【讨论】:

    • 谢谢....我已经尝试过 'data': show_data ...但是...结果是 None..只有文档数据显示在我的 pdf 数据中
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-05
    • 2021-06-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多