Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
1958 Zobrazení

Hi,

I created a computed Many2Many field. To make it writable, I used the inverted argument to define a reverse function like so:

document_ids = fields.Many2many(..., compute='_compute_document_ids', inverse='_set_document_ids')
def _compute_document_ids(self): ​...
def _set_document_ids(self): ​...

Then I created a view which makes use of this field with a Kanban or Tree element. So far everything works fine, I can read, create and delete documents.


Now I want to have the Kanban not to be able to create or delete records, only to be able to edit records when opening them. So I tried the following attemps, none of them works:

### 1:
field name="document_ids" mode="kanban" options="{'no_create': True}" /> 

### 2:
field name="document_ids" mode="kanban" create="0" />
### 3:
field name="document_ids">
​tree create="0">
​ ...


No matter if I use Kanban/Tree here, I still have the "add" or "add a line" option. When I make the field readonly, then the add/delete options disappear. But when I open the record details, I also cannot edit the (because read only).


What am I missing? I need to have a computed field for showing related Many2Many records, I do not want to be able to add/remove records from the parent record but be able to edit them in detail view by clicking on them.

THX



Avatar
Zrušit
Nejlepší odpověď

To achieve your goal of making the Kanban view not able to create or delete records, but still be able to edit them when opening, you can use a combination of the following approaches:


    Make the Field Readonly in Kanban:

    Set the readonly attribute for the document_ids field in the Kanban view to prevent creating or deleting records directly from the Kanban view.


Use a Separate Form View for Editing:

Create a separate form view for editing the records and use it when clicking on a record in the Kanban view. This allows you to control the edit behavior independently.

Then, define a form view for the model where you can customize the behavior as needed.


When clicking on a record in the Kanban view, Odoo will open the form view specified in the model.


Use a Related Field for Display:

If you only need to display related records in the Kanban view and do not require direct editing, you can use a related field for display purposes in the Kanban view.


Then, define a related field in your model. 


    display_document_ids = fields.Many2many(related='document_ids')


    Note: This approach will only allow displaying related records in the Kanban view without the ability to edit them directly.


Choose the approach that best fits your requirements. If you need to customize the editing behavior, creating a separate form view for editing is a flexible solution.

Avatar
Zrušit
Autor Nejlepší odpověď

Hi. Thanks for your answer. 

According to it I created another view for editing the detail data (in my case Document). Odoo also uses this view correctly to display the detail date and I am also able to edit the record with this view.

But as soon as I make the Many2Many / One2Many field *readonly* in the parent view then the detail data view is also *locked* so that I cannot edit data anymore.

The same result also if I replace the Kanbank Many2Many with a tree.


Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
dub 24
3658
1
pro 16
7877
4
úno 20
4040
2
bře 15
9743
2
čvc 16
519