تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
1 الرد
4107 أدوات العرض

Hello, How can I show the other field when it is selected?
Scenario:

fieldA has field1 and field2


If field1 is selected, fieldB will display

If field2 is selected, fieldC will display

class AccountVoucherLine(models.Model):
        _inherit = "account.voucher.line"
        
        fieldA = fields.Selection([
                ('field1', 'Field 1'),
                ('field2', 'Field 2'),
            ], 'Field Type', required=True,  index=True)
        
    class AccountVoucher(models.Model):
        _inherit = "account.voucher"
        
        fieldB = fields.Char(string="Field B")
        fieldC = fields.Char(string="Field C")
الصورة الرمزية
إهمال
أفضل إجابة

Hello,

        Try this in your xml file,

    <field name="fieldA/>
    <field name="fieldB  attrs="{'invisible': [('fieldA', '!=', 'field1')]}"/>

    <field name="fieldC  attrs="{'invisible': [('fieldA', '!=', 'field2')]}"/>

Thanks

الصورة الرمزية
إهمال
الكاتب

Hi, I updated my code.

what if they are related fields from a different model?

Hi, In your case, based on fieldA , the other two fields are displaying. account.voucher.line is the One2many to account.voucher ,

You can have related field only in account.voucher.line and not in account.voucher

For example,

class AccountVoucher(models.Model):

_inherit = "account.voucher"

fieldB = fields.Char(string="Field B")

fieldC = fields.Char(string="Field C")

class AccountVoucherLine(models.Model):

_inherit = "account.voucher.line"

fieldA = fields.Selection([

('field1', 'Field 1'),

('field2', 'Field 2'),

], 'Field Type', required=True, index=True)

fieldB = fields.Char(string="Field B", related='voucher_id.fieldB', store=True)

fieldC = fields.Char(string="Field C", related='voucher_id.fieldC', store=True)

and as I answered before, view can be written only for account.voucher.line

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
يناير 23
2220
0
يوليو 20
3318
1
يوليو 19
6752
1
مايو 16
16877
1
أكتوبر 23
1991