Odoo 9.0 C How to add a new many2one field from an inherited view? - view

Could you guy please show me what is the right steps to follow when we want to add a new many2one field to an inherited view like account.invoice.order.

It's like the same :
<template id="new_id" inherit_id="module_name.qweb_template_id" name="Template name as you want">
<!-- specify the target that you want to add the many2one field
than the place after,before or inside -->
<xpath expr="//target_where_you_want_to_add" position="after/before/inside">
<field name="your_one_to_many_field_name" />
</xpath>
</template>
the hard part is targeting the write place
like if you want to add the the field to a div tag inside a div with id ="div_id" and the div contain a class="class_name"
<xpath expr="//div[#id='div_id']/div[#class='class_name']" position="inside">
or a after a field inside that div named field1
<xpath expr="//div[#id='div_id']/div[#class='class_name']/field[#name='field1']" position="after">
or after a field that named field1
<!-- // is like a shortcut -->
<xpath expr="//field[#name='field1']" position="after">
so see who can you target the place that you want to put the field using tag names and properties like id,class,... (string is not supported in odoo 9)

Related

Add total label to tree footer odoo 12

I need to add a Total label on the last row from a tree, the last row is for sum values, how can I edit a tree footer?
view.xml
<xpath expr="//field[#name='field_list']/tree/field[#name='name']" position="after">
<field name="field1" sum="Total Field 1"/>
<field name="field2" sum="Total Field 2"/>
<field name="field3" sum="Total Field 3"/>
</xpath>
screenshot
Is there a way to edit the tree footer?
The list footer is used to show aggregates (sum, avg), it is rendered in _renderFooter of the ListRenderer.
The method docstring:
/**
* Render the footer. It is a <tfoot> with a single row, containing all
* aggregates, if applicable.
*
* #private
* #returns {jQueryElement} a <tfoot> element
*/
The method that computes aggregates will check for the field type, the computation will be ignored if the field type is not one of the following integer, float or monetary.
You can alter the _renderFooter to be able to provide a static text to display in the footer using a field attribute.
Example:
var ListRenderer = require("web.ListRenderer");
ListRenderer.include({
_renderFooter: function () {
var res = this._super();
_.each(this.columns, function (column) {
if(!('aggregate' in column) && column.attrs.text) {
res.find('.'+column.attrs.name).text(column.attrs.text);
}
});
return res;
},
});
To add the above code, check the Assets Management documentation.
To display the text in the footer of the corresponding column, set the text attribute in the field tag ( if the field contain an aggregate, the text will be ignored).
<field name="total" text="Total"/>

Odoo duplicate many2many fields

A model [m] with a many2many field [m2m]
Field [m2m] have attribute [copy=False]
A form view [v] display the [m] and the field [m2m] with widget [many2many_tags]
I have tested that the python object did return a with False on field [m2m]
but the javascript, keep render the tags on web.
model.py
class model(models.Model):
_name = "m"
m2m = fields.Many2many('sale.order', string="SO", copy=False)
XML File
<record ...>
<form>
<group>
<field name="name"/>
<field name="ref"/>
<field name="so_m2m" widget="many2many_tags" options="{'no_create_edit': True}"/>
</group>
</form>
</record>
When I duplicate the current record, the field [m2m] is keeps the old tag from old record which is not expected.
After clicking the save button, the old tag will disappear.
Try one thing here :
Whatever your third table is there, both fields used in many2many relation, from third table keep them as a copy false.
i.e.
m2m = fields.Many2many('sale.order','sale_order_another_table_rel', 'sale_order_field','antother_table_field', string="SO", copy=False)
Into new table :
_name = 'sale.order.another.table.rel'
sale_order_field_id = // copy=false
another_table_field_id = //copy = false
Hopefully work.

TYPO3 Fluid - How To Make f:form.textarea Mandatory

I have text fields like this that will turn red and won't let you submit the form automatically if I put the property required on "1":
<f:form.textfield required="1"
property="name"
class="lcapp-formwidth"/>
Now I'm searching for the same in a textarea...the property required doesn't work here anymore...what would be the "best practice" to make it a required field just like the textfield?
<f:form.textarea property="story"
rows="3"
cols="7"
class="lcapp-formwidth" />
It is true, the TextareaViewHelper does not support the required attribute as an argument, but you can add any attribute to a fluid generated tag by using the additionalAttributes argument.
E.g.:
<f:form.textarea property="story"
rows="3"
cols="7"
class="lcapp-formwidth"
additionalAttributes="{required: 'required'}" />
Notice how additionalAttributes expects an array notation, where the key is the name of the attribute.

OpenERP, dynamic DOMAIN in view

I work with OpenERP and I try to create a new form view for the account_bank_statement_line object. so when i create a new statement line the statement object must in open state so far no problem i solved with domain in the field tag attribute, But when I try to view the satatement after confirming the cash; the statement_id will desapear becouse it state is confirmed how can I solve this probleme can sommeone help me
<field colspan="2" name="statement_id" domain="[('state','=','open')]" attrs="{'readonly':[('state','=', 'confirm')]}" widget="selection" string="Cash Register"/>
<field colspan="6" name="amount" attrs="{'readonly':[('state','=', 'confirm')]}" />
regards
try adding the domain, domain="[('state','in',['open','confirm'])]"
From your code I don't really see what is hiding your field "statement_id". The fields are visible by default and can be hidden by the invisible attribute. Try to add it explicitly to your field definition:
<field colspan="2" name="statement_id"
invisible="0"
domain="[('state','=','open')]"
attrs="{'readonly':[('state','=', 'confirm')]}"
widget="selection" string="Cash Register"/>

How do you add fields to com_content in Joomla! with a plugin and store the data in its own table?

I'm running Joomla 1.7 and I know that it has the ability to add custom form fields to components with a plugin.
There is a sample plugin located at:
/plugins/user/profile
This plugin allows you to put custom form fields on the user profile front end and back end and these fields are stored in a custom table.
I created a similar plugin for user profiles and it worked perfectly.
However, when I go to create a plugin like this for com_content, I am met with a problem.
this is what my XML file looks like:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="additionalinfo">
<fieldset name="additionalinfo_fieldset" label="PLG_CONTENT_ADDITIONALINFO_FIELDSET_LABEL">
<field name="tagline" type="text" size="50" default="" label="PLG_CONTENT_ADDITIONALINFO_TAGLINE_LABEL" description="PLG_CONTENT_ADDITIONALINFO_TAGLINE_DESC" />
<field name="pseudocategory" type="category" extension="com_content" label="PLG_CONTENT_ADDITIONALINFO_PSEUDOCATEGORY_FIELD_LABEL" description="PLG_CONTENT_ADDITIONALINFO_PSEUDOCATEGORY_FIELD_DESC" />
</fieldset>
</fields>
</form>
This however does not work, whenever I do something like above, the form fields never show up on the admin form (even though I have it set correctly, and the only thing that changed between the user plugin and the content plugin is the name of the form i'd like the form to appear on
When I change my XML to this:
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="attribs">
<fieldset name="additionalinfo_fieldset" label="PLG_CONTENT_ADDITIONALINFO_FIELDSET_LABEL">
<field name="tagline" type="text" size="50" default="" label="PLG_CONTENT_ADDITIONALINFO_TAGLINE_LABEL" description="PLG_CONTENT_ADDITIONALINFO_TAGLINE_DESC" />
<field name="pseudocategory" type="category" extension="com_content" label="PLG_CONTENT_ADDITIONALINFO_PSEUDOCATEGORY_FIELD_LABEL" description="PLG_CONTENT_ADDITIONALINFO_PSEUDOCATEGORY_FIELD_DESC" />
</fieldset>
</fields>
</form>
When I make this simple change, the form fields show up! BUT, the data isn't stored or retrieved from the custom table, it just goes into the 'attribs' column on the _content table. This stores the content in JSON, which is alright, but we'd like to be able to index the content by the custom fields (and not have to loop through each record in the database to find what we're looking for).
Any ideas on how to fix this?
thanks!
david barratt
I guess your plugin file ( for example, "yourplugin.php" ) will have one method called "onContentPrepareForm". If you want to add data to an article, this method should start like this:
function onContentPrepareForm($form, $data)
{
if (!($form instanceof JForm))
{
$this->_subject->setError('JERROR_NOT_A_FORM');
return false;
}
// Check we're manipulating an
if ( $form->getName() != "com_content.article" ) {
return true;
}
//[...] The rest of your code here
Besides, if you want to store these fields in another table in order to make it easier to search using this fields, maybe you should create a new table and save the data using the "onContentAfterSave" method:
public function onContentAfterSave( $context, &$article, $isNew )
On this method, you should always check that $context is "com_content.article", otherwise you might face problems when saving categories.
I hope it helps!

Resources