コンテンツへスキップ
メニュー
この質問にフラグが付けられました
2 返信
7891 ビュー

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
2577
2
3月 15
7921
1
3月 15
7213
2
4月 15
5956