Send only the required fields when fetching a readonly view definition

issue11134
review380081002
This commit is contained in:
Nicolas Évrard
2022-04-08 19:07:13 +02:00
parent b1bc6a51f5
commit 67a308aca0
2 changed files with 14 additions and 31 deletions
+9 -18
View File
@@ -41,8 +41,7 @@ class TariffCode(DeactivableMixin, ModelSQL, ModelView, MatchMixin):
start_month = fields.Selection(MONTHS, 'Start Month', sort=False,
states={
'required': Eval('end_month') | Eval('start_day'),
},
depends=['end_month', 'start_day'])
})
start_day = fields.Integer('Start Day',
domain=['OR',
('start_day', '<=', If(Eval('start_month').in_(
@@ -52,13 +51,11 @@ class TariffCode(DeactivableMixin, ModelSQL, ModelView, MatchMixin):
],
states={
'required': Bool(Eval('start_month')),
},
depends=['start_month'])
})
end_month = fields.Selection(MONTHS, 'End Month', sort=False,
states={
'required': Eval('start_month') | Eval('end_day'),
},
depends=['start_month', 'end_day'])
})
end_day = fields.Integer('End Day',
domain=['OR',
('end_day', '<=', If(Eval('end_month').in_(
@@ -68,8 +65,7 @@ class TariffCode(DeactivableMixin, ModelSQL, ModelView, MatchMixin):
],
states={
'required': Bool(Eval('end_month')),
},
depends=['end_month'])
})
duty_rates = fields.One2Many('customs.duty.rate', 'tariff_code',
'Duty Rates')
@@ -116,15 +112,13 @@ class DutyRate(ModelSQL, ModelView, MatchMixin):
('start_date', '<=', If(Bool(Eval('end_date')),
Eval('end_date', datetime.date.max), datetime.date.max)),
('start_date', '=', None),
],
depends=['end_date'])
])
end_date = fields.Date('End Date',
domain=['OR',
('end_date', '>=', If(Bool(Eval('start_date')),
Eval('start_date', datetime.date.min), datetime.date.min)),
('end_date', '=', None),
],
depends=['start_date'])
])
computation_type = fields.Selection([
('amount', 'Amount'),
('quantity', 'Quantity'),
@@ -133,20 +127,17 @@ class DutyRate(ModelSQL, ModelView, MatchMixin):
states={
'required': Eval('computation_type').in_(['amount', 'quantity']),
'invisible': ~Eval('computation_type').in_(['amount', 'quantity']),
},
depends=['computation_type'])
})
currency = fields.Many2One('currency.currency', 'Currency',
states={
'required': Eval('computation_type').in_(['amount', 'quantity']),
'invisible': ~Eval('computation_type').in_(['amount', 'quantity']),
},
depends=['computation_type'])
})
uom = fields.Many2One('product.uom', 'Uom',
states={
'required': Eval('computation_type') == 'quantity',
'invisible': Eval('computation_type') != 'quantity',
},
depends=['computation_type'])
})
@classmethod
def __setup__(cls):
+5 -13
View File
@@ -13,21 +13,18 @@ class Category(metaclass=PoolMeta):
customs = fields.Boolean('Customs', select=True,
states={
'readonly': Bool(Eval('childs', [0])) | Bool(Eval('parent')),
},
depends=['parent'])
})
tariff_codes_parent = fields.Boolean("Use Parent's Tariff Codes",
states={
'invisible': ~Eval('customs', False),
},
depends=['customs'],
help='Use the tariff codes defined on the parent category.')
tariff_codes = fields.One2Many('product-customs.tariff.code',
'product', 'Tariff Codes', order=[('sequence', 'ASC'), ('id', 'ASC')],
states={
'invisible': (Eval('tariff_codes_parent', False)
| ~Eval('customs', False)),
},
depends=['tariff_codes_parent', 'customs'])
})
@classmethod
def __setup__(cls):
@@ -35,11 +32,9 @@ class Category(metaclass=PoolMeta):
cls.parent.domain = [
('customs', '=', Eval('customs', False)),
cls.parent.domain or []]
cls.parent.depends.append('customs')
cls.parent.states['required'] = Or(
cls.parent.states.get('required', False),
Eval('tariff_codes_parent', False))
cls.parent.depends.append('tariff_codes_parent')
@classmethod
def default_customs(cls):
@@ -100,8 +95,7 @@ class Template(metaclass=PoolMeta):
],
states={
'required': Eval('tariff_codes_category', False),
},
depends=['tariff_codes_category'])
})
tariff_codes_category = fields.Boolean("Use Category's Tariff Codes",
help='Use the tariff codes defined on the category.')
tariff_codes = fields.One2Many('product-customs.tariff.code',
@@ -109,14 +103,12 @@ class Template(metaclass=PoolMeta):
states={
'invisible': ((Eval('type') == 'service')
| Eval('tariff_codes_category', False)),
},
depends=['type', 'tariff_codes_category'])
})
country_of_origin = fields.Many2One(
'country.country', "Country",
states={
'invisible': Eval('type') == 'service',
},
depends=['type'])
})
@classmethod
def __register__(cls, module_name):