message_post on change of state odoo - python-2.7

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

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...

Document path odoo 8

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]

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" />

Joomla ACL custom actions

I'm creating a custom (1.6) component wherein users can book a camp site. Users will be required to log in if they want to use funds/credits that they already have stored. Only certain groups can use these funds/credits.
I have created an access.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<access component="com_propbooker">
<section name="booking">
<action name="booking.create" title="Book Site" description="Allows users of this group to book sites." />
</section>
</access>
and my config.xml file:
<config>
<fieldset name="API Configuration" label="API Configuration">
<field name="google_api_key" label="Google API Key" type="text" size="50" default="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" />
</fieldset>
<fieldset name="Booking Permissions" label="Booking Permissions" description="Set Groups that can book sites">
<field name="booking_permission" label="Booking Permission" type="rules" class="inputbox" validate="rules" filter="rules" component="com_propbooker" section="booking" />
</fieldset>
</config>
It all shows up fine when I click the options button, but no changes are ever saved. It always flips back to "Inherited" when i click the "Save" button.
Thanks in advance for any insight.
Try using permissions as the fieldset name and rules as the fieldname in your config.xml.
Like this:
<fieldset name="permissions"
label="JCONFIG_PERMISSIONS_LABEL"
description="JCONFIG_PERMISSIONS_DESC" >
<field name="rules"
type="rules"
label="JCONFIG_PERMISSIONS_LABEL"
class="inputbox"
validate="rules"
filter="rules"
component="com_propbooker"
section="booking"
/>
</fieldset>
I would also consider using the section name component as it is the default naming. But your needs may be different.