Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
3952 Lượt xem

Hello All,

I have to two many2one type field. In field local region "Hong kong", "Kawloon" and "New Terriotories". And in another many2one fields district related to these regions. And i want that when i select a 'local region' then district avail only related to that region. 

My code is here:

Python Code:

class district_code_form(models.Model):

    _name = 'district.districe.code'

    _rec_name = 'district_mainn'


    district_mainn = fields.Char('District Value')

    district_ss = 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")

   

class customer_information(models.Model):

    _inherit = "res.partner"

 @api.onchange('district_table_case')

    def _onchange_district_table(self):

        if self.district_table_case:

            return {'domain': {'district_table': [('district_table_case', '=', self.district_table_case)]}}

        else:

            return {'domain': {'district_table': []}}

 district_table_case = fields.Many2one('district.districe.code')

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

XML Code:


 <field name="district_table_case"/>

    <field name="district_table"/>

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

you will get error
Error: ValueError: Invalid field u'district_table_case' in leaf "<osv.ExtendedLeaf: (u'district_table_case', u'=', 1) on district_district (ctx: )>
Because you are trying to access the unknown field.

Ảnh đại diện
Huỷ bỏ
Tác giả

Yes exactly, i getting this error. How to solve this problem? Do you any suggestion?

domain can be applied on the fields which is available in the defined model in many2one

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 10 17
2962
2
thg 10 17
4858
2
thg 7 25
676
0
thg 12 24
1225
2
thg 10 24
1385