Skip to Content
Menu
This question has been flagged
1 Reply
1604 Views

Hi, for example I want to update the price of products with a price of zero dollars to 100.

for price_list_items in (self.env['product.pricelist.item'].search_read([], [])):
    if price_list_items.price == 0:
price_list_items.price = 100

But It's not working.

    AttributeError: 'dict' object has no attribute 'price'

How can I make such a update like this ?


Avatar
Discard
Best Answer

Hello Selman Yilmaz,

you have used search_read method which returns List of dictionaries containing the asked fields.

please check search_read method. 

@api.model
def search_read(self, domain=None, fields=None, offset=0, limit=None, order=None, **read_kwargs):
"""Perform a :meth:`search` followed by a :meth:`read`.

:param domain: Search domain, see ``args`` parameter in :meth:`search`.
Defaults to an empty domain that will match all records.
:param fields: List of fields to read, see ``fields`` parameter in :meth:`read`.
Defaults to all fields.
:param int offset: Number of records to skip, see ``offset`` parameter in :meth:`search`.
Defaults to 0.
:param int limit: Maximum number of records to return, see ``limit`` parameter in :meth:`search`.
Defaults to no limit.
:param order: Columns to sort result, see ``order`` parameter in :meth:`search`.
Defaults to no sort.
:param read_kwargs: All read keywords arguments used to call read(..., **read_kwargs) method
E.g. you can use search_read(..., load='') in order to avoid computing name_get
:return: List of dictionaries containing the asked fields.
:rtype: list(dict).
"""

you could use search method directly as follow

for price_list_items in self.env['product.pricelist.item'].search_read([]):

    if price_list_items.product_id.price==0:
           price_list_items.product_id.price=100      


Thanks & Regards,



CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209
Email: info@candidroot.com
Skype: live:candidroot
Web: https://www.candidroot.com
Address: 1229-1230, Iconic Shyamal, Near Shyamal Cross Road, Ahmedabad, Gujarat



Avatar
Discard
Related Posts Replies Views Activity
1
Dec 23
1002
1
Nov 23
820
2
Aug 23
934
1
Dec 23
2077
1
Jul 23
1522