Skip to Content
Menu
This question has been flagged
2 Replies
7863 Views

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
Discard
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
Discard
Author

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'

Author

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
Discard
Author

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

Author

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 Replies Views Activity
1
Mar 15
9810
0
Mar 17
2541
2
Mar 15
7900
1
Mar 15
7200
2
Apr 15
5918