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.
Related
Please let me know where I'm making mistake
I 'm trying to add a clickable Text, when click on that move to the form and tree view I can save data and when click on save button I can get back to the previous view, and the previous view then have a clickable text to go again and see the data
view.xml
<odoo>
<data>
<record id="kts_project_task" model="ir.ui.view">
<field name="name">kts.project.task.view.form</field>
<field name="model">project.task</field>
<field name="inherit_id" ref="project.view_task_form2" />
<field name="arch" type="xml">
<field name="date_deadline" position="after">
<field name="actual_completion_date" />
<field name="testscript_ids"/>
</field>
</field>
</record>
Error--->> <record id="kts_project_script" model="ir.ui.view">
<field name="name">kts.project.task.testscript.view.form</field>
<field name="model">kts.project.task.testscript</field>
<field name="arch" type="xml">
<form string="Test Script">
<group col="2">
<group>
<field name="test_case_id"/>
<field name="test_priority"/>
<field name="module_name"/>
<field name="test_title"/>
<field name="overall_status"/>
</group>
<group>
<field name="test_designed_by"/>
<field name="test_designed_date"/>
<field name="test_executed_by"/>
<field name="test_executed_date"/>
<field name="remark"/>
</group>
</group>
<group>
<field name="pre_conditions"/>
</group>
</form>
<field name="test_script_line_ids" mode="tree">
<tree editable="bottom" string="Test Script" >
<field name="step_name" />
<field name="description" />
<field name="expected" />
<field name="actual_result" />
<field name="pass_fail"/>
<field name="remark"/>
</tree>
</field>
</field>
</record>
</data>
</odoo>
model.py
class kts_project_task(models.Model):
_inherit = 'project.task'
actual_completion_date = fields.Date(string='Actual Completion Date', index=True, copy=False, tracking=True)
testscript_ids = fields.Many2one('kts.project.task.testscript', string="Test Script")
#api.returns('self', lambda value: value.id)
def copy(self, default=None):
if default is None:
default = {}
default['user_id']=False
return super(kts_project_task, self).copy(default)
def get_user(self):
if SUPERUSER_ID == self._uid:
return True
else:
return False
#field level readonly managed for users
#api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(kts_project_task, self).fields_view_get(view_id=view_id,
view_type=view_type,
toolbar=toolbar,
submenu=submenu)
if self.env.user.has_group('project.group_task_user') :
doc = etree.XML(res['arch'])
for field in ['date_deadline','project_id','user_id','tag_ids','name', 'partner_id']:
for node in doc.xpath("//field[#name='%s']" % field):
node.set("readonly", "1")
modifiers = json.loads(node.get("modifiers"))
modifiers['readonly'] = True
node.set("modifiers", json.dumps(modifiers))
res['arch'] = etree.tostring(doc)
return res
class kts_project_task_testscript(models.Model):
_name = 'kts.project.task.testscript'
test_case_id = fields.Char(string='Test Case ID')
test_priority = fields.Char(string='Test Priority')
module_name = fields.Char(string='Module Name')
test_title = fields.Char(string='Test Title')
overall_status = fields.Char(string='Overall Status')
test_designed_by = fields.Char(string='Test Designed By')
test_designed_date = fields.Date(string='Test Designed Date')
test_executed_by = fields.Char(string='Test Executed By')
test_executed_date = fields.Date(string='Test Executed Date')
remark = fields.Char(string='Remarks')
pre_conditions = fields.Text(string='Pre-conditions')
test_script_line_ids = fields.One2many('kts.project.task.testscript.line', 'testscript_id', 'Test Script Id')
class kts_project_task_testscript_line(models.Model):
_name = 'kts.project.task.testscript.line'
step_name = fields.Char(string='Steps')
description = fields.Text(string='Test Steps')
expected = fields.Text(string='Excepted results')
actual_result = fields.Text(string='Actual Results')
pass_fail = fields.Selection([
('pass', 'Pass'),
('fail', 'Fail'),
], string="Status(P/F)")
remark = fields.Text(string='Remarks')
testscript_id = fields.Many2one('kts.project.task.testscript', string="Task Activities")
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
In Product form view there is Button Sale. When you activate it shows tree view with all sale orders for this product. My goal is to make the same button but it has to show all pos orders that was made with this product.
i tried something like this but i know it's total garbage. If someone could explain to me how it works i will be more then grateful
<record id="act_product_pos_sale" model="ir.actions.act_window">
<field name="name">POS Product Sale1</field>
<field name="res_model">product.product</field>
<field name="view_id" ref="product.product_product_tree_view"/>
</record>
<record model="ir.ui.view" id="product_form_pos_sale_button">
<field name="name">product.product.sale.pos.order</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" name="action_view_pos_product"
type="object" icon="fa-usd">
<field string="POS" name="pos_product_order_total" widget="statinfo" />
</button>
</div>
</field>
</record>
class ProductProduct(models.Model):
_inherit = 'product.product'
#api.multi
def action_view_pos_product(self):
OrderLine = self.env['pos.order.line']
action = self.env.ref('sale.act_product_pos_sale')
# action['domain'] = [('product_id', 'in', products.ids)]
# action['context'] = {'': ,}
return action
You add action and call that action using button:
Step 1: you have to calculate total pos sale count using compute method:
class ProductProduct(models.Model):
_inherit = 'product.product'
#api.multi
def _pos_sales_count(self):
r = {}
domain = [
('state', 'in', ['sale', 'done']),
('product_id', 'in', self.ids),
]
for group in self.env['report.pos.order'].read_group(domain, ['product_id', 'product_qty'], ['product_id']):
r[group['product_id'][0]] = group['product_qty']
for product in self:
product.sales_count = r.get(product.id, 0)
return r
pos_sales_count = fields.Integer(compute='_pos_sales_count', string='#Pos Sales')
class ProductTemplate(models.Model):
_inherit = 'product.template'
#api.multi
#api.depends('product_variant_ids.pos_sales_count')
def _pos_sales_count(self):
for product in self:
product.pos_sales_count = sum([p.sales_count for p in product.product_variant_ids])
pos_sales_count = fields.Integer(compute='_pos_sales_count', string='#POS Sales')
Step 2 : define action to link pos order line related to product:
<record id="action_product_pos_sale_list" model="ir.actions.act_window">
<field name="name">Sale Order Lines</field>
<field name="res_model">pos.order.line</field>
<field name="context">{'search_default_product_id': [active_id], 'default_product_id': active_id}</field>
</record>
<record model="ir.ui.view" id="product_form_view_pos_sale_order_button">
<field name="name">product.product.pos.sale.order</field>
<field name="model">product.product</field>
<field name="inherit_id" ref="product.product_normal_form_view"/>
<field name="groups_id" eval="[(4, ref('sales_team.group_sale_salesman'))]"/>
<field name="arch" type="xml">
<div name="button_box" position="inside">
<button class="oe_stat_button" name="%(action_product_pos_sale_list)d"
type="action" icon="fa-usd">
<field string="Sales" name="pos_sales_count" widget="statinfo" />
</button>
</div>
</field>
</record>
I have created one model, It contain 2 fields and one grid view. So I am trying to many2one for one field to create new id. Please let me know where i am making the mistake ?
.py code is here
from openerp.osv import fields, osv
class agile_portfolio(osv.Model):
_name = "agile.portfolio"
_rec_name = 'epic_owner'
_columns = {
'name': fields.char('Asset Name',),
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID'),
'strat_id1' : fields.one2many('portfolio.grid','strat_id','Strategy Name'),
}
agile_portfolio()
class portfolio_grid(osv.Model):
_name = 'portfolio.grid'
_columns = {
'name' : fields.char('Part'),
'strat_code' : fields.char('Code'),
'strat_quty' : fields.char('Quantity '),
'strat_uom' : fields.char('UoM'),
'strat_id': fields.many2one('agile.portfolio','Strat Id'),
}
portfolio_grid()
class assetid_name(osv.Model):
_name = 'assetid.name'
_rec_name = 'asst_id'
_columns = {
'asst_id' : fields.char('Asset_ID'),
}
assetid_name()
.xml code is here
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<!--Portfolio View-->
<record id="agile_portfolio_form" model="ir.ui.view">
<field name="name">agile.portfolio.form</field>
<field name="model">agile.portfolio</field>
<field name="arch" type="xml">
<form string="AssetConfig">
<group>
<group>
<field name="name"/>
</group>
<group>
<field name="epic_owner"/>
</group>
</group>
<notebook>
<page string="Part Name">
<field name="strat_id1">
<form string="Part Name">
<group>
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</group>
</form>
<tree string="Part Name">
<field name="name"/>
<field name="strat_code"/>
<field name="strat_quty"/>
<field name="strat_uom"/>
</tree>
</field>
</page>
</notebook>
</form>
</field>
</record>
<record id="agile_portfolio_action" model="ir.actions.act_window">
<field name="name">AssetConfigs</field>
<field name="res_model">agile.portfolio</field>
<field name="view_type">form</field>
<field name="help" type="html">
<p class="oe_view_nocontent_create">Click to create a new portfolio</p>
</field>
</record>
<!--side menu's-->
<menuitem id="asset_config" name="AssetConfigs"/>
<menuitem id="portfolio_menu" name="AssetParts" parent="asset_config"/>
<menuitem id="portfolio_nxt_menu" name="AssetParts" parent="portfolio_menu" action="agile_portfolio_action"/>
</data>
</openerp>
openerp.py
{
'name': 'Agile',
'version':'1.0',
'description': """
Agile Methodology
- Portfolios
- Programs
- Projects
""",
'author': 'Suraj',
'depends': ['base_setup',],
'data': ['agile_view.xml',],
'installable': True,
'auto_install': False,
}
I think you have given the wrong model name in following field.
'epic_owner':fields.many2one('Agile.assetid.name','Asset ID')
Here instead of "Agile.assetid.name" you have to give "assetid.name" if you want to manage M2O of last model "assetid.name". I think no model have capital letter.
I think this will resolve your issue.
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'), }