콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
7894 화면

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
9853
0
3월 17
2578
2
3월 15
7921
1
3월 15
7213
2
4월 15
5959