在Odoo10中选择区域的区域时显示默认区域

时间:2017-11-03 06:32:33

标签: python-2.7 api openerp onchange odoo-10

我有3个区和一些与这些区有关的区域。现在,我希望当我选择区域而不是相关区域默认显示在下一个字段时,不需要填写区域。为此,我的代码如下:

Python代码:

class district_code_form(models.Model):
    _name = 'district.districe.code'
    _rec_name = 'district_value'

    district_value = fields.Char('District Value')
    district_region = fields.One2many('district.district', 'district_id', string="District Workflow")

class district_form(models.Model):
    _name = 'district.district'
    _rec_name = 'district'

    district_id = fields.Many2one('district.district.code', string='Districts Id', ondelete='cascade', index=True, copy=False)
    district = fields.Char("District")
    district_code = fields.Char('District Code')

现在我想访问此配置表,我的代码在这里:

class customer_information(models.Model):
    _inherit = "res.partner"

    @api.onchange('district_table_case', 'district_table')
    def _onchange_district_table(self):
        print "A:", self.district_table_case.district_region
        print "B:", self.district_table_case.district_value
        rec = self.district_table_case.district_region
        res = self.district_table_case.district_value
        print "res:", res
        if res:
            return {'domain': {'district_table_case': [('id', 'in', res)]}}
        else:
            return {'domain': {'district_table_case': []}}

    district_table = fields.Many2one('district.district')
    district_table_case = fields.Many2one('district.districe.code', change_default=True,
                                          default=_onchange_district_table)

我在终端屏幕上收到所有ID但没有达到标记

提前致谢。

1 个答案:

答案 0 :(得分:1)

您可以将district_table_case用作related field吗?

如:

class customer_information(models.Model):
    _inherit = "res.partner"

    district_table_case = fields.Many2one('district.districe.code', string="Region", related="district_table.district_id")

这样,它总是指向分配给区的区域。