如何为项目销售订单创建字段

时间:2015-10-22 14:27:13

标签: odoo odoo-8

我有用于快速访问与项目相关的实体的字段。例如:

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')
    ....

我正在尝试在 project.project 模型中创建 sale_order_ids 。我的第一次尝试不起作用:

sale_order_ids   = fields.One2many('sale.order', 'project_id', string='Sale orders')

因为字段 sale.order .project_id的类型为 account.analytic.account

project.project 对象继承自 account.analytic.account 。如果它们共享相同的Id,则此查询应该可以正常工作,但它们不会。导航将是:

"project.project".analytic_account_id" -> sale.order".project_id

结果将是相应的 sale.order (s)。

1 个答案:

答案 0 :(得分:0)

使用计算字段

sale_order_ids = fields.One2many('sale.order', compute='_get_sale_orders', string='Sale orders')

@api.model
def _get_sale_orders(self):
    for record in self:
        record.sale_order_ids = self.env['sale.order'].search([('project_id', '=', record.analytic_account_id.id)]).ids