How to use Chatter in Odoo? - odoo

I want to use Chatter for students model, so that, when value of some field is changed then it is logged under student form
To achieve this, I did the following things:
1. Added this div
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread"/>
</div>
in the student form.
It added the chatter, but when i clicked on New Message button, it gave the following error.
This could be because i haven't inherited mail.thread in student model.
Then i inherited this class in student model.
Then it again gave an error as shown below
I search this topic, but couldn't found anything.
It would be appreciated if someone could help me out.

In order to log changes of specific fields you need so set the track_visibility attribute on each field you want to track:
class OpStudent(models.Model):
_name = 'op.student'
_inherits = {
'res.partner': 'partner_id',
}
_inherit = [
'mail.thread',
'ir.needaction_mixin',
]
foo = fields.Char(track_visibility='always')
You may read more about it in the official documentation.

You're using Chatter for keeping the track on student details.
So I'll suggest another module which is working absolutely fine and keeps the track on student or any other model you want as I have personally used it.
I used audit log. It tracks all the CRUD operations. It will create Audit
the menu in setting tab from there you can set the model which you want to track.
For reference you can check this image also.

I had the same problem, but with res.company, I solved it like this:
class ResCompany(models.Model):
_name = 'res.company'
_inherit = ['res.company','mail.thread', 'mail.activity.mixin']
date_end = fields.Date(string="Fin Date",tracking=True)
and in xml:
<xpath expr="//form/sheet" position="after">
<div class="oe_chatter">
<field name="message_follower_ids" widget="mail_followers"/>
<field name="message_ids" widget="mail_thread" />
</div>
</xpath>
I hope, that it serves you.

Related

Odoo Overwrite delete record confirmation dialog

Hello I need to add some information to the delete record confirmation dialog on Odoo 12, adding some information of how many dependent records will be deleted. Something like:
Are you sure you want to delete this record ?
Doing this you will lose N records.
Currently is defined on "addons/web/static/src/js/views/basic/basic_controller.js" on _deleteRecords method. But if I change it there it will be changed for all my modules.
I'm wondering if there is a method to overwrite this... Or my other idea is to hide the button and use a wizard to do it.
any idea?
By default odoo can do that from xml file but if you need dynamic message than
please create one transient model for wizard and this model have two fields which is your message field and your main form view id after that you simply override the method unlink and in method do your computations if you want confirmation in deletion then return from that condition like this:
return{
'type':'ir.actions.act_window',
'name':'Message',
'res_model':'your.wizard.model',
'view_type':'form',
'view_mode':'form',
'target':'new',
'context':{'thesis_obj':self.id,'text_message_field':'course Work completed'},
'res_id':value.id
}
After wizard opened you have your wizard's form view right?
in wizard form view if user click on OK button then call your original method from which you have to do it in first place.
Wizard View Reference:
<record id="wizard_message_form_view" model="ir.ui.view">
<field name="name">Approval Message</field>
<field name="model">your.wizard.model</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Message">
<separator string="Message" colspan="6"/>
<field name="text_message" colspan="4" nolabel="1" readonly="1" widget="html"/>
<newline/>
<separator colspan="6"/>
<footer>
<button name="btn_approve_oric" type="object" string="OK" class="oe_highlight"/>
<button special="cancel" string="No"/>
</footer>
</form>
</field>
Feel free to ask.

Odoo conditional readonly field on One2many field disappears

I've a conditional readonly field in the view of a model. This model is used as a One2many field on it's parent model.
When I edit one of the elements of the One2many field, click another of the elements the value of the field that has the conditional readonly disappears.
In my searches for this problem I've found the next related issue on odoo github.
My problem is quite similar, but the value of the field completely disappears when the readonly condition is False. When the condition is True the value reappears after clicking outside of the element (another element or outside of the form).
Basically, the models are:
One2many class:
class ChildClass(models.Model):
_name = 'child.class'
some_field = fields.Integer()
conditional_field = fields.Boolean()
conditional_readonly_field = fields.Integer()
parent_field = fields.Many2one(
'parent.class'
)
Parent class:
class ParentClass(models.Model):
_name = 'parent.class'
one2many_field = fields.One2many(
'child.class',
'parent_field'
)
View
<odoo>
<data>
<record model="ir.ui.view" id="view_draft_order_form">
<field name="name">parent.class.form</field>
<field name="model">parent.class</field>
<field name="arch" type="xml">
<form>
<field name="one2many_field">
<form>
<field name="some_field"/>
<field name="conditional_readonly_field" attrs="{'readonly': [('conditional_field', '=', True)]}"/>
</form>
</field>
</form>
</field>
</data>
<odoo>
So, the value of the conditional_readonly_field disappears after editing some_field and clicking on another element of the One2many field. The problem is that it may be after the first, second or some number of clicks (I've been trying and it's not consistent).
For the record, when the readonly condition is removed, the problem disappears.
Thanks in advance for any suggestions!
Yes, It will disappear when you give readonly attributes.
For overcome this problem, pass the value in create method as well in the write method. This will solve your problem.

Odoo : override "create_attendees()" method

I'm working on Odoo 8.
I added a smart button on my partner form to display the current opportunities of the partner. When i click on the button, i want to open the list of the filtered opportunities. This works, but not in a list of opportunities (should be crm_case_tree_view_oppor); it opens a list of leads (with my opportunities inside ??? > crm_case_tree_view_leads).
And so, when i click on the create button (on the top of the list), it opens the lead form and not the opportunity form.
Here's my code :
Smart button in my inherited partner form :
<button class="oe_inline oe_stat_button" type="action" name="%(action_current_opportunity_partner_list)d" icon="fa fa-star-o">
<field string="Opp. en cours" name="opportunity_current_count" widget="statinfo"/>
</button>
And the associated action :
<record id="action_current_opportunity_partner_list" model="ir.actions.act_window">
<field name="domain">[('partner_id.id', '=', active_id), ('probability', '!=', 0), ('probability', '!=', 100)]</field>
<field name="view_mode">tree,form</field>
</record>
How can i tell Odoo to open the list of opportunities (crm.crm_case_tree_view_oppor) and after, make the button create to create an opportunity and not a lead ?
You need to add a view_id on your ir.actions.act_window like:
<field name="view_id" ref="crm.crm_case_tree_view_oppor" />
Don't forget to set crm in your module dependencies (__openerp__.py)
For the second Problem (create) add a context to your action:
<field name="context">{'stage_type': 'opportunity', 'default_type': 'opportunity', 'default_user_id': uid, 'needaction_menu_ref': 'sale.menu_sale_quotations'}</field>
That one is just copied from the window action behind the Opportunities menu item.
So i just replace my button with this :
<button class="oe_inline oe_stat_button" type="action" name="crm.crm_case_category_act_oppor11" icon="fa fa-star" context="{'search_default_partner_id': active_id}">
<field string="Opportunités" name="opportunity_total_count" widget="statinfo"/>
</button>
Just change the name to "crm.crm_case_category_act_oppor11" and erase my own actions.
Works now.
The list worked before, button not the "Create" button. I haven't any explanations.

different view form for edit and create in odoo

I'd like to know is it possible to have different form views for edit mode and create mode in odoo ?
Actually I just want to hide some elements in create mode and show it in edit mode.
I've tried to using attrs like :
<button name="%(print_invoice)d" string="Cetak Struk" type="action" attrs="{'invisible':[('id', '!=', False)]}" />
But when i open the form it gives me error like this :
Uncaught Error: Unknown field id in domain [["id","!=",false]]
Any help would be appreciated.
Thank you
I have used attrs="{'invisible': [('id', '=', False)]}" to hide a field on creation. You must have id as a (hidden) field in your view, like <field name="id" invisible="1" />
you can easily work around this by using "create_date" as a trafic light.
1st expose the field
# make creation date visible
create_date = fields.Date(
'Data',
invisible=False,
readonly=True,
)
then add it to the form and use it into attrs property
<field name="create_date" invisible="1" />
<ELEM attrs="{'invisible': [('create_date', '!=', False)]}">
[...]
</ELEM>
You can have different views for read, edit and create like this if desired
<div class="oe_read_only">
READ ONLY
</div>
<div class="oe_edit_only" attrs="{'invisible':[('id', '=', False)]}">
EDIT ONLY
</div>
<div attrs="{'invisible':[('id', '!=', False)]}">
CREATE ONLY
</div>
#qatz
You cannot have different views based on "Edit" or "Create" of record.
You can try this by adding "state" field and based on the value of state you can hide show the elements.
Hope this helps !!

One Module fields use in other module

I am trying to use some fields of "Job Positions" in "Opportunities" and we can say it as a merger fields. but i am unable to do this task . i have no knowledge about Python language.
I have created a user defined fields and use it in opportunities by XML coding by developer options . I know that it is easy because user defined fields has "crm.lead" named module which is same in opportunities.
but now When i want to use this fields in "hr.job" then it give me error "fields not found" . i know that this fields is not in current module and it is part of "crm.lead" not "hr.job".
Is it possible to use one module fields in another module?
Yes you can do so. First you have to create an object for that and then browse the record and fetch the value of the field which you want.
For example create one method and then browse the crm.lead record:
crm_obj = self.pool.get('crm.lead')
crm_brw = crm_obj.browse(cr, uid, crm_rec_id, context=context)
print "my field value:: ", crm_brw.your_field
Here, "crm_rec_id" is the id of the record of crm.lead object
There are lots of examples given in addons.
yes you can it done by _inherits.
for eg.
hr_job in hr module .
class hr_job(osv.osv):
_name = "hr.job"
_description = "job position"
_columns = {
'name': fields.char('job name', size=64)
}
crm_lead in crm module.
class crm_lead(osv.osv):
_name = "crm.lead"
_inherits = {'hr.job': 'job_id'}
_description = "Lead/Opportunity"
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner')
}
in xml file of crm create form view.
<record id="crm_lead_form" model="ir.ui.view">
<field name="name">crm.lead</field>
<field name="model">crm.lead</field>
<field name="arch" type="xml">
<form>
<field name="name"/> # job name from hr_job
<field name="partner_id"/> # partner_id from crm.lead
</form>
</field>
</record>
don't forget add dependency.