在 sale.py 中覆盖 _prepare_invoice(self, cr, uid, order, lines, context=None)

override _prepare_invoice(self, cr, uid, order, lines, context=None) in sale.py

我需要重写 sale.py 中的内置方法 _prepare_invoice。

但我收到此错误

ValueError: "'builtin_function_or_method' object is not iterable" while evaluating
u'action_invoice_create()'

我需要覆盖创建新发票的方法。

 File "/home/cybrosys/Desktop/odoo-8.0-20150624/addons/Ship/Ship.py", line 104, in _prepare_invoice
    sal_rec = self.browse(cr,uid,id,context=context)
  File "/home/cybrosys/Desktop/odoo-8.0-20150624/openerp/api.py", line 241, in wrapper
    return old_api(self, *args, **kwargs)
  File "/home/cybrosys/Desktop/odoo-8.0-20150624/openerp/models.py", line 5222, in browse
    ids = _normalize_ids(arg)
  File "/home/cybrosys/Desktop/odoo-8.0-20150624/openerp/models.py", line 6090, in _normalize_ids
    return tuple(arg)

下面的方法根据API调用的不同覆盖不同的方式

对于 OpenERP 7.0

from openerp.osv import fields, osv
class sale_order(osv.osv):
    _inherit = 'sale.order'

    def _prepare_invoice(self, cr, uid, order, lines, context=None):
        res=super(sale_order, self)._prepare_invoice(cr, uid, order, lines, context=context)
        res.update({'delivery_note': order.partner_id.picking_warn_msg})
        return res

对于 Odoo 8.0 或更高版本

如果您在 Odoo 中使用新的 API,那么您应该遵循以下方式

from openerp import models, fields, api, _
class sale_order(models.Model)
   _inherit = 'sale.order'
   @api.v7
   def _prepare_invoice(self, cr, uid, order, lines, context=None):
        res=super(sale_order, self)._prepare_invoice(cr, uid, order, lines, context=context)
        res.update({'delivery_note': order.partner_id.picking_warn_msg})
        return res

希望我的回答对您有所帮助:)