How to add a field that link to attachment model? - hyperlink

I have to include a field (paper) to store files in my model (salary) that looks like a hyperlink like if it was a binary. But I don't want it to be a binary stored in my model but to be stored in attachment model as an attachment.
In Knowledge module you can see that it is done, but it is done on itself, as Knowledge is the very module where attachments are stored.
I need to link from my model to attachment model so as the file will be stored in that model but in my model I have to have a field that looks like a hyperlink and when I link on it, I can download the file. As the same time, my field has to behave as a binary field, as I have to load files from it.
It has to work in version 7 and 8

if someone still need it here is the original xml code to create the 'attachment' submenu in 'others' button:
<record model="ir.values" id="ir_action_document_file_directory_form">
<field name="key2" eval="'tree_but_open'"/>
<field name="model" eval="'document.directory'"/>
<field name="name">Browse Files</field>
<field name="value" eval="'ir.actions.act_window,%d'%action_document_file_directory_form"/>
</record>
it is in
addons\document\document_view.xml

Maybe this works for you:
adding another field to create the link
file = fields.Binary("your_file", related='ir.attachment.datas')

Related

Change field label/string

I'm trying to change field label/string on amount_by_group field that is showing total tax amount on Invoice form.
Tried to do it like this - using field attributes
<xpath expr="//field[#name='amount_by_group']" position="attributes">
<attribute name="string">Porez</attribute>
</xpath>
No luck, also tried to replace field with the same field but with string defined
<xpath expr="//field[#name='amount_by_group']" position="replace">
<field name="amount_by_group" widget="tax-group-custom-field" nolabel="1" colspan="2" attrs="{'invisible': [('amount_tax', '=', 0)]}" string="Tax"/>
</xpath>
I used methods described here (first two points in answer by Cybrosys) https://www.odoo.com/forum/help-1/change-field-label-through-python-149963
Does anybody have clue how to change that fields name? At the moment field label is "Neoporezivo" and I'd like to show it as "Porez".
What you tried is correct. It seems in your case, you have to update field translation.
When we load a new language, Odoo translates terms based on .po file given the folder i18n in the related module.
You can try first from the front end and if it works, you can override .po file.
Try this:
Active developer mode.
Go to Settings > Translations > Translated Terms
Find your displayed term and edit it with your desired term.
Refresh your page and check your form. It should update with the desired term.
EDIT:

Team Foundation Server Using Custom Fields instead of System Fields

I'm introducing TFS 2010 in our company.
After a lot of work on item customizations, I'm considering using custom fields as some system fields.
One example...
I've got some management requirements for the field "System.priority". This field should be set to "REQUIRED", so everyone has to do an estimation about the priority of a bug or task.
Are there any well known problems with creating an custom mypriority field and using it? (except the whole customizing afterwards for the basic reports...)
I know i cant delete the system fields but i can delete the references for system.priority from the layout tab and then im going to use my own customized ones ..
Is this possible?
Avoid creating custom fields when the default ones can serve the purpose. E.g.: Use the REQUIRED rule where needed:
<FIELD name="Priority" refname="Microsoft.VSTS.Common.Priority" type="Integer" reportable="dimension">
<REQUIRED />
</FIELD>

Struts2 Validatation

I have used Struts2 in a period time, but I am still very confused with Struts2 Validation.
I have used xml-validation, or method addFieldError() to validate, but when I first come to input form-page, a page with struts-tags, and a <s:form>, I can not just go to this page by a href-link, I must go through another action, I read that page jsp with struts-tags must come from a action.
And I usually create a Action just for redirect to this input page, in execute() method just "success" and the role of this action is to go to input page legally, and in action which process the input form input-page, I choose the "input" result is still this input page.
So, I feel uncomfortable to do this, I always have a GoToSiteAction, just first-time go to input page.
So, I really need your help!!.
Use the with input fields , create a action and create a validation xml file with same name as java file name
For example : AddInput.java
xml file: AddInput-validation.xml
put it in same package.
write all the validations you need for the form in xml file like this.
<field name="U_Id">
<field-validator type="requiredstring" short-circuit="true">
<message>Affiliate Id cannot be empty</message>
</field-validator>
</field>
<field name="Password">
<field-validator type="requiredstring" short-circuit="true">
<message>Password cannot be empty</message>
</field-validator>
<field-validator type="stringlength">
<param name="minLength">5</param>
<param name="maxLength">30</param>
<message>Password cannot be less than 5 or more than 30</message>
</field-validator>
</field>
When you hit the action it will first hit the validation xml and check for the validation then process the action class part.
You are not using or not using the struts2-conventions plugin to it's full effect. Please see: http://struts.apache.org/2.1.6/docs/convention-plugin.html search this page for the string "Examples of Action and Result to Template mapping" and consider the table which follows.
In the future after adding the struts2-conventions-plugin jar to your project add the postfix "-input" to the end of all future forms.
Say we created a form to add a new employee:
/WEB-INF/content/add-employee-input.jsp
The struts2 form tag would reference an action simply called "add-employee" in a java class probably named something like com.mypackages.struts2.AddEmployee then if the add-employee action validation fails then "input" is returned and the "add-employee-input" form is again rendered. However we do not need to create a "add-employee-input" action, the conventions plugin will do this for us automatically... as such we can directly enter the form if we wish by referencing it and this is very convenient.
Try it out and you'll see what I mean.

how to display validation message in specific <div> element in Struts2

I'm new to Struts 2 and facing this problem in keeping the layout of my page:
<s:form action="abc.action"><br>
<s:textfield key="name" label="Name" /><%--here I need to display errormessage for `name`--%>
<br>
<s:textfield key="email" label="Email" /><%--here I need to display errormessage for `email`--%>
<br>
<s:submit>
</s:form>
I'm using xml-validator for my action class, this works fine. but the validation-error messages appear over the fieldname and text-box. but i want it to come afterwards respective text-box (inside another html-container). Kindly advise.
If you're used to writing HTML, switch to the simple theme.
In struts.xml is probably the best place:
<struts>
<constant name="struts.ui.theme" value="simple" />
</struts>
Then just use the fielderror tag to put the error for the field where you want it.
It's a good to be familiar with the Struts2 tags: http://struts.apache.org/release/2.3.x/docs/tag-reference.html
That is the default according to Struts2 default templating. To change it, see http://www.mkyong.com/struts2/working-with-struts-2-theme-template/
You Can also Use Struts2 validation Framework
Validation framework comes with set of useful routines to handle form validation automatically and it can handle both server side as well as client side form validation. If certain validation is not present, you can create your own validation logic by implementing java interface.
com.opensymphony.xwork2.Validator
Validator uses XML configuration files to determine which validation routines should be installed and how they should be applied for a given application. validators.xml file contains all common validators declaration. If validators.xml file is not present in classpath, a default validation file is loaded from path
com/opensymphony/xwork2/validator/validators/default.xml
Validators Scope
There are two types of Validators in Struts2 Validation Framework.
Field Validators
Non-field validators
Field validators, as the name indicate, act on single fields accessible through an action. A validator, in contrast, is more generic and can do validations in the full action context, involving more than one field (or even no field at all) in validation rule. Most validations can be defined on per field basis. This should be preferred over non-field validation wherever possible, as field validator messages are bound to the related field and will be presented next to the corresponding input element in the respecting view.
<validators>
<field name="bar">
<field-validator type="required">
<message>You must enter a value for bar.</message>
</field-validator>
</field>
</validators>
Non-field validators only add action level messages. Non-field validators are mostly domain specific and therefore offer custom implementations. The most important standard non-field validator provided by XWork is ExpressionValidator.
<validators>
<validator type="expression">
<param name="expression">foo lt bar</param>
<message>Foo must be greater than Bar.</message>
</validator>
</validators>
For whole detail example visit this link link to struts2 validation

Formatting hyperlink as a picture in a custom list schema

In my custom list XML I added a few URL fields. one of them has to be displayed as a picture just like when you select "Format URL as: Picture" in the fields settings of the UI.
In the customList's schema.xml I haven't found any place where to override the html markup for a URL type.
Any help or clue is welcome :)
Thanks,
teebot
Try changing the Format property of the relevant fields xml Schema.
Get a copy of SharePoint Manager to try it.
<Field ID="{c29e077d-f466-4d8e-8bbe-72b66c5f205c}" Name="URL"
SourceID="http://schemas.microsoft.com/sharepoint/v3" StaticName="URL"
Group="Base Columns" Type="URL" DisplayName="URL" ColName="nvarchar3"
RowOrdinal="0" ColName2="nvarchar4" RowOrdinal2="0" Format="Image" Version="1" />

Resources