对象没有属性'env'我正在尝试访问env,但我得到'account.invoice'对象没有属性'env'。 代码
def get_cp(self,customer = None, supplier = None):
filter_st = ()
if customer: filter_st = ('customer','=',customer)
if supplier: filter_st = ('supplier','=',supplier)
filter_st += ('facturado','=',False)
cps = self.env['transport_liqproducto.data'].search([filter_st])
cps_list = []
for c in cps:
cps_list.append((0,0,{
'name':"%s-%s-%s-%s n %s"%(c.product,c.origen,c.destino,c.type,c.comp),
'price_unit': c.tarifa,
'quantity': c.cant,
}))
return cps_list
class account_invoice(models.Model):
_inherit = "account.invoice"
@api.onchange('partner_id')
def onchange_partner_id(self, cr, uid, ids, partner_id, context=None,*args,**kargs):
val = {}
if partner_id:
type = args[4]['journal_type']
if type == 'sale':
val['invoice_line'] = get_cp(self,customer=partner_id)
return {'value': val}
如何访问'transport_liqproducto.data'记录集?
谢谢!
答案 0 :(得分:3)
我这样解决了
env = api.Environment(cr, 1, {})
cps = env['transport_liqproducto.data'].search([domain])
答案 1 :(得分:1)
你使用v7表示法
def onchange_partner_id(self, cr, uid, ids, partner_id, context=None,*args,**kargs)
尝试使用v8
def onchange_partner_id(self)
代替(在方法中你需要引用self.partner_id,而不是用作参数的partner_id)