ODOO - How to update two levels o2m fileds relation - odoo

Odoo community version 11.0-20190311
I have a parent class (dt_tst001) with a o2m field (itens) related to a class (dt_tst002), with another o2m field (tributos) related to a third class (dt_tst003).
In the parent class there is another field (seguro_total) and when its value is changed I need to start a recalculation (_upd_seguro) of field (seguro) in the second class and fields (base_calculo, valor_tributo) in the third class.
The recalculation in the second class is working, but not in the third one.
Debuging step by step the values are updated but when checking the form, it shows the original values, and this values are sent to the database.
Sample code:
class DT_TST001(models.Model):
_name = "dt_tst001"
_rec_name = "documento"
documento = fields.Char(string = "Documento", size = 9, required = True)
seguro_total = fields.Float(string = "Seguro total")
itens = fields.One2many("dt_tst002", inverse_name = "documento_id", required = True)
#api.onchange('seguro_total')
def _upd_seguro(self):
for item in self.itens:
item.update({
'seguro' : ((item.quantidade * item.valor_unitario) / item.valor_total) * self.seguro_total})
for tributo in item.tributos:
tributo.update({'base_calculo' : (item.valor_total + item.seguro)})
tributo.update({'valor_tributo' : (item.valor_total + item.seguro) * tributo.aliquota / 100})
class DT_TST002(models.Model):
_name = "dt_tst002"
_rec_name = "documento_id"
documento_id = fields.Many2one("dt_tst001", string = "Documento", required = True, ondelete='cascade')
produto_id = fields.Char(string = "Produto", size = 15, required = True)
quantidade = fields.Float(string="Quantidade", default = 0.00)
valor_unitario = fields.Float(string="Valor unitário", required = True, default = 0.00)
valor_total = fields.Float(string="Valor total", required = True, default = 0.00)
seguro = fields.Float(string="Seguro", compute='_recalc_impostos', store=True)
tributos = fields.One2many("dt_tst003", inverse_name = "item_id")
#api.onchange('quantidade', 'valor_unitario', 'seguro')
def _upd_valor_total(self):
self.valor_total = (self.quantidade * self.valor_unitario) + self.seguro
class DT_TST003(models.Model):
_name = "dt_tst003"
item_id = fields.Many2one("dt_tst002", string = "Ítem", required = True, ondelete='cascade')
tributo_id = fields.Char(string = "Tributo", size = 15, required = True)
base_calculo = fields.Float(string = "Base de cálculo")
aliquota = fields.Float(string = "Alíquota")
valor_tributo = fields.Float(string = "Valor do tributo")
#api.multi
def name_get(self):
result = []
for m_tst003 in self:
name = m_tst003.item_id.documento_id._name + " - " + m_tst003.item_id._name + " - " + m_tst003.tributo_id._name
result.append((m_tst003.id, name))
return result
Sample view definition:
<odoo>
<data>
<!-- VIEWS PARA NOTAS DE ENTRADA -->
<record model="ir.ui.view" id="tst001_form">
<field name="model">dt_tst001</field>
<field name="name">tst001_form</field>
<field name="arch" type="xml">
<form string="Documento de entrada">
<group colspan="1" style="margin: 0px">
<field name="documento" style="text-transform: uppercase;"/>
<field name="seguro_total"/>
</group>
<notebook>
<page string="Ítens">
<group>
<h6>
<field name="itens" context="{'form_view_ref' : 'dt_tst.tst002_form',
'tree_view_ref' : 'dt_tst.tst002_tree',
'default_itens' : itens}" force_save="1" class="oe_horizontal_separator oe_clear"/>
</h6>
</group>
</page>
</notebook>
</form>
</field>
</record>
<record model="ir.ui.view" id="tst001_tree">
<field name="model">dt_tst001</field>
<field name="name">tst001_tree</field>
<field name="arch" type="xml">
<tree string="Documentos de entrada">
<field name="documento"/>
<field name="seguro_total"/>
</tree>
</field>
</record>
<!-- ITENS -->
<record model="ir.ui.view" id="tst002_form">
<field name="model">dt_tst002</field>
<field name="name">tst002_form</field>
<field name="arch" type="xml">
<form string="Ítem de documento de entrada">
<group style="margin: 0px">
<group colspan="4" style="margin: 0px">
<field name="produto_id"/>
</group>
<group colspan="4" style="margin: 0px">
<group style="margin: 0px">
<field name="quantidade"/>
</group>
<group style="margin: 0px">
<field name="valor_unitario"/>
</group>
<group colspan="4" style="margin: 0px">
<field name="valor_total" readonly="1" options='{"always_reload": True}' />
</group>
</group>
<group colspan="4" style="margin: 0px">
<field name="seguro"/>
</group>
<field name="valor_total" invisible="1"/>
</group>
<notebook>
<page string="Tributos">
<group>
<h6>
<field name="tributos" context="{'form_view_ref' : 'dt_test.tst003_form',
'tree_view_ref' : 'dt_test.tst003_tree',
'default_tributos' : tributos,
'default_valor_total' : valor_total}" force_save="1" class="oe_horizontal_separator oe_clear"/>
</h6>
</group>
</page>
</notebook>
</form>
</field>
</record>
<record model="ir.ui.view" id="dt_fis.tst002_tree">
<field name="model">dt_tst002</field>
<field name="name">tst002_tree</field>
<field name="arch" type="xml">
<tree string="Ítens de documentos de entrada">
<field name="produto_id"/>
<field name="quantidade"/>
<field name="valor_unitario"/>
<!-- Enviar campos invisíveis para que seu conteúdo seja resgatado no formulário -->
<field name="seguro" invisible="1"/>
<field name="tributos" invisible="1"/>
</tree>
</field>
</record>
<!-- VIEWS PARA DOCUMENTOS DE ENTRADA E SAÍDA -->
<record model="ir.ui.view" id="tst003_form">
<field name="model">dt_tst003</field>
<field name="name">tst003_form</field>
<field name="arch" type="xml">
<form string="Tributos de ítem de documento fiscal">
<sheet>
<group>
<field name="tributo_id"/>
<field name="base_calculo"/>
<field name="aliquota"/>
<field name="valor_tributo"/>
</group>
</sheet>
</form>
</field>
</record>
<record model="ir.ui.view" id="tst003_tree">
<field name="model">dt_tst003</field>
<field name="name">tst003_tree</field>
<field name="arch" type="xml">
<tree string="Tributos de ítem de documento fiscal">
<field name="tributo_id"/>
<field name="base_calculo"/>
<field name="aliquota"/>
<field name="valor_tributo"/>
</tree>
</field>
</record>
<record model="ir.actions.act_window" id="dt_test.tst001_action">
<field name="name">Documentos de entrada - teste</field>
<field name="res_model">dt_tst001</field>
<field name="view_mode">tree,form</field>
<field name="view_type">form</field>
<field name="view_ids" eval="[(5, 0, 0),
(0, 0, {'view_mode': 'tree', 'view_id': ref('tst001_tree')}),
(0, 0, {'view_mode': 'form', 'view_id': ref('tst001_form')})]"/>
<field name="view_type">form</field>
</record>
<menuitem name="Documentos de entrada" id="dt_test.tst001_menu" parent="dt_test.tst_menu_registros" action="dt_test.tst001_action" sequence="10"/>
</data>
</odoo>
Thank you!

well, it seems in the second class it is working because seguro field of class DT_TST002 is computed based on _recalc_impostos function. it doesn't use on_change. one more thing to note, is there are no relation between class DT_TST001 & DT_TST003.
according to your comment the on_change method would be like the following:
#api.onchange('seguro_total')
def _upd_seguro(self):
for item in self.itens:
seguro = ((item.quantidade * item.valor_unitario) / item.valor_total) * self.seguro_total
tributes = []
for tributo in item.tributos:
base_calculo = (item.valor_total + item.seguro)
valor_tributo = (item.valor_total + item.seguro) * tributo.aliquota / 100
tributes.append((1, tributo.id, {'base_calculo' : base_calculo, 'valor_tributo' : valor_tributo}))
item.update({
'seguro' : seguro
'tributos' : tributes,
})
also, please note that you can deal with relational fields as following
(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update the linked record with id = ID (write *values* on it)
(2, ID) remove and delete the linked record with id = ID (calls unlink on ID, that will delete the object completely, and the link to it as well)
(3, ID) cut the link to the linked record with id = ID (delete the relationship between the two objects but does not delete the target object itself)
(4, ID) link to existing record with id = ID (adds a relationship)
(5) unlink all (like using (3,ID) for all linked records)
(6, 0, [IDs]) replace the list of linked IDs (like using (5) then (4,ID) for each ID in the list of IDs)

Related

odoo.tools.convert.ParseError: while parsing -> views.xml:15, near

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

POS product order lines

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>

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.