Skip to Content
Menu
This question has been flagged
2 Replies
694 Views

Hi. I have a Many2One field and Multi line text field. I want to transfer record from Many2One fied  to Multi line Text field when CheckBox is selected. Then when I change rercord in Many2One field and press CheckBox again I want the previous record t ostay and add a new one to the field. I'm using Studio and Compute function.

for record in self:

    if record.x_studio_check_out:

        record['x_studio_history_2']=record['x_studio_so'],record['x_studio_history_2']

But it gives me this in result 

(project.task(53,), False) after first run and then  (project.task(49,), '(project.task(53,), False)') after second Instead of showing value of the field SO

Any help is appreiciated as always

Avatar
Discard
Best Answer

Hi Roman,

You can implement the provided solution as follows:

for record in self:
    if record.x_studio_check_out and record.x_studio_so:
        record['x_studio_history_2'] += "," + str(record.x_studio_so.name)

The error you encountered, "AttributeError: 'bool' object has no attribute 'name'", indicates that the field x_studio_so is now null. This could be due to it being empty or not having a value assigned.

To prevent this error, you should ensure that the field x_studio_so contains a value before accessing its attributes. Hence, I added an additional condition and record.x_studio_so to the loop. This checks if record.x_studio_so is not null before attempting to access its attributes.

By adding this condition, you ensure that the loop only accesses the attribute name if x_studio_so is not null, thus preventing the AttributeError.


Hope it helps




Avatar
Discard
Best Answer

A many to one field is a link to another database table, in the UI it would be boring to see project.task, 53 so instead a field in that table is displayed.

Try record.x_studio_so.name to get the name of the project.


You should also look into how python handles text and concatenation.

*Edit* - x_studio_so.name is correct or the field is not filled in, if there is nothing in the field it returns the boolean False. x_studio_history as a multiline text will act the same and return False if there is nothing in it. You will need to handle that with an if statement or something. Same with the so field if that is blank it will return nothing.

Start with this and figure out how you want to handle if either of those fields are currently empty.

for record in self:
    if record.x_studio_check_out:
​record['x_studio_history_2'] = str(record.x_studio_so.name) + ", " + str(record.x_studio_history_2)
Avatar
Discard
Author

Thanks for reply. Looks like it doesn't like 'name' attribute.
AttributeError: 'bool' object has no attribute 'name'.