Ir al contenido
Menú
Se marcó esta pregunta
1 Responder
1687 Vistas

I created this model in odoo16

class CustomerProject(models.Model):
_name = 'customer.project'
_rec_name = 'project'
_description = 'Customer Project'
customer_id=fields.Many2one('res.partner',string="Customer",required=True)
project=fields.Char(required=True)

and i added project_id field in sale.order.line:

def set_domain_project_id(self):
"""Set domain to project_id to get only projects which have Customer_id equal to the same partner_id of sale order."""

sale_order=self.env['sale.order'].browse(self._context.get('active_id', []))
print(sale_order)
partner_id = sale_order.partner_id.id
return [('customer_id', '=', partner_id)]

project_id = fields.Many2one('customer.project', string="Project Code", domain=set_domain_project_id)

I need to set domain to project_id to get only projects which have the customer_id equals to the partner_id of sale order when select partner_id
but the above code return sale order empty (sale.order() )
so i can't get the partne_id of the current sale order

Avatar
Descartar
Mejor respuesta

Hi,

To set the domain to project_id to get only projects with the customer_id equal to the partner_id of the sale order, Update your code like this.

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

def set_domain_project_id(self):
"""Set domain for project_id to get only projects with customer_id equal to partner_id of the sale order."""
partner_id = self.order_id.partner_id.id
return [('customer_id', '=', partner_id)]

project_id = fields.Many2one('customer.project', string="Project Code", domain=set_domain_project_id)


Hope it helps

Avatar
Descartar