1

我使用了命令 fetchall()

cr.execute('select a.name, a.state, a.amount_total, a.date_confirm, b.product_uom_qty from sale_order a, sale_order_line b where a.id = b.order_id')
temp = cr.fetchall()

所以它需要表 SO 中的所有 SO,我想在这里填写所有结果:

class sales_items_line(osv.osv_memory):
_name = "sales.items.line"
_description = "Sales Items Line"
_columns = {
    'name': fields.char('Name', size=64),
    'qty': fields.char('Quantity', size=64),
    'date': fields.date('Date', required=True),
    'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
    'draft_assigned': fields.boolean('Select'),
    'sale_items_id': fields.many2one('add.sales.items', 'Deposit Items ID'),
}

但如何?请帮帮我..., cr.execute 是不同的类

4

1 回答 1

3


您必须覆盖 default_get() 方法并填写您的列。
这是代码:

def default_get(self, cr, uid, fields, context=None):
    fields = super(sales_items_line, self).default_get(cr, uid, fields, context=context)
    cr.execute('select a.name as "name", a.state as "state", a.amount_total as "total", a.date_confirm as "date", b.product_uom_qty as "qty" from sale_order a, sale_order_line b where a.id = b.order_id')
    data = cr.dictfetchall()
    for rec in data:
        fields['name'] = rec.get('name', '')
        fields['qty'] = rec.get('qty', 0.00)
        fields['amount'] = rec.get('total', 0.00)
    return data

希望这能解决您的问题。
谢谢你。

于 2012-09-09T04:43:30.517 回答