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

I have a scenario where I've added numerous custom fields to the account.move inherited view, and most of these fields share the same visibility condition. The challenge is that I need to write multiple conditions to control their visibility. Whenever a requirement changes, I must update the condition for multiple fields individually. Additionally, if I want to display a field for multiple move_types , I end up writing lengthy conditions for each field.

Over time, the account.move form view has become very large due to these customizations and conditions, making it increasingly difficult to implement changes without risking disruptions to other flows, such as vendor bills, customer invoices, and journal entries. Is there a more efficient way to manage this, where I can define a single condition that applies to multiple fields, simplifying maintenance and ensuring stability across the views? basically an if block where i can check the move type and define all the fields for a certain move_type, similarly another if condition to deal with another move_type

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

I don’t have enough karma to post, so I’m commenting here. As Andre mentioned, I’d prefer using the second option, but the challenge I’m facing is how to create separate workflow views while inheriting the original account.move form view. I want to avoid copying the entire XML from the original form view into my custom view. Instead, I’d like to inherit the form view for each workflow, allowing me to manage fields based on the specific workflow.

Câu trả lời hay nhất

Hi,


You can simplify your process as follows.


1- Add a boolean field in the 'account.move'. It should be a computed field and made invisible in the form view. Add the compute function and add all your conditions in the function.

This field will encapsulate your condition logic (e.g., move_type == 'out_invoice'). It will be used to control field visibility in the view.

     class AccountMove(models.Model):

    """Inherited model 'account.move'."""
_inherit = 'account.move'

is_check_condition = fields.Boolean(string="Check Condition",
help="Compute field for check the field conditions",
compute="_compute_conditions")
# Add your custom fields


def _compute_conditions(self):
"""Compute field for checking the field visibility of the custom fields"""
for rec in self:
if rec.move_type == 'out_invoice': #Add all the condition that make the boolean field True
rec.is_check_condition = True
else:
rec.is_check_condition = False


2- Add the computed boolean field as the invisible attribute of the custom fields.


<record id="view_move_form" model="ir.ui.view">
<field name="name">account.move.form.inherit</field>
<field name="model">account.move</field>
<field name="inherit_id" ref="account.view_move_form"/>
<field name="arch" type="xml">
#Add the compute field and make it invisible
<xpath expr="//group[@id='header_right_group']" position="inside">
<field name="is_check_condition" invisible="1"/>
</xpath>
# Add the boolean field as the condition for the custom field
<xpath expr="//#" position="inside">
<field name="custom_field" invisible="is_check_condition"/>
</xpath>
</field>
</record>



If you have multiple distinct conditions, you can create multiple computed booleans.This way, different sets of fields can reference different visibility flags.


Hope it helps.


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

Hi.
Managing large views is always hard especially when the conditions start to increase exponentially. 

Someway you can make the process easier:

Option 1: Define a new selection field that tracks each workflow, and have a computed action for changing the visibility of the other fields, or set any rules you might have (domains, fields values, etc
).
This lets you define each process with a single user action, and every aspect of that workflow is embedded into a single function.

Option 2: Create one view per workflow type.
As before, this gives you more control over each workflow. The negative part is that you increase maintenance difficulty, as your fields are replicated through more locations, but for some cases this works well.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 6 25
75
1
thg 6 25
178
1
thg 1 25
1097
1
thg 6 25
540
1
thg 5 25
550