Make a functional field editable in Openerp?

2024/11/15 15:03:03

How to make functional field editable in Openerp?

When we create

'capname': fields.function(_convert_capital, string='Display Name', type='char', store=True
),

This will be displayed has read-only and we can't able to edit the text.

How we make this field has editable?

Answer

A computed field has a function that automatically calculates it's value on some source data.

It is possible to add it the inverse operation, updating the source data based on a value manually set on it, thus making it editable.

From the documentation:

to allow setting values on a computed field, use the inverse parameter. It is the name of a function reversing the computation and setting the relevant fields:

Example code:

document = fields.Char(compute='_get_document', inverse='_set_document')def _get_document(self):for record in self:with open(record.get_document_path) as f:record.document = f.read()
def _set_document(self):for record in self:if not record.document: continuewith open(record.get_document_path()) as f:f.write(record.document)
https://en.xdnf.cn/q/71875.html

Related Q&A

how to read a fasta file in python?

Im trying to read a FASTA file and then find specific motif(string) and print out the sequence and number of times it occurs. A FASTA file is just series of sequences(strings) that starts with a header…

Passing a pandas dataframe column to an NLTK tokenizer

I have a pandas dataframe raw_df with 2 columns, ID and sentences. I need to convert each sentence to a string. The code below produces no errors and says datatype of rule is "object." raw_d…

SWIG - Wrap C string array to python list

I was wondering what is the correct way to wrap an array of strings in C to a Python list using SWIG.The array is inside a struct :typedef struct {char** my_array;char* some_string; }Foo;SWIG automati…

How to show an Image with pillow and update it?

I want to show an image recreated from an img-vector, everything fine. now I edit the Vector and want to show the new image, and that multiple times per second. My actual code open tons of windows, wit…

How do I map Alt Gr key combinations in vim?

Suppose I wanted to map the command :!python % <ENTER> to pressing the keys Alt Gr and j together?

cannot import name get_user_model

I use django-registrations and while I add this code in my admin.pyfrom django.contrib import adminfrom customer.models import Customerfrom .models import UserProfilefrom django.contrib.auth.admin impo…

pytest: Best Way To Add Long Test Description in the Report

By default pytest use test function names or test files names in pytest reportsis there any Best way to add test description (Long test name) in the report with out renaming the files or functions usin…

Adding a calculated column to pandas dataframe

I am completely new to Python, pandas and programming in general, and I cannot figure out the following:I have accessed a database with the help of pandas and I have put the data from the query into a …

Scipy: Centroid of convex hull

how can I calculate the centroid of a convex hull using python and scipy? All I found are methods for computing Area and Volume.regards,frank.

Creating a montage of pictures in python

I have no experience with python, but the owner of this script is not responding.When I drag my photos over this script, to create a montage, it ends up cutting off half of the last photo on the right …