odoo - How to create a field for project sale orders -
i have fields quick access of entities related project. example:
class project(models.model): _name = "project.project" _description = "project" _inherit = 'project.project' production_order_ids = fields.one2many('mrp.production', 'project_id', 'production orders') purchase_order_ids = fields.one2many('purchase.order', 'project_id', 'purchase orders') ....
i trying create sale_order_ids in project.project model. first try did not work:
sale_order_ids = fields.one2many('sale.order', 'project_id', string='sale orders')
because because field sale.order.project_id of type account.analytic.account.
a project.project object inherits account.analytic.account. query should work ok if share same id, not. navigation be:
"project.project".analytic_account_id" -> sale.order".project_id
and result corresponding sale.order(s).
use computed field:
sale_order_ids = fields.one2many('sale.order', compute='_get_sale_orders', string='sale orders') @api.model def _get_sale_orders(self): record in self: record.sale_order_ids = self.env['sale.order'].search([('project_id', '=', record.analytic_account_id.id)]).ids
Comments
Post a Comment