Skip to Content
Menu
This question has been flagged

Hello

I'm very new to this and I'm looking to add a new field to the project.task view. The field is visible in the view and I get the list of products. Now my goal is to narrow down that list of products to the products this partner has bought and paid for. 

My thought was to create a domain that gets the product ids and then create a domain. But every time I open the view my partner_id.id is False. I have tried getting it for hours but it is either False, 0 or None. When I check the partner_id somewhere else (for example the onchange) it is 12 which was correct in that case.

What do I need to do to get the partner_id.id into my function? Am I missing something?

Excuse my formatting, I don't know how the correct code markup tags.

from odoo import fields, models, api


class ExtendService(models.Model):
    _inherit = "project.task"

@api.model
def _getfilter(self):
    rec = self.env['account.move.line'].search([('partner_id.id', '=', self.partner_id.id)])
    eligible_product_ids = []
    for x in rec:
        if type(x.product_id.id) == int:
            eligible_product_ids.append(x.product_id.id)
    return [('id', 'in', eligible_product_ids)]

service_product_id = fields.Many2one('product.product',
    string="Related Product Id",
    domain=_getfilter)

@api.onchange('partner_id')
    def _onchange_partner_id(self):
    print(self.partner_id.id)

Avatar
Discard
Related Posts Replies Views Activity
0
Oct 24
124
1
Aug 24
421
2
Nov 24
752
1
May 24
1308
3
Oct 23
13195