Odoo: how to change title on wizard form view? - odoo

Odoo generates form with default "Odoo" title. I want to write my own title, how to do that?
here is also .xml fo this form:
<record model="ir.ui.view" id="email_compose_message_wizard_form">
<field name="name">mail.compose.message.form</field>
<field name="model">mail.compose.message</field>
<field name="groups_id" eval="[Command.link(ref('base.group_user'))]"/>
<field name="arch" type="xml">
<form string="Compose Email">
<div style="display_none">
<group>
<!-- truly invisible fields for control and options -->
<field name="composition_mode" invisible="1"/>
<field name="model" invisible="1"/>
<field name="res_id" invisible="1"/>
<field name="is_log" invisible="1"/>
<field name="parent_id" invisible="1"/>
...
and .py model:
class MailComposer(models.TransientModel):
_name = 'mail.compose.message'
_inherit = 'mail.composer.mixin'
_description = 'Email composition wizard'
_log_access = True
_batch_size = 500

When the action name is set, Odoo will use it as a title for the dialog
if (action.target === "new") {
cleanDomFromBootstrap();
const actionDialogProps = {
// TODO add size
ActionComponent: ControllerComponent,
actionProps: controller.props,
};
if (action.name) {
actionDialogProps.title = action.name;
}
Odoo will try to use the action name first then the default title (Odoo)

Related

Odoo 11 - pull fields values from other models

I have added a custom field (many2one) in crm.lead form and a custom class for that
Here is my code (I am using odoo 11):
models.py
from odoo import models, fields, api
# Add fields to Leads
class Leads_events(models.Model):
_inherit = 'crm.lead'
venue = fields.Many2one('crm.lead.venue',String="Venue")
venue_city = fields.Char(String="City")
venue_country = fields.Many2one('res.country', string="Country")
# Create venue class
class Leads_venue(models.Model):
_name = 'crm.lead.venue'
name = fields.Char(string="Venue name")
city = fields.Char(string="City")
country = fields.Many2one('res.country', string="Country")
address = fields.Text(string="Address")
website = fields.Char(string="Website")
phone = fields.Char(string="Phone")
fax = fields.Char(string="Fax")
notes = fields.Text(string="Notes")
views.xml
<record id="crm_lead_venue_form" model="ir.ui.view">
<field name="name">crm.lead.venue.form</field>
<field name="model">crm.lead.venue</field>
<field name="arch" type="xml">
<form string="Venues">
<group>
<group>
<field name="name"/>
<field name="country"/>
<field name="city"/>
<field name="address"/>
</group>
<group>
<field name="phone"/>
<field name="fax"/>
<field name="website"/>
</group>
<group>
<field name="notes" />
</group>
</group>
</form>
</field>
</record>
<record id="crm.crm_case_form_view_oppor_events" model="ir.ui.view">
<field name="name">crm_case_form_view_oppor_events</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<xpath expr="//notebook" position="before">
<group string="Venue">
<field name="venue"/>
<field name="event_city" string="City"/>
<field name="event_country"/>
</group>
</xpath>
</field>
</record>
This works fine. Now what I am trying to pull is the city and country from crm.lead.venue selected record to crm.lead 'venue_city' and 'venue_country' fields.
I looked at onchange function but I cannot find how to make it work...
I've tried this following another post I read but it is not working
#api.onchange('venue')
def onchange_venue(self):
if self.venue:
self.event_city = self.venue.city
self.event_country = self.venue.country
Is there anywhere I can find a documentation or help more complete on this ? The official documentation is not very precise on this matter.
The onchange method works when the user change the field in the view, and I cant see the field on your view, so the method would be never be called. You should add "venue" field to the form and test it again.
Edit
Have you seen that it is not event_city but venue_city? The onchange should be on leads_events. Did you test that onchange is executed and has no value? Or it doesnt even execute the function ?
#api.onchange('venue')
def onchange_venue(self):
if self.venue:
self.venue_city = self.venue.city
self.venue_country = self.venue.country

Domain for on field based on another

In task templates form i can add group_id. I want to make a domain that will add task templates depending in what group they belong but kinda have no clue now.
class ProjectTaskGroup(models.Model):
_name = 'project.task.group'
_inherit = 'project.object'
name = fields.Char(string="Name", required=True)
class ProjectTaskTemplate(models.Model):
_name = 'project.task.template'
_inherit = 'project.object'
name = fields.Char(string="Name", required=True)
group_id = fields.Many2one('project.task.group', string="Task Group")
<!-- Project Task Views -->
<record id="view_task_form2" model="ir.ui.view">
<field name="name">project.task.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2"/>
<field name="arch" type="xml">
<xpath expr="//div[#class='oe_title']" position="before">
<div class="oe_inline oe_edit_only">
<field name="group_id" class="oe_inline"/>
<field name="task_template_id" class="oe_inline"/>
</div>
</xpath>
</field>
</record>
First add field in model 'project.task.group'
template_id = fields.One2many('project.task.template', 'group_id', string='Group task')
Field of 'project.task'
task_template_id = field.Many2one('project.task.template')
group_id=field.Many2one('project.task.group')
In view of 'project.task'
<field name="task_template_id" class="oe_inline"/>
<field name="group_id" class="oe_inline" domain="[('template_id', '=', task_template_id)]"/>
first select template so we get group_id belogs to task_template_id

Pass data to many2one widget

I have a custom module with the following simple data structure:
class Site(models.Model):
_name = 'sites.site'
site_name = fields.Char(string="Site Name")
contact_in_site_role_ids = fields.One2many(comodel_name="sites.contact_in_site_role", inverse_name="site_id", string="Site Contacts", required=False, )
class SiteRole(models.Model):
_name = "sites.site_role"
role_name = fields.Char(string="Role Name")
class ContactInSiteRole(models.Model):
_name = "sites.contact_in_site_role"
site_id = fields.Many2one("sites.site",string="Site")
contact_id = fields.Many2one("res.partner",string="Contact")
role_id = fields.Many2one("sites.site_role",string="Site Role")
role_detail = fields.Char(string="Role details")
This is currently managed by the following form:
<record model="ir.ui.view" id="site_form_view">
<field name="name">site.form</field>
<field name="model">sites.site</field>
<field name="arch" type="xml">
<form string="Site Form">
<sheet>
<group>
<field name="site_name"/>
</group>
<notebook>
<page string="Site Contacts">
<field name="contact_in_site_role_ids" widget="one2many_list">
<tree>
<field name="contact_id"/>
<field name="role_id"/>
<field name="role_detail"/>
</tree>
</field>
</page>
</notebook>
</sheet>
</form>
</field>
</record>
This works well, apart from when clicking to add a contact on the Many2One widget on the "Edit Site Form", it prompts again for the site. How do I remove the "Site" option from this popup form, and have the relevant site passed from the parent form:
Try to pass like below and see
<field name="contact_in_site_role_ids" widget="one2many_list" context="{'default_site_id':parent.id}"/>
The concept here is we can initialize the child element values by passing them in the context like:
{default_child_field: value}

ODOO 8 on_change

Please I am facing somes problems with the new odoo 8 api, I have the following classes
class TypeProcessus(models.Model):
_name = 'atom.promaintenance.type.processus'
name = fields.Char()
id_phases = fields.One2many('atom.promaintenance.phases','id_processus','Liste des Phases')
class Phases(models.Model):
_name = 'atom.promaintenance.phases'
name = fields.Char()
autoriserCommentaire = fields.Boolean()
autoriserPiecesJointes = fields.Boolean()
id_processus = fields.Many2one('atom.promaintenance.type.processus')
parent_id = fields.Many2one('atom.promaintenance.phases','Phase Parent', select=True, ondelete='cascade')
commentaire = fields.Text()
#api.one
#api.onchange('name')
def phases_write(self):
print 'test'
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<tree string="note_evaluation_tree" editable="bottom">
<field name="id_phases" />
</tree>
</sheet>
</form>
</field>
</record>
First of all my problem is when Creating a new Processus, and adding phases, there is a relation parent child between phases and the drop down list for parent stay empty unless u save the processus to make them available.
i managed to add onChange event to the phases to persist them to database but i can't figure out how to save those records with the new api system, thank you
If you mean what I understand, you need to use the widget one2many_list in the XML code, which by the way, I think is wrong. It should be something like this:
<record model="ir.ui.view" id="atom_promaintenance_type_processus">
<field name="name">atom.promaintenance.type.processus.form</field>
<field name="model">atom.promaintenance.type.processus</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Type Processus" >
<sheet>
<h1>UPDATED</h1>
<field name="name" />
<field name="id_phases" widget="one2many_list">
<tree string="note_evaluation_tree" editable="bottom">
<field name="name"/>
<field name="autoriserCommentaire"/>
<field name="autoriserPiecesJointes"/>
<field name="parent_id"/>
<field name="commentaire"/>
</tree>
</field>
</sheet>
</form>
</field>
</record>
The widget will allow you to add phases for a processus and then save it.
The new API uses self for all the record modifications. So in your case, if you want to change the name, write like this:
#api.one
#api.onchange('name')
def onchange_name(self):
self.name = 'what you want to save'

Custom Module Add Customers Automatically in Openerp

I have a custom module where i have inherited res.partner.I have a field "doctor"(which is many2one field).When i create a customer i can select a doctor.In img 1 Willam is the customer and he has selected Nitesh as the doctor.I have created doctor_view.xml which will show all the details of the Doctor.Now in img 2 , as we have selected "Nitesh" as 'Doctor' for 'Customer Willam',i should display "Willam" under "Client" in img2. Can anyone help me in this?Thanks in advance
My code
Customer.py
from qrcode import *
from osv import osv
from osv import fields
class res_partner(osv.osv):
_inherit = "res.partner"
_description = "adding fields to res.partner"
_columns = {
'doctor': fields.many2one('crm.lead.doctor','Doctor'),
}
class crm_lead_doctor(osv.osv):
_name = "crm.lead.doctor"
_order = "name"
_columns ={
'name':fields.char('Doctor Name',required=True,size=64,translate=True),
'doctor_id':fields.char('Doctor Id',size=64,readonly=True),
'doctor_mobile': fields.char('Mobile',required=True,size=64),
'doctor_email': fields.char('Email',size=64),
'doctor_hospital': fields.many2one('crm.lead.hospital','Hospital'),
'doctor_street': fields.char('Street', size=128),
'doctor_street2': fields.char('Street2', size=128),
'doctor_zip': fields.char('Zip', change_default=True, size=24),
'doctor_city': fields.char('City', size=128),
'doctor_state_id': fields.many2one("res.country.state", 'State'),
'doctor_country_id': fields.many2one('res.country', 'Country'),
'doctor_brochure': fields.char('Brochuer',size=64),
'doctor_flyer': fields.char('Flyer',size=64),
'doctor_training': fields.char('Training',size=64),
'doctor_starterpacksent': fields.char('Strater pack sent',size=64),
'doctor_no_of_deliveries': fields.char('No of Deliveries/year',size=64),
'doctor_fee': fields.char('Fee',size=64),
'doctor_registration': fields.char('Registration No',size=64),
'doctor_pancard': fields.char('Pan Card No',size=64),
'doctor_fiscalcode': fields.char('Fiscal Code',size=64),
'doctor_iban': fields.char('IBAN',size=64),
'doctor_contractset': fields.char('Contract Set',size=64),
'doctor_contractrecieved': fields.char('Contract Recieved',size=64),
'doctor_clients':fields.many2many('res.partner')
}
def create(self, cr, uid, vals, context={}):
doc_seq = self.pool.get('ir.sequence').get(cr, uid, 'master.doctor')
vals['doctor_id'] = doc_seq
res = super(res_partner.crm_lead_doctor, self).create(cr, uid, vals, context)
return res
Doctor_view.xml
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="view_doctor_form_extended" model="ir.ui.view">
<field name="name">crm.lead.doctor.form</field>
<field name="model">crm.lead.doctor</field>
<field name="arch" type="xml">
<form string="Doctor Details" version="7.0">
<group>
<field name="name"/>
<!-- <field name="doctor_id"/> -->
<field name="doctor_mobile"/>
<field name="doctor_email"/>
<field name="doctor_hospital"/>
<label for="street" string="Doctor Address"/>
<div>
<field name="doctor_street" placeholder="Street..."/>
<field name="doctor_street2"/>
<div class="address_format">
<field name="doctor_city" placeholder="City" style="width: 40%%"/>
<field name="doctor_state_id" on_change="onchange_state(state_id)" options='{"no_open": True}' placeholder="State" style="width: 24%%"/>
<field name="doctor_zip" placeholder="ZIP" style="width: 34%%"/>
</div>
<field name="doctor_country_id" placeholder="Country" options='{"no_open": True}'/>
</div>
</group>
<notebook>
<page string="Sales">
<group>
<group>
<field name="doctor_brochure"/>
<field name="doctor_flyer"/>
<field name="doctor_training"/>
<field name="doctor_starterpacksent"/>
<field name="doctor_no_of_deliveries"/>
<field name="doctor_fee"/>
</group>
<group>
<field name="doctor_registration"/>
<field name="doctor_pancard"/>
<field name="doctor_fiscalcode"/>
<field name="doctor_iban"/>
<field name="doctor_contractset"/>
<field name="doctor_contractrecieved"/>
</group>
</group>
</page>
<page string="Clients">
<field name="doctor_clients"/>
</page>
</notebook>
</form>
</field>
</record>
<record id="view_doctor_tree_extended" model="ir.ui.view">
<field name="name">crm.lead.doctor.tree</field>
<field name="model">crm.lead.doctor</field>
<field name="arch" type="xml">
<tree string="Doctor Details" version="7.0">
<field name="doctor_id"/>
<field name="name"/>
<field name="doctor_mobile"/>
<field name="doctor_email"/>
<field name="doctor_hospital"/>
</tree>
</field>
</record>
<record id="new_doctor" model="ir.actions.act_window">
<field name="name">Doctors</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">crm.lead.doctor</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="view_id" ref="view_doctor_tree_extended"/>
</record>
<!-- ===========================Menu Settings=========================== -->
<menuitem name ="Doctors - Hospitals" id = "menu_lead" />
<menuitem name="Doctors" id="sub_menu_lead" parent="menu_lead" />
<menuitem name="Doctors" id="create_lead" parent="sub_menu_lead" action="new_doctor"/>
</data>
</openerp>
that's a perfect example for a one2many relationship between doctor-client. if you would realise it that way in openerp, you will have the clients shown in your doctor-view.
many2many would make sense, if your client has more than one doctor.
little hint: 'doctor_clients':fields.one2many('res.partner','doctor')
from qrcode import *
from osv import osv
from osv import fields
class res_partner(osv.osv):
_inherit = "res.partner"
_description = "adding fields to res.partner"
_columns = {
'doctor': fields.many2one('crm.lead.doctor','Doctor'), #the so called relation_field for the one2many relation to crm.lead.doctor
}
class crm_lead_doctor(osv.osv):
_name = "crm.lead.doctor"
_order = "name"
_columns ={
'name':fields.char('Doctor Name',required=True,size=64,translate=True),
'doctor_id':fields.char('Doctor Id',size=64,readonly=True),
'doctor_mobile': fields.char('Mobile',required=True,size=64),
'doctor_email': fields.char('Email',size=64),
'doctor_hospital': fields.many2one('crm.lead.hospital','Hospital'),
'doctor_street': fields.char('Street', size=128),
'doctor_street2': fields.char('Street2', size=128),
'doctor_zip': fields.char('Zip', change_default=True, size=24),
'doctor_city': fields.char('City', size=128),
'doctor_state_id': fields.many2one("res.country.state", 'State'),
'doctor_country_id': fields.many2one('res.country', 'Country'),
'doctor_brochure': fields.char('Brochuer',size=64),
'doctor_flyer': fields.char('Flyer',size=64),
'doctor_training': fields.char('Training',size=64),
'doctor_starterpacksent': fields.char('Strater pack sent',size=64),
'doctor_no_of_deliveries': fields.char('No of Deliveries/year',size=64),
'doctor_fee': fields.char('Fee',size=64),
'doctor_registration': fields.char('Registration No',size=64),
'doctor_pancard': fields.char('Pan Card No',size=64),
'doctor_fiscalcode': fields.char('Fiscal Code',size=64),
'doctor_iban': fields.char('IBAN',size=64),
'doctor_contractset': fields.char('Contract Set',size=64),
'doctor_contractrecieved': fields.char('Contract Recieved',size=64),
'doctor_clients':fields.one2many('res.partner','doctor','Clients') #here we use 'doctor' the new field of res.partner as relation_field to bind the relation
}
def create(self, cr, uid, vals, context={}):
doc_seq = self.pool.get('ir.sequence').get(cr, uid, 'master.doctor')
vals['doctor_id'] = doc_seq
res = super(res_partner.crm_lead_doctor, self).create(cr, uid, vals, context)
the views are just fine
return res
If I understand correctly you want to see the customer under the doctor's clients?
The customer will show under the doctor's clients only once you save the customer. Before you save, the link is not created so it wont show in the doctor's form view.
If you save the customer, and then open the doctor it should show as a client.