Document path odoo 8 - action

I have created a kanban view for Document management system to show folders and files. To do this i have created an action. Each time i click on folder the document path above the save button displays the action name instead folder name. i need to display the folder name please help!!
Code:
<record model="ir.actions.act_window" id="action_ams_document_file_directory_form1">
<field name="type">ir.actions.act_window</field>
<field name="res_model">document.directory</field>
<field name="name">Folder</field>
<field name="view_type">form</field>
<field name="view_mode">kanban,tree,form</field>
<field name="view_id"
ref="3e_apartment_management.view_document_sub_directory_kanban" />
<field name="domain">[('parent_id','=',active_id)]</field>
<field name="context">{'parent_id':active_id}</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">
This folder is empty.
</p>
<p>
Click on 'Create' button to add new folder.
</p>
</field>
</record>
Attached screen shots:

You could try using the name_get method. This will set the name that will be displayed on top of the page.
In the following code "%s" % (record.name) can be changed to your own value or method that returns the value for the record
example old api
def name_get(self, cr, uid, ids, context=None):
return [(record.id, "%s" % (record.name))
for record in self.browse(cr, uid, ids, context=context)]
example new api
#api.multi
def name_get(self):
return [(record.id, "%s" % (record.name))
for record in self]

Related

Send an Email to multiple customers containing multiple products

I'm trying to send an email to multiple partners containing multiple products with Odoo.
#OdepoOffer.py
# -*- coding: utf-8 -*-
from openerp import models, fields, api
"""
Class nomRelation Pour la gestion des noms des relations
"""
class odepoOffer(models.Model):
_name = 'odepo.offer'
name = fields.Char('Nom Offre' ,size=32)
odepoContactId = fields.Many2many('res.partner', ondelete='no action', string="Panier Clients")
odepoProductId = fields.Many2many('product.product', ondelete='no action', string="Panier Produits")
#api.multi
def email_partner(self):
'''
This function opens a window to compose an email, with the edi sale template message loaded by default
'''
self.ensure_one()
ir_model_data = self.env['ir.model.data']
try:
compose_form_id = ir_model_data.get_object_reference('mail', 'email_compose_message_wizard_form')[1]
except ValueError:
compose_form_id = False
# It's worth noting that Odoo 9 uses 'mail.template' whereas Odoo 8 uses 'email.template'
# template_id = self.env['email.template'].search([('name', '=', 'Odepo Offer')], limit=1)
ctx = dict()
ctx.update({
'default_model': 'res.partner',
'default_res_id': False,
'default_use_template': True,
'default_template_id': False,
'default_composition_mode': 'comment',
'email_to':'testmail#gmail.com',
'subject':'mario',
'skip_notification': True,
})
return {
'type': 'ir.actions.act_window',
'view_type': 'form',
'view_mode': 'form',
'res_model': 'mail.compose.message',
'views': [(compose_form_id, 'form')],
'view_id': compose_form_id,
'target': 'new',
'context': ctx,
}
# values['subject'] = val
# values['email_to'] = val1
# values['body_html'] = val2
# values['body'] = val3
# values['res_id'] = False
# values['attachment_ids'] = val4
and the view:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_odepo_offer_tree">
<field name="name">odepo.offer.tree</field>
<field name="model">odepo.offer</field>
<field name="arch" type="xml">
<form string="Odepo Offre">
<group>
<field name="name" string="Name"/>
<field name="odepoContactId" widget="many2many_tags" options="{'no_create_edit': True}"/>
<field name="odepoProductId" widget="many2many_tags" options="{'no_create_edit': True}"/>
<button name="email_partner" type="object" string="Create Email" class="oe_highlight"/>
</group>
</form>
</field>
</record>
<!--<record id="odepo_offer_email_header_form" model="ir.ui.view">
<field name="name">odepo.offer.header</field>
<field name="model">odepo.offer</field>
<field name="inherit_id" ref="view_odepo_offer_tree"/>
<field name="arch" type="xml">
<xpath expr="//form/sheet" position="before">
<button name="email_partner" type="object" string="Create Email" class="oe_highlight"/>
</xpath>
</field>
</record>-->
<act_window id="action_view_wizard" name="Mr" res_model="odepo.offer" view_mode="tree,form"/>
<menuitem name="Gestion Des Offres" id="gestion_offer_id" parent="odepo_contact.odepo_config_id" sequence="10" />
<menuitem name="Noms Des Offres" id="sub_gestion_offer_id" parent="gestion_offer_id" sequence="11" action="action_view_wizard"/>
</data>
</openerp>
For now, i'm able to create an offer and name it and fill the odepoContactId with my contacts, and odepoProductId with my products.
Then, i click on the button send email, i have a wizard that pop up with the mail compose. The problem, is that i'm unable to add the contacts in my odepoContactId field to the recipients in the mail compose that pop up in the wizard. I Tried to pass an email adress throw the context but with no luck
You need to inherit "mail.compose.message" model because in that model all partners are there. In that model "partner_ids" are there which is may2many relation with "res.partner"
You can take reference from Sales

Odoo hide "Create" and "Edit" buttons depend on state and role

I would like to hide "Create" and "Edit" buttons on state and group role in form view .For example hide Create and Edit buttons when the state is not draft and user belongs to request user group.
As I understand hide buttons I can on editing views. And on group role rules I can disable create or edit.
I tried to write a rule for request user group but then user can't use the button but see it.
From view I found only way to hide default Create and Edit buttons:
<form string="Request" create="false" edit="false">
But in that way I hide them for all users for all states. Is there another way how can I hide Create and Edit buttons depend on state and group role?
I tried to expand the base.xml template on conditions state is "approved" or "done" and the group role is purchase_request_user and view id is view_purchase_request_form "Create" and "Edit" button:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space='preserve'>
<t t-extend="FormView.buttons">
<t t-if="widget.fields_view.state !== 'done' or widget.fields_view.state !== 'approved'">
<div class="o_form_buttons_view">
<button t-if="widget.is_action_enabled('edit')"
type="button"
class="oe_form_button_edit btn btn-default btn-sm" accesskey="E">
Edit
</button>
<button t-if="widget.is_action_enabled('create')"
type="button" class="oe_form_button_create btn btn-default btn-sm"
accesskey="C">
Create
</button>
</div>
</t>
</t>
</templates>
added 'base' to dependences.
UPDATED base.xml Now I can change "Create" button name depend on my view name but nothing that depends on my module states.
<templates>
<t t-extend="FormView.buttons">
<t t-jquery="button.oe_form_button_create" t-operation="replace">
<t t-if="widget.fields_view.name == 'purchase.request.form'">
<button t-if="widget.is_action_enabled('create')"
type="button" class="oe_form_button_create btn btn-default btn-sm"
accesskey="C">
New button name
</button>
</t>
</t>
</t>
</templates>
My form view xml peace:
<openerp>
<data>
<record model="ir.ui.view" id="view_purchase_request_form">
<field name="name">purchase.request.form</field>
<field name="model">purchase.request</field>
<field name="arch" type="xml">
<form string="Purchase Request" create="false" edit="false">
<header>
<button name="%(action_sale_order_reset)d" attrs="{'invisible': [('state','not in', ('to_approve_first'))]}" string="Reset" type="action" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_to_approve_first" states="draft" string="Request approval" type="object" class="oe_highlight"/>
<button name="button_approved" states="to_approve_first" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_approvedd" states="approved" string="Return Request" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_create_order" states="approvedd" string="Create Order" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_user"/>
<button name="button_to_approve_second" states="create_order" string="Approve" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_approved2" states="to_approve_second" string="Done" type="object" class="oe_highlight" groups="purchase_request.group_purchase_request_manager"/>
<button name="button_rejected" states="draft,approvedd" string="Reject" type="object" groups="purchase_request.group_purchase_request_user"/>
<field name="state" widget="statusbar" statusbar_visible="draft,to_approve_first,approved,rejected" statusbar_colors="{"approved":"green"}"/>
</header>
<sheet>
<group>
<group>
<field name="date_start" readonly="1"/>
<field name="participate_process"/>
</group>
<group>
<field name="requested_by" readonly="1"/>
<field name="assigned_to" attrs="{'readonly': [('state','not in', ('draft'))]}" />
</group>
<notebook>
<page string="Order" attrs="{'invisible': [('state','in', ('draft', 'to_approve_first', 'approved', 'approvedd'))]}">
<field name="supply_ids" attrs="{'readonly': [('state','not in', ('to_approve_second'))]}"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
You have to write a template inheriting the 'FormView.buttons' one, check the context fields, like groups and state, and put a condition based on the wanted fields.
Something like this:
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space='preserve'>
<t t-extend="FormView.buttons">
<t t-if="widget.fields_view.state == <wanted_state>">
<your operations>
</t>
</t>
</templates>
Using this you can inspect all the FormView widget fields, you can find it in /odoo/addons/web/static/src/js/views/form_view.js.
I also found datarecord inside it, which should contain your state info and value.
Then, if you want to do the same with the buttons in edit mode, replace '.o_form_buttons_view' with '.o_form_buttons_edit'.
Tell me if you have problems. And again sorry for the delay, I was a little busy.
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_buttons_view" t-operation="before">
<t t-log="widget"/>
</t>
</t>
Thank you! #Michele Zaccheddu using your answer I can get many types of the widget using
<t t-extend="FormView.buttons">
<t t-jquery=".o_form_buttons_view" t-operation="before">
<t t-log="widget"/>
</t>
</t>
Just put the code as a test and after update apps - go to form view, check using browser Developer Tools, In the console you will get the list from "Class", I'm using odoo 11 and can target
<t t-if="widget.initialState.data.state === 'draft'">
For other versions, please check the t-log yourself it can be different, but I haven't check for user group it may or may not be there...

message_post on change of state odoo

I am trying to post message on openchatter on state change. i used the following good but nothing happened.
in .py file.
#api.one
#api.depends('state')
def log_prod(self,state):
if state in ["i"]:
msg="Dear User: your account has been update"
return self.message_post(body=msg)
state = fields.Selection([('i','Internship'),('j','Joined')])
on xml
<field name="state" widget="statusbar" statusbar_visible="i,j"/>
Even no error. Thanks in advance
Use #api.onchange('state') instead of #api.depends('state')
#api.onchange('state')
def log_prod(self,state):
if state in ["i"]:
msg="Dear User: your account has been update"
return self.message_post(body=msg)
#api.onchange('state')
def log_prod(self):
if self.state in ["i"]:
msg="Dear User: your account has been update"
return self.message_post(body=msg)
Just add argument tracking=True, in the state field. That's it.
To Enable chatter first you need to inherit your model from mail.mesage class Example:
class sale_order(osv.osv):
_name = "sale.order"
_inherit = ['mail.thread']
This will enable chatter functionality on your Model, now next thing you need todo is:
<record id="view_order_form" model="ir.ui.view">
<field name="name">sale.order.form</field>
<field name="model">sale.order</field>
<field name="arch" type="xml">
<form string="Sales Order" version="7.0">
...
</form>
<sheet>
...
</sheet>
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers" groups="base.group_user"/>
<field name="message_ids" widget="mail_thread"/>
</div>
</field>
</record>
this will add chatter in your form view and then your message_post will show up.
code :
<field name="state" widget="statusbar" statusbar_visible="i,j"/>
is for statusbar not for chatter.
Bests

Joomla Template Paramenter Type Menu Assignment

I use Joomla 3.2.1.
I create a new template and add some configuration parameter.
Now I need in my advanced configuration a selection, where I can set the menu assignment for a slideshow in my template. The Slideshow is html / javascript (jquery). I can enable/disable it in configuration.
But I want to assign it to menu item. Is there a configuration parameter type for this? I couldnt find.
my configuration looks like:
<config>
<fields name="params" >
<fieldset name="advanced">
<field type="spacer" label="Slideshow" />
<field name="isSlideshow" type="radio"
class="btn-group btn-group-yesno"
default="1"
label="Slideshow">
<option value="1">JYES</option>
<option value="0">JNO</option>
</field>
<!-- add menu assingment-->
<field type="menut assignment???"....>
<field name="slide1" type="media" default=""
label="Slide 1"/>
<field name="slide2" type="media" default=""
label="Slide 2"/>
<field name="slide3" type="media" default=""
label="Slide 3"/>
</fieldset>
</fields>
</config>
You should create a module with the slideshow code.
Then assign the module to a position in your template, where you will include the position:
<jdoc:include type="modules" name="slideshow" />
Install the module in the slideshow position, then in the module settings, tab "Menu Assignment", choose "Only on the pages selected";
below you can tick the menu items you want it to show on.
There are a few cases where this is not sufficient, i.e. in the blog view the articles will share the same menu item, but you might want to treat them differently. You have many options here, the best is to create a different - named position in the template, and assign the modules to the appropriate one, i.e.:
<jdoc:include type="modules" name="slideshow-all" />
<jdoc:include type="modules" name="slideshow-articles" />

Field not displaying on list with Content types Inherits="False"

I've defined a content type 'related links' and set Inherits="False" and added line to remove out-of-the-box 'title' field as I don't want it showing in the view or new/edit/display forms, see (OPTION 1) in CAML below.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- ===== Fields ===== -->
<!-- Link Category -->
<Field DisplayName="Link Category"
Name="LinkCategory"
ID="{654EAC00-342B-4176-9D91-613AD724F684}"
Group="Custom"
Overwrite="True"
Type="Lookup"
ShowField="Title"
List="Lists/LinkCategoryList"
WebId="~sitecollection" />
<!-- ===== Content Type ===== -->
<!--
Related Links
- Parent ContentType: Item (0x01)
-->
<ContentType Name="Related Links"
ID="0x0100c11a1db14e564574bc49a2aa9bf325d3"
Group="Custom"
Description=""
Inherits="False"
Version="0">
<FieldRefs>
<!-- Title (OPTION 1) -->
<RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" />
<!-- (OPTION 2)
<FieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}"
Hidden="TRUE" Required="FALSE" DisplayName="_hidden" />
-->
<!-- Link Category -->
<FieldRef DisplayName="Link Category"
Name="LinkCategory"
ID="{654EAC00-342B-4176-9D91-613AD724F684}"
Required="True" />
</FieldRefs>
</ContentType>
</Elements>
This does remove the 'title' field from the content type but when I try to associate the content type with a list it does not display the 'LinkCategory' field in the view or new/edit/display forms. Why is it so?
<?xml version="1.0" encoding="utf-8"?>
<List xmlns:ows="Microsoft SharePoint"
Title="Related Links"
FolderCreation="FALSE"
Direction="$Resources:Direction;"
Url="Lists/RelatedLinksListDefinition"
BaseType="0"
EnableContentTypes="True"
xmlns="http://schemas.microsoft.com/sharepoint/">
<MetaData>
<ContentTypes>
<!-- Related Links -->
<ContentTypeRef ID="0x0100c11a1db14e564574bc49a2aa9bf325d3" />
</ContentTypes>
<Fields>
</Fields>
<Views>
<View ...etc...>
<ViewFields>
<FieldRef Name="LinkCategory"></FieldRef>
</ViewFields>
<Query>
<OrderBy>
<FieldRef Name="ID"></FieldRef>
</OrderBy>
</Query>
</View>
</Views>
<Forms>
<Form Type="DisplayForm" Url="DispForm.aspx"
SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="EditForm" Url="EditForm.aspx"
SetupPath="pages\form.aspx" WebPartZoneID="Main" />
<Form Type="NewForm" Url="NewForm.aspx"
SetupPath="pages\form.aspx" WebPartZoneID="Main" />
</Forms>
</MetaData>
</List>
As a work around I've set Inherits="True" on the content type and used (OPTION 2) in content type CAML and that hides the 'title' field, but would really like to understand what's going on here and what's the best approach to take. Thanks in advance!
PS: This post has similar question: SharePoint 2010: RemoveFieldRef and Inherits="TRUE"
PSS: When I browse via SP Manager 2010 after deploying using OPTION 1, I get the following:
'Link Category' Field created correctly
'Related Links' Content Type created correctly with 'Link Category' field
'Related Links' list created with 'Related Links' Content Type associated
However 'Related Links' list has no reference to 'Link Category' Field.
Ok so was on my way up the garden path...
The issue why 'Link Category' Field was not being created on the 'Related Links' list wasn't related to setting Inherits="False", it was because I had not defined it in the list schema even though I'd defined it in the content type. As mentioned here:
http://msdn.microsoft.com/en-us/library/aa543576.aspx
When SharePoint Foundation creates a list instance, it includes only
those columns that are declared in the base type schema of the list or
in the list schema. If you reference a site content type in the list
schema, and that content type references site columns that are not
included in the base type schema of the list or in the list schema,
those columns are not included. You must declare those columns in the
list schema for SharePoint Foundation to include them on the list.
And here:
http://stefan-stanev-sharepoint-blog.blogspot.com/2010/03/contenttypebinding-vs-contenttyperef.html
One ugly thing about it is that you specify a site content type to be
attached to the list based on that list definition but the framework
doesn’t provision the fields in the content type if they are missing
in the list – so you need to add manually all content type’s fields in
the Fields element of the list schema file. This is actually what I
called the fields’ redefinition issue...
So duplicated Field element below from the content type definition to list schema:
<Fields>
<Field DisplayName="Link Category"
Name="LinkCategory"
ID="{654EAC00-342B-4176-9D91-613AD724F684}"
Group="Custom"
Overwrite="True"
Type="Lookup"
ShowField="Title"
List="Lists/LinkCategoryList"
WedId="~sitecollection" />
</Fields>
I can confirm that using Inherits="False" & <RemoveFieldRef ID="{fa564e0f-0c70-4ab9-b863-0177e6ddd247}" /> does remove the title field.
Here's another good link about Inherits="False" for those who stumble upon this post.
https://sharepoint.stackexchange.com/questions/2995/mysteries-of-the-contenttype-inherits-attribute