检索同一表的乘法ID

时间:2018-12-12 15:59:30

标签: odoo odoo-8 odoo-9

因此,每个伙伴都有此字段,我在我的方法中将其添加到列表fields中。这些字段是带有comodel'product.category'的many2one字段,因此它们位于同一表中。如何为当前合作伙伴检索所有此字段的ID?

class ClientPotential(models.Model):
    _name = 'client.potential'
    _description = 'Client Potential'
    partner_id = fields.Many2one(
            'res.partner', string='Client')

@api.onchange('partner_id', 'categ_id')
    def _calculate_potential(self):
        categ_obj = self.env['product.category']
        fields = ['flexible_id', 'flexible_qty', 'drawer_id', 'drawer_qty',
                  'runner_id', 'runner_qty', 'group_1_id', 'group_1_qty', 'group_2_id',
                  'group_2_qty', 'group_3_id', 'group_3_qty']

        for field in fields:
            categ_obj += 
        ?????

1 个答案:

答案 0 :(得分:1)

我认为getattr可以解决问题:

    categ_obj = self.env['product.category']
    fields = ['flexible_id', 'flexible_qty', 'drawer_id', 'drawer_qty',
              'runner_id', 'runner_qty', 'group_1_id', 'group_1_qty', 'group_2_id',
              'group_2_qty', 'group_3_id', 'group_3_qty']
    if self.partner_id:
        for field_name in fields:
            categ_obj += getattr(self.partner_id, field_name)

希望你有个主意

因此,我爱python。