odoo 8与型号不同.模型到osv.osv

  • 本文关键字:osv 模型 odoo odoo odoo-8
  • 更新时间 :
  • 英文 :


在我的odoo 8 itu中使用两种类,模型。Model和osv.osv,我需要它来更改表单模型。模型到osv.osv

class purchase_extend2(models.Model):
_inherit = 'purchase.order'
allowed_credit = fields.Float(string="Customer Debt", compute="_get_allowed_credit", )
@api.one
@api.depends('customer_id')
def _get_allowed_credit(self):
invoice_pool = self.env['account.invoice']
confirmed_so_objs = invoice_pool.search([('state', '=', 'open'), ('partner_id', '=', self.customer_id.id)])
self.allowed_credit = sum([so.amount_total for so in confirmed_so_objs])

如何把它改成这个班?

class purchase_extend2(osv.osv):

谢谢

您需要使用一个功能字段

示例:

from openerp.osv import osv, fields

class PurchaseOrderExtend(osv.osv):
_inherit = 'purchase.order'
def _get_allowed_credit(self, cr, uid, ids, field_name, arg, context):
res = {}
invoice_pool = self.pool.get('account.invoice')
for order in self.browse(cr, uid, ids, context=context):
confirmed_so_objs = invoice_pool.search_read(cr, uid, [('state', '=', 'open'), ('partner_id', '=', order.partner_id.id)], ['amount_total'])
res[order.id] = {'allowed_credit': sum(so['amount_total'] for so in confirmed_so_objs)}
return res
_columns = {
'allowed_credit': fields.function(_get_allowed_credit, type="float", string="Customer Debt", multi='_get_allowed_credit')
}

要使用异常,请使用以下导入:

from openerp.exceptions import Warning

相关内容

  • 没有找到相关文章

最新更新