如何在default_get上使用新API?

时间:2016-11-24 10:23:08

标签: python api odoo-10

我想将以下代码转换为新的API。

from odoo import api, fields, models
...

def default_get(self, cr, uid, fields, context=None):
    product_pricelist = self.pool.get('product.pricelist')
    if context is None:
        context = {}
    res = super(back_to_back_order, self).default_get(cr, uid, fields, context=context)
    order = self.pool.get('sale.order').browse(cr, uid, context['active_id'], context=context)
    items = [(6, 0, [])]
    date_order = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
    for line in order.order_line:

        price = 0.0
        if 'pricelist_id' in res:
            if res['pricelist_id']:
                date_order_str = datetime.strptime(date_order, DEFAULT_SERVER_DATETIME_FORMAT).strftime(DEFAULT_SERVER_DATE_FORMAT)
                price = product_pricelist.price_get(cr, uid, [res['pricelist_id']],
                        line.product_id.id, line.product_uom_qty or 1.0, line.partner_id.id or False, {'uom': line.product_id.uom_po_id.id, 'date': date_order_str})[res['pricelist_id']]
            else:
                price = line.product_id.standard_price
        else:
            price = line.product_id.standard_price


        item = 0,0,{
                'product_id': line.product_id.id,
                'qty': line.product_uom_qty,
                'price': price,
                'subtotal': price * line.product_uom_qty
            }
        if line.product_id:
            items.append(item)


    res.update(line_ids=items)
    return res

1 个答案:

答案 0 :(得分:0)

from odoo import api, fields, model

@api.model
def default_get(self, fields):
    return super(MailMail, self).default_get(fields)

通过这种方式转换你的功能。

希望得到这个帮助。