what does attachment=True do odoo 13 - odoo

I created a custom module in which I have this field
record_file = fields.Binary(string='file', attachment=True, help='Upload the file')
from what I understand attachment=True should save my images or pdfs to ir.attachment but am not seeing any there
am I doing something wrong

You are not doing something wrong, ir.attachment records are hidden when the value of res_field (a Char field) is set.
When you upload the file and save, an attachment is created and the value of the res_field is set to record_file which makes it invisible under Attachments.
You can check that the methods _search and read_group was overridden to add res_field=False in the domain if not present.
Note that the default value for the attachment parameter is True so you do not need to useattachment=True.
Edit:
From Binary field documentation:
attachment (bool) – whether the field should be stored as ir_attachment or in a column of the model’s table (default: True).

Related

What is use of sanitize attribute in html type field in odoo?

In html type of field one attribute is available, In which we can pass True/False.
body_html = fields.Html('Body', translate=True, sanitize=False, help="Rich-text/HTML version of the message (placeholders may be used here)")
body_html = fields.Html('Body', translate=True, sanitize=True, help="Rich-text/HTML version of the message (placeholders may be used here)")
If we set True/False then we are getting same result.
What is difference if we set True/False in this field ?
It's just telling Odoo if to clean html code, like deleting scripts, tags/nodes, etc. For more information look into the code.

Extract and compare text from an image with a baseline text string in TestComplete

I have a scenario in which user enters text in a text box .
Now, when the workflow of the test case is executed,the user provided text appears in an image format after the test flow is fully executed.
This is actually how the application under test treats the input data.It represents the text in a non-editable format.I simply take the snapshot here for comparison purpose .i.e setting the baseline for my test.
Is there a way that I can store this user entered text in step 1 in my baseline data store and then extract the text from image as part of validation of the correct data provided by user in the test case conclusion step.
I have used two checkpoints strategies to find the right solution,just am not sure whether it actually serves the purpose.
1.Added Object checkpoint while script record ,here's the script
Call Objects.configPackage_success.Check(Aliases.Microsoft_ConfigurationManagement.SmsWizardForm.zpagePanel.zinteriorPagePanel.WizardPage.ActionsCompletionWizardPageControl.labelCaption)
I have enabled the text field for this property during record time.I hope it compares the text extracted from the object somehow.I maybe wrong.
2.Added Property checkpoint with script below
Call aqObject.CheckProperty(Aliases.Microsoft_ConfigurationManagement.SmsWizardForm.zpagePanel.zinteriorPagePanel.WizardPage.ActionsCompletionWizardPageControl.labelCaption.Text, "OleValue", cmpEqual, "The Create Package and Program Wizard completed successfully")
Again,it hopefully does the text comparison part.Not sure how it internally works.
Or do I have rely only on Region checkpoints for validation of my test-output with baseline image.
Thanks

Can i change type of a field for already created pdf?

I have already created pdf, where I have field called Name which is of type String.
How can I change this field type to List like here?
Here is example how to add field type List for new PDF file:
cell.setCellEvent(new ChoiceFields(4));

Paperclip attachment file size

How do I fetch the file size of each style of a paperclip attachment?
#user.attachment_file_size doesn't seem to work
#user.attachment(:style).size
gives a number not related to the actual file size
I didn't find either how to get the file size for a given style, other than the original one.
As seen in the paperclip source code, #user.attachment.size returns the size of the file as originally assigned. There is no way to get it for a specific style...
A solution would be:
open(#user.attachment(:style)).size
But not efficient at all.
To do it well, you should probably add some "custom size" fields in your attachment table that you would fill once the attachment is saved for each style...
User find by ID(for example)
User has :photo
#user.last.photo_file_size
You can get a string like "WIDTHxHEIGHT" inside styles hash, for the giving object's style, using Paperclip::Style#geometry:
string = #user.attachment.styles[:size].geometry
Than you can split the string to have either height or width:
width = string.split("x")[0]
height = string.split("x")[1]
It seems it is possible actually
Just have to cath the temporary files for each style and applying size method.
let's say you have two styles large and small for your attachment called image and you have created two extra fields in your model large_size and small_size to save those values.
Just add the below bit of code to your model:
before_create :assign_sizes
private
def assign_sizes
self.large_size = image.queued_for_write[:large].size.to_i
self.small_size = image.queued_for_write[:small].size.to_i
end
The fields large_size and small_size will be popuated with each style file size. And this will be done before the files are sent to S3 for example. So there is no extra querying the files headers from S3.

Plone 4 - Get url of a file in a plone.app.blob.field.FileField

I have a custom content type with 3 FileFields (plone.app.blob.field.FileField) and I want to get their url's, so i can put them on my custom view and people will be able to download these files.
However, when using Clouseau to test and debug, I call :
context.getFirst_file().absolute_url()
Where getFirst_file() is the accessor to the first file (field called 'first_file').
The url returned is 'http://foo/.../eat.00001', where 'eat.00001' is the object of my custom type that contains the file fields...
The interesting thing is, if I call:
context.getFirst_file().getContentType()
It returns 'application/pdf', which is correct since it's a pdf file.
I'm pretty lost here, any help is appreciated. Thanks in advance!
File fields do not support a absolute_url method; instead, through acquisition you inherit the method from the object itself, hence the results you see. Moreover, calling getFirst_field() will return the actual downloadable contents of the field, not the field itself which could provide such information.
Instead, you should use the at_download script appended to the object URL, followed by the field id:
First File
You can also re-use the Archetypes widget for the field, by passing the field name to the widget method:
<metal:field use-macro="python:context.widget('first_field', mode='view')">
First File
</metal:field>
This will display the file size, icon (if available), the filename and the file mime type.
In both these examples, I assumed the name of the field is 'first_field'.