如何从另一个模型获取sale.order的amount_total值?

时间:2015-08-24 14:26:31

标签: python python-2.7 odoo-8 odoo

我不知道如何获取当前amount_total的值以将其转换为myfunction,请帮助我。

from openerp.osv import fields, osv
import conver

class sale_total_extend(osv.Model):
   _inherit='sale.order'
   _name='sale.order'
   _description="le modele ajoute le total d'un devis en lettres"

def _amount_all_text(self, cr, uid, ids, field_name, arg, context=None):
    res = {}
    for order in self.browse(cr, uid, ids, context=context):
        res[order.id] = conver.myfunction(order.amount_total)
    return {}

_columns = {
    'amount_total_text': fields.function(_amount_all_text, string='total en lettres', type='text',store=True, multi='sums', help="Total en lettres"),
}

1 个答案:

答案 0 :(得分:1)

要覆盖函数_amount_all,请尝试类似下面的代码(此示例位于website_sale_delivery模块中):

class SaleOrder(orm.Model):
    _inherit = 'sale.order'

    def _amount_all_wrapper(self, cr, uid, ids, field_name, arg, context=None):        
        """ Wrapper because of direct method passing as parameter for function fields """
        return self._amount_all(cr, uid, ids, field_name, arg, context=context)

    def _amount_all(self, cr, uid, ids, field_name, arg, context=None):
        res = super(SaleOrder, self)._amount_all(cr, uid, ids, field_name, arg, context=context)
        currency_pool = self.pool.get('res.currency')
        for order in self.browse(cr, uid, ids, context=context):
            line_amount = sum([line.price_subtotal for line in order.order_line if line.is_delivery])
            currency = order.pricelist_id.currency_id
            res[order.id]['amount_delivery'] = currency_pool.round(cr, uid, currency, line_amount)
        return res