This question has been flagged
1 Reply
2326 Views

Hi everyone,

For a specific partner and a specific product I want to get the last price for that I tried this one but I get not the last_price

def product_id_change(self, cr, uid, ids, product, uom_id, qty=0, name='', type='out_invoice', partner_id=False, fposition_id=False, price_unit=False, currency_id=False, company_id=None, context=None):
        res = super(kms_account_invoice_line, self).product_id_change(cr, uid, ids, product, uom_id, qty, name, type, partner_id, fposition_id, price_unit, currency_id=currency_id, company_id=company_id, context=context)
        acc_inv_obj = self.pool.get('account.invoice.line')
 acc_inv_ids = acc_inv_obj.search(cr, uid,[('partner_id', '=', partner_id),('product_id','=',product)], context=context)
        for acc_inv_data in acc_inv_obj.browse(cr, uid, acc_inv_ids, context=context):
            print 'last_price',acc_inv_data.price_unit
            res['value'].update({'last_price':acc_inv_data.price_unit})
        return res

could you help me please to get the write last_price.

Thanks

Avatar
Discard
Best Answer
acc_inv_ids = acc_inv_obj.search(cr, uid,[('partner_id', '=', partner_id),('product_id','=',product), ('id', 'not in', [ids])], ,order="asc", limit=1, context=context)

Use this domain in your search so it will return latest id of the invoice line and return only single id at a time because we used limit=1 and in case you didn't get any id from the search then please remove ('id', 'not in', [ids]) this domain from search.
hope this will help you.
Avatar
Discard
Author

Thanks for your answer it was very helpful but I had to remove order="asc"