Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odgovori
7880 Prikazi

Hey i am having this attribute error

@api.model
def _make_pr_get_domain(self, values):
domain = (
("state", "=", "draft"),
("picking_type_id", "=", self.picking_type_id.id),
("company_id", "=", values["company_id"].id),
)
gpo = self.group_propagation_option
group_id = (
(gpo == "fixed" and self.group_id.id)
or (gpo == "propagate" and values["group_id"].id)
or False
)
if group_id:
domain += (("group_id", "=", group_id),)
return domain

Bold part is throwing me the error can anyone tell whats wrong here. some help would be great

Avatar
Opusti
Best Answer

Hi,

Before calling .id you have to ensure that the field/variable contains a value in it. As a an example, instead of using self.picking_id.id, check whether the values["company_id"].id have a value in it, similarly values['group_id'].id

Thanks

Avatar
Opusti
Avtor

Hey niyas thanks for the reply i checked the values of company_id and i still get the same error

File "/opt/odoo13/odoo-custom-addons/purchase_request/models/stock_rule.py", line 105, in create_purchase_request

domain = rule._make_pr_get_domain(procurement.values)

File "/opt/odoo13/odoo-custom-addons/purchase_request/models/stock_rule.py", line 63, in _make_pr_get_domain

or (gpo == "propagate" and values["group_id"].id)

AttributeError: 'bool' object has no attribute 'id'

Avtor

here is the code

@api.model

def _make_pr_get_domain(self, values):

"""

This method is to be implemented by other modules that can

provide a criteria to select the appropriate purchase request to be

extended.

:return: False

"""

domain = (

("state", "=", "draft"),

("picking_type_id", "=", self.picking_type_id.id),

)

if values.get('company_id'):

domain += ("company_id", "=", values['company_id'].id)

gpo = self.group_propagation_option

group_id = (

(gpo == "fixed" and self.group_id.id)

or (gpo == "propagate" and values["group_id"].id)

or False

)

if group_id:

domain += (("group_id", "=", group_id),)

return domain

Best Answer

hi, 

make sure you have values["company_id"] before getting .id
domain = (("state", "=", "draft"),("picking_type_id", "=", self.picking_type_id.id))

if values.get('company_id'):
    domain += (("company_id", "=", values['company_id'].id))
// rest of code

p.s: i'm assuming that values['company_id'] returns a record

Hope this helps.

Avatar
Opusti
Avtor

Hey ibrahim thanks for replying but i am still getting the same error here is my code as per your instructions

@api.model

def _make_pr_get_domain(self, values):

"""

This method is to be implemented by other modules that can

provide a criteria to select the appropriate purchase request to be

extended.

:return: False

"""

domain = (

("state", "=", "draft"),

("picking_type_id", "=", self.picking_type_id.id),

)

if values.get('company_id'):

domain += ("company_id", "=", values['company_id'].id)

gpo = self.group_propagation_option

group_id = (

(gpo == "fixed" and self.group_id.id)

or (gpo == "propagate" and values["group_id"].id)

or False

)

if group_id:

domain += (("group_id", "=", group_id),)

return domain

Can you please help me fix it

don't add @api.model

Avtor

Still same..What can be the issue?

Same function is available in po with the name of make_po_get_domain but that way it doesnt take the procurement group in account while create requests

In this case you need to debug your code and see which value is empty.

you can try with pdb.

Otherwise, you can add prints in your code and check every information.

Related Posts Odgovori Prikazi Aktivnost
1
mar. 15
9849
0
mar. 17
2574
2
mar. 15
7916
1
mar. 15
7209
2
apr. 15
5955