跳至内容
菜单
此问题已终结
2 回复
7879 查看

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

形象
丢弃
最佳答案

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

形象
丢弃
编写者

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'

编写者

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

最佳答案

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.

形象
丢弃
编写者

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

编写者

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.

相关帖文 回复 查看 活动
1
3月 15
9849
0
3月 17
2574
2
3月 15
7916
1
3月 15
7209
2
4月 15
5955