Mariano DAngelo
Mariano DAngelo

Reputation: 940

object has no attribute 'env'

object has no attribute 'env' I'm trying to access to env, but I get 'account.invoice' object has no attribute 'env'. The code

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}

How can I access to 'transport_liqproducto.data' recordset ?

Thanks!

Upvotes: 2

Views: 11515

Answers (2)

Alessandro Ruffolo
Alessandro Ruffolo

Reputation: 1575

you used v7 notation for

def onchange_partner_id(self, cr, uid, ids, partner_id, context=None,*args,**kargs)

try with v8

def onchange_partner_id(self)

instead (into the method you need to refer to self.partner_id, instead of the partner_id used as parameter)

Upvotes: 1

Mariano DAngelo
Mariano DAngelo

Reputation: 940

I solved like this

env = api.Environment(cr, 1, {})    
cps = env['transport_liqproducto.data'].search([domain])

Upvotes: 3

Related Questions