I have defined state actions, buttons, and the workflow. They work just fine, the problem is when I tried to add a clickable statusbar and everytime I click the status bar, it won't actually do anything other than changing the record's state.
How do I link the statusbar to the workflow/actions?
model.py
def action_state_draft(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'draft' })
return True
def action_state_confirmed(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'confirmed' })
return True
def action_state_posted(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'posted' })
return True
def action_state_cancelled(self, cr, uid, ids):
self.write(cr, uid, ids, { 'state' : 'cancelled' })
return True
def hello_world(self):
print "Hello World!"
def hello_world_second(self):
print "Hello World Second!"
model_view.xml
<header>
<button name="action_state_confirmed" string="Confirm" states="draft" />
<button name="action_state_posted" string="Post" states="confirmed" />
<button name="action_state_cancelled" string="Cancel" states="draft,confirmed,posted" />
<field name="state" widget="statusbar" clickable="True" statusbar_visible="draft,confirmed,posted,cancelled"/>
</header>
model_workflow.xml
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="ig_account_voucher_wkf" model="workflow">
<field name="name">ig.account.voucher.wkf</field>
<field name="osv">ig.account.voucher</field>
<field name="on_create">True</field>
</record>
<record id="act_draft" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">draft</field>
<field name="flow_start">True</field>
</record>
<record id="act_confirmed" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">confirmed</field>
<field name="action">
write({'state':'confirmed'})
hello_world()
hello_world_second()
</field>
<field name="kind">function</field>
</record>
<record id="act_posted" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">posted</field>
<field name="action">write({'state':'posted'})</field>
<field name="kind">function</field>
</record>
<record id="act_posted" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">cancelled</field>
<field name="action">write({'state':'cancelled'})</field>
<field name="kind">function</field>
<field name="flow_stop">True</field>
</record>
<record id="transition_draft_confirmed" model="workflow.transition">
<field name="act_from" ref="act_draft"/>
<field name="act_to" ref="act_confirmed"/>
<field name="condition">True</field>
<field name="signal">action_state_confirmed</field>
</record>
<record id="transition_confirmed_posted" model="workflow.transition">
<field name="act_from" ref="act_confirmed"/>
<field name="act_to" ref="act_posted"/>
<field name="condition">True</field>
<field name="signal">action_state_posted</field>
</record>
<record id="transition_confirmed_cancelled" model="workflow.transition">
<field name="act_from" ref="act_confirmed"/>
<field name="act_to" ref="act_posted"/>
<field name="condition">True</field>
<field name="signal">action_state_cancelled</field>
</record>
</data>
</openerp>
Another relevant little question: Why do we need workflow instead of just using buttons and actions?
In your code you have missing commas on workflow action when u pass the multiple method in workflow action.
please make is correct first
<record id="act_confirmed" model="workflow.activity">
<field name="wkf_id" ref="ig_account_voucher_wkf"/>
<field name="name">confirmed</field>
<field name="action">
write({'state':'confirmed'}),
hello_world(),
hello_world_second()
</field>
<field name="kind">function</field>
</record>
Another Answer of your Question is :
Why Work flow is needed instead of button ??
The Main Goal is that the work flow is define as the business process flow.
Another goals are :
description of document evolution in time
automatic trigger of actions if some conditions are met
management of company roles and validation steps
management of interactions between the different objects/modules
graphical tool for visualization of document flows
I hope this should helpful for you ..:)
Related
I am trying to execute a function to populate new tree view. I need to execute the function and redirecting to the tree view done by only one button. Please help me with doing it.
My function is
def populate_values(self, cr, uid, ids, context={}):
result = {'value': {}}
today = datetime.datetime.now()
tt=today.date()
emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
if emps:
#...
#...
#...
return {
'name':_("leave.score.card.tree"),
'view_mode': 'tree',
'view_id': '%(open_leave_score_card_tree)d',
'views': [('tree'),('graph')],
'view_type': 'graph',
'res_id' : '%(open_leave_score_card)d',
'res_model': 'leave.score.card',
'type': 'ir.actions.act_window',
'target': 'new',
}
Form view with the button
<record model="ir.ui.view" id="edit_leave_score_card_form">
<field name="name">leave.score.card.form</field>
<field name="model">leave.score.card</field>
<field name="arch" type="xml">
<form string="Leave Score Card" create="false" edit="false" version="7.0">
<sheet>
<button string="Generate" type="object" name="populate_values" class="oe_highlight"/>
</sheet>
</form>
</field>
</record>
The tree view where I need to get redirected
<record model="ir.ui.view" id="view_leave_score_card_tree">
<field name="name">leave.score.card.tree</field>
<field name="model">leave.score.card</field>
<field name="arch" type="xml">
<tree string="Leave Score Card To the Date" create="false" edit="false" colors="red:available_medical < 0.0; red:available_casual < 0.0">
<field name="employee_id" />
<field name="category_id" />
<field name="taken_medical" />
<field name="taken_casual" />
<field name="taken_annual" />
<field name="taken_spc" />
<field name="available_medical" />
<field name="available_casual" />
<field name="available_annual" />
<field name="available_spc" />
<field name="sec_id" invisible="1" />
</tree>
</field>
</record>
Action windows
<record id="open_leave_score_card" model="ir.actions.act_window">
<field name="name">Leave Score Card Form</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">leave.score.card</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
</record>
<record id="open_leave_score_card_tree" model="ir.actions.act_window">
<field name="name">Leave Score Card Tree</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">leave.score.card</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="view_id" eval="view_leave_score_card_tree"/>
<field name="search_view_id" ref="view_leave_score_card_search"/>
</record>
Please let me know where I did wrong because the button call totally not redirecting
No need to write any function for that. I understand that you want to print score card of the employee while you click on the button.
Update action of score card as follow.
<record id="open_leave_score_card_tree" model="ir.actions.act_window">
<field name="name">Leave Score Card Tree</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">leave.score.card</field>
<field name="view_type">form</field>
<field name="view_mode">tree,graph</field>
<field name="view_id" eval="view_leave_score_card_tree"/>
<field name="search_view_id" ref="view_leave_score_card_search"/>
<field name="context">{
'search_default_employee_id': [active_id],
'default_employee_id': active_id,
'active_test': False,}
</field>
</record>
And then change button code in xml as follow.
<button string="Generate" type="action" name="%(open_leave_score_card_tree)d" class="oe_highlight"/>
Remove function no need it. And if you want to do it with the existing code without changing anything then set domain in dynamic action which you are returning from the function.
In your function you have written wrong view_type, it should be form not graph if you want to return list view then.
def populate_values(self, cr, uid, ids, context={}):
today = datetime.datetime.now()
tt=today.date()
emps=self.pool.get('hr.employee').search(cr, uid, [('current_status','=','active')], context=context)
if emps:
return {
'name':_("leave.score.card.tree"),
'view_mode': 'tree',
'view_id': '%(open_leave_score_card_tree)d',
'views': [('tree'),('graph')],
'view_type': 'form',
'res_id' : '%(open_leave_score_card)d',
'res_model': 'leave.score.card',
'type': 'ir.actions.act_window',
'domain' : [('employee_id','in', ids)],
'target': 'new',
}
return True
I would like to remove the node <sheet></sheet> from a form view. For instance, I have this view:
<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>
<sheet>
<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>
</sheet>
</form>
</field>
</record>
I would like to convert it in this other view without the node, but keeping all the elements within it:
<record id="view_account_period_form" model="ir.ui.view">
<field name="name">account.period.form</field>
<field name="model">account.period</field>
<field name="arch" type="xml">
<form string="Account Period">
<header>
[...]
</header>
<group>
<group>
<field name="name"/>
<field name="fiscalyear_id" widget="selection"/>
<label for="date_start" string="Duration"/>
<div>
<field name="date_start" class="oe_inline" nolabel="1"/> -
<field name="date_stop" nolabel="1" class="oe_inline"/>
</div>
</group>
<group>
<field name="code"/>
<field name="special"/>
<field name="company_id" widget="selection" groups="base.group_multi_company"/>
</group>
</group>
</form>
</field>
</record>
Is that possible or I need to override the complete code again?
Maybe something similar to:
<xpath expr="//form/sheet" position="replace">
<!-- [...] -->
</xpath>
There is an open issue in Git Hub asking for solving this here, but I think that maybe anyone knows how to do it without programming a new feature in Odoo.
Just use fields_view_get:
from lxml import etree
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
res = models.Model.fields_view_get(self, cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)
if view_type == 'form':
doc = etree.XML(res['arch'])
for sheet in doc.xpath("//sheet"):
parent = sheet.getparent()
index = parent.index(sheet)
for child in sheet:
parent.insert(index, child)
index += 1
parent.remove(sheet)
res['arch'] = etree.tostring(doc)
return res
improved in case of oe_chatting presence
I am from the future. I found a module time ago that made wider forms in a much easier way: web_sheet_full_width. It works for all the forms. The sheet is not removed, but the result is almost the same because the form fits in the entire screen with full width.
My page for product has the field Item Number (default_code), circled in the attached picture. My question is how I can pass this item number to the popup window that is shown when I click on button More and select "Replace all in BOM", also circled in the attached picture. I have tried by adding field "default_code" in popup window, but it just displays empty box.
Thanks for your help!
Here is the main view:
And here is my XML code:
<record id="replace_all_in_BOM_form" model="ir.ui.view">
<field name="name">replace.all.in.BOM.form</field>
<field name="model">product.template</field>
<field name="priority" eval="20"/>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="default_code" string="Item Number" readonly="0" invisible="0" />
</field>
</record>
<record id="action5" model="ir.actions.act_window">
<field name="name">Replace all in BOM</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">product.template</field>
<field name="view_type">form</field>
<field name="target">new</field>
<field name="view_id" ref="replace_all_in_BOM_form"/>
</record>
You need to write default_get in that pop-up object.
try with this,
def default_get(self, cr, uid, fields, context=None):
product_obj = self.pool.get('product.product')
record_ids = context and context.get('active_ids', []) or []
res = super(product_product, self).default_get(cr, uid, fields, context=context)
for product in product_obj.browse(cr, uid, record_ids, context=context):
if 'default_code' in fields:
#in 'default_code' is a field name of that pop-up window
res.update({'default_code': product.default_code})
return res
I searched and modified the source code of a simple custom module of openerp, I give the code below
init.py
import sim
openerp.py
{
'name': 'Student Information Management',
'version': '0.1',
'category': 'Tools',
'description': """This module is for the Student Information Management.""",
'author': 'Mr Praveen Srinivasan',
'website': 'http://praveenlearner.wordpress.com/',
'depends': ['base'],
'data': ['sim_view.xml'],
'demo': [],
'installable': True,
'auto_install': False,
'application': True,
}
sim_view.xml
<?xml version="1.0"?>
<openerp>
<data>
<!-- ============== student================= -->
<!-- 1st part of the sim_view start-->
<record model="ir.ui.view" id="student_form">
<field name="name">Student</field>
<field name="model">sim.student</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Student" version="7.0">
<group>
<field name="reg_no"/>
<field name="student_name"/>
<field name="father_name"/>
<field name="gender"/>
<field name="contact_no"/>
<field name="address"/>
</group>
</form>
</field>
</record>
<!-- 1st part of the sim_view end-->
<!--2nd part of the sim_view start-->
<record model="ir.ui.view" id="student_tree">
<field name="name">Student</field>
<field name="model">sim.student</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree string="Student">
<field name="reg_no"/>
<field name="student_name"/>
<field name="father_name"/>
<field name="gender"/>
<field name="contact_no"/>
<field name="address"/>
</tree>
</field>
</record>
<!--2nd part of the sim_view end-->
<!-- 3rd part of the sim_view start-->
<record model="ir.actions.act_window" id="action_student">
<field name="name">Student</field>
<field name="res_model">sim.student</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<!--3rd part of the sim_view end-->
<!--4th part of the sim_view start-->
<menuitem name="SIM/Student/StudentInfo" id="menu_sim_student"
action="action_student"/>
<!--4th part of the sim_view end-->
</data>
</openerp>
sim.py
**
from openerp.osv import fields, osv
class student(osv.osv):
_name = "sim.student"
_description = "This table is for keeping personal data of student"
_columns = {
'reg_no': fields.integer('Registration Number',size=7,required=True),
'student_name': fields.char('Student Name',size=25,required=True),
'father_name': fields.char("Father's Name",size=25),
'gender':fields.selection([('male','Male'),('female','Female')],'Gender'),
'contact_no':fields.char('Contact Number',size=10),
'address':fields.char('Address',size=256)
}
_sql_constraints = [
('uniq_name', 'unique(reg_no)', 'This Reg.No is number already registered!')
]
student()
**
All is working good, but I want to add an auto incremented registration Id field. I searched the Internet how to do it, but I can't get a proper solution. Please help me.
After creating sequence file you can add this function to your sim.py
def create(self, cr, uid, vals, context=None):
sequence=self.pool.get('ir.sequence').get(cr, uid, 'reg_code')
vals['reg_no']=sequence
return super(student, self).create(cr, uid, vals, context=context)
This function will work properly
Create a record in ir.sequence. First make your reg_no field to char.
<record id="seq_type_1" model="ir.sequence.type">
<field name="name">REG Type</field>
<field name="code">reg_code</field>
</record>
<record id="seq_1" model="ir.sequence">
<field name="name">reg</field>
<field name="code">reg_code</field>
<field name="prefix">REG</field>
<field name="padding">3</field>
</record>
In your py file you can define when to generate the sequence. Either in defaults to get default reg number or override the create method and call the sequence Or in any other methods:
_defaults = { 'reg_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'reg_code'), }
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.