why field value doesn't show? - odoo

my problem is that when I use inheritance, records from parent class don't display
this is my class :
class LabTestCashRegister (models.Model):
_name = "medical.cash"
_inherit = "medical.lab.patient"
comment = fields.Text(store=True,size=2000000)
type_In = fields.Char(default='Reste', readonly=False)
and this is my view:
<record model="ir.ui.view" id="medical_lab_cash_tree_id">
<field name="name">cash</field>
<field name="model">medical.cash</field>
<field name="type">tree</field>
<field name="arch" type="xml">
<tree>
<field name="patient_id"/>
<field name="cat"/>
<field name="test_type_id"/>
<field name="state_money"/>
<field name="Avance"/>
<field name="Amount"/>
<field name="Reste"/>
<field name="comment"/>
<field name="type_In"/>
</tree>
</field>
</record>
(Amount, Reste, Avance,state_money exist on the parent class)

Change your LabTestCashRegister to
class LabTestCashRegister (models.Model):
_inherit = "medical.lab.patient"
comment = fields.Text(store=True,size=2000000)
type_In = fields.Char(default='Reste', readonly=False)
This should work for you. Let me know if not.

Related

Getting mixing apples and oranges error while inheriting res.users

I am trying to inherit res.users in odoo 12. But I am getting mixing apples and oranges error. I want to create a new table having the fields of res.users models.
model.py
class SaleIndividual(models.Model):
_name = 'sale.individual'
_inherit = 'res.users'
individual_description = fields.Char()
view.xml
<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">sale.individual</field>
<field name="inherit_id" ref="auth_signup.res_users_view_form"/>
<field name="arch" type="xml">
<field name="login" position="after">
<field name="individual_description" />
</field>
</field>
</record>
</odoo>
error:
raise TypeError("Mixing apples and oranges: %s in %s" % (item, self))
TypeError: Mixing apples and oranges: sale.individual(<odoo.models.NewId object at 0x123018048>,) in res.users()
First Method:
If you want t inherit res users then please follow the below steps:
class ResUsers(models.Model):
_inherit = 'res.users'
individual_description = fields.Char()
view.xml
<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="auth_signup.res_users_view_form"/>
<field name="arch" type="xml">
<field name="login" position="after">
<field name="individual_description" />
</field>
</field>
Second Method:
if you want create new model then follow the steps below:
class SaleIndividual(models.Model):
_name = 'sale.individual'
_inherit = 'res.users'
individual_description = fields.Char()
Need to create a new view file with out inheriting res users view file for this case.
<odoo>
<record id="view_form_sale_custom_individual" model="ir.ui.view">
<field name="name">Individual Form</field>
<field name="model">sale.individual</field>
<field name="arch" type="xml">
<form>
<field name="individual_description" />
</form>
</field>

Odoo. How to create a view to extended model

I am very new in odoo and i really need your help.
I've extended res.partner :
class extendedPartner(models.Model):
_name = 'extended.partner'
_inherit = 'res.partner'
auto = fields.One2Many('partner.car', 'auto_name', 'Car', required=False)
class partnerCar(models.Model):
_name = 'partner.car'
auto_model = fields.Char('Model auto', size=20, required=True)
release = fields.Integer('Year of release', required=True)
auto_name = fields.Many2One('extended.partner', 'Car Name', required=True)
But I don't know how to write xml so that I could see all partner's cars and information about them
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Cars">
<!-- what should I write here? -->
</page>
</notebook>
</field>
</record>
Could you please help me? Thank you in advance.
UPD:
Is it right solution?
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</field>
</record>
You are almost there, since you inherit from another view and you injecting your view into the view you inherit from, you need to give your new view a "hook" in the parent view which it can use to attach its contents. So you use an xpath expression, and then you insert your field.
When you insert a relational field you can create so called embedded views. Here you have defined a tree view for your field. That means whenever your field will be rendered as a tree that is the tree that will be used, in your case the form.
You could also create a <form> after <tree> to be shown when clicked.
<record model="ir.ui.view" id="view_partner_form">
<field name="name">res.partner.form.inherit</field>
<field name="model">extended.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="insert_x_path_xpression here" position="after, before etc"
<field name="auto">
<tree>
<field name="auto_name"/>
<field name="auto_model"/>
<field name="release"/>
</tree>
</field>
</xpath>
</field>
</record>

Updating Field in the Form in Odoo respect to change in value of another Field?

I developed a Location Module in Odoo where I can add country's & states related to that Country. Then Iam calling this module in another Module Where I have to do like:- when selecting a country, it should automatically populate the states belong to that country in the state field.How this can be done? I tried Onchange function,But didnt worked? I will Provide my model & view code here below.
from openerp import models, fields, api
class peniel(models.Model):
_name='peniel'
name = fields.Char(string="Name")
product = fields.Many2one('product.template', string='Product', required=True)
employee = fields.Many2one('hr.employee', string='Employee', required=True)
customer = fields.Many2one('res.partner', string='Customer', required=True)
country = fields.Many2one('location', string='Country', required=True)
state = fields.Many2one('state', string='State', required=True)
date_d = fields.Date(string="Date Activity")
comment = fields.Text(string="Comments")
#api.onchange('country')
def onchange_country(self):
if self.country:
self.state = self.country.state
View File will be like:
<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<record id="action_peniel" model="ir.actions.act_window">
<field name="name">Peniel </field>
<field name="res_model">peniel</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
<field name="search_view_id" eval="False"/>
<field name="context">{}</field>
<field name="help">Create new Record</field>
</record>
<menuitem name="Peniel" id="peniel_roof" sequence="60"/>
<menuitem id="menu_peniel_roof" name="Peniel" parent="peniel_roof" sequence="1"/>
<menuitem action="action_peniel" id="menu_action_peniel" parent="menu_peniel_roof" sequence="20"/>
<record id="view_location_tree" model="ir.ui.view">
<field name="name">peniel.tree</field>
<field name="model">peniel</field>
<field name="arch" type="xml">
<tree string="Peniel">
<field name="name"/>
<field name="product"/>
<field name="employee"/>
<field name="customer"/>
<field name="country"/>
<field name="state"/>
<field name="date_d"/>
<field name="comment"/>
</tree>
</field>
</record>
<record id="view_location_form" model="ir.ui.view">
<field name="name">peniel.form</field>
<field name="model">peniel</field>
<field name="arch" type="xml">
<form string="Peniel">
<group>
<field name="name"/>
<field name="product"/>
<field name="employee"/>
<field name="customer"/>
<field name="country"/>
<field name="state"/>
<field name="date_d"/>
<field name="comment"/>
</group>
</form>
</field>
</record>
</data>
</openerp>
Their is no require of onchange function. We may handle with below tricks.
Replace your field definition
country = fields.Many2one('location', string='Country', required=True)
state = fields.Many2one('state', string='State', required=True)
with
country = fields.Many2one('res.country', string='Country', required=True)
state = fields.Many2one('res.country.state', string='State', required=True)
Now change field on .xml side:
Replace field
<field name="state"/>
with
<field name="state" domain="[('country_id', '=', country)]"/>

How send default value for field from view to other view

I need to create one2one relation in openerp7. I read many articles about this idea and I could to type the following code
problem is : that openerp7 does not send value from parent view (calculation) to child (container)
this my code
testproject.py:
from osv import fields,osv
class container(osv.osv):
_name='container'
_columns={
'calculation_id': fields.many2one('calculation','Calculation'),
'name': fields.char('Name', size=32),
}
container()
class calculation(osv.osv):
_name='calculation'
_columns={
'container_id': fields.many2one('container','Container'),
'namefull': fields.char('Name Full', size=32),
}
calculation()
xml code:
<?xml version="1.0"?>
<openerp>
<data>
<record model="ir.ui.view" id="view_container_form">
<field name="name">container.form</field>
<field name="model">container</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Container">
<field name="name" select="1"/>
<field name="calculation_id" context="{'default_container_id': active_id}" />
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_container">
<field name="name">Container</field>
<field name="res_model">container</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Container/Container" id="menu_container"/>-->
<menuitem name="Container" id="menu_container_item" parent="menu_container" action="action_container"/>
<record model="ir.ui.view" id="view_calculation_form">
<field name="name">calculation.form</field>
<field name="model">calculation</field>
<field name="type">form</field>
<field name="arch" type="xml">
<form string="Calculation">
<field name="namefull" />
<field name="container_id" />
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_calculation">
<field name="name">Calculation</field>
<field name="res_model">calculation</field>
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem name="Calculation" id="menu_calculation_item" parent="menu_container" action="action_calculation"/>
</data>
</openerp>
You are correct, OpenERP will not move data around for you -- you will need to modify your Python code to do it.
Oh, and you should name your tables with your model as well -- I'll use a fake model name of my_model:
class calculation(osv.Model):
_name = 'my_model.calculation'
_columns = {
'container_id' fields.many2one('my_model.container', 'Container'),
'namefull': fields.char('Name Full', size=32),
}
def create(self, cr, uid, values, context=None):
new_id = super(calculation, self).create(cr, uid, values, context=context)
self.pool.get('my_model.container').create(cr, uid, {'calculation_id':new_id, 'name':values['namefull'])
return new_id
And something similer to write() in case namefull is updated.

OpenERP - implementing something similar to stock.picking.in

The way stock.picking.in is implemented in openERP is interesting. I am trying to do something similar with purchase orders.
Stock.picking.in inherits from stock.picking, customizes a few columns and defaults and declares the table as stock_picking. On the UI side, a form view is inherited from view_picking_form and the model used is stock.picking.in.
I am trying to do something similar by creating a special purchase order. The problem is that the form for the special PO never gets picked up. It always shows a dynamic view with all fields of the PO dumped in some default manner. The developer mode also does not show the right form view.
When I check Settings -> User Interface -> Views, it does show the view properly but doesn't display it when I create new special PO.
Here is the code:
class my_purchase_order(osv.osv):
_name = "purchase.order"
_inherit = "purchase.order"
_columns={
...
}
my_purchase_order()
class my_purchase_order_special(osv.osv):
_name = 'purchase.order.my_special'
_inherit = "purchase.order"
_table = "purchase_order"
_columns = {...
}
my_purchase_order_special()
<record id="po_my_special_form" model="ir.ui.view">
<field name="name">po_my_special_form</field>
<field name="model">purchase.order.my_special</field>
<field name="type">form</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
...
</field>
</record>
<record id="po_my_special_tree" model="ir.ui.view">
<field name="name">po_my_special_tree</field>
<field name="model">purchase.order.my_special</field>
<field name="arch" type="xml">
<tree fonts="bold:message_unread==True" colors="grey:state=='cancel';blue:state in ('wait','confirmed');red:state in ('except_invoice','except_picking')" string="Purchase Order">
<field name="message_unread" invisible="1"/>
<field name="name" string="Reference"/>
<field name="date_order" />
<field name="partner_id"/>
<field name="company_id" groups="base.group_multi_company" widget="selection"/>
<field name="minimum_planned_date" invisible="context.get('quotation_only', False)"/>
<field name="origin"/>
<field name="amount_untaxed" sum="Total Untaxed amount" string="Untaxed"/>
<field name="amount_total" sum="Total amount"/>
<field name="state"/>
</tree>
</field>
</record>
<record id="action_po_my_special_tree" model="ir.actions.act_window">
<field name="name">Special Purchase Orders</field>
<field name="type">ir.actions.act_window</field>
<field name="res_model">purchase.order.my_special</field>
<field name="view_mode">tree,form,graph,calendar</field>
<field name="context">{}</field>
<field name="domain">[('state','=','draft')]</field>
<field name="search_view_id" ref="purchase.view_purchase_order_filter"/>
</record>
<record id="action_po_my_special_form" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="po_my_special_form"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>
Please advise. Thanks in advance.
Turns out I was missing view records:
<record id="action_po_my_special_tree2" model="ir.actions.act_window.view">
<field eval="1" name="sequence"/>
<field name="view_mode">tree</field>
<field name="view_id" ref="po_my_special_tree"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>
<record id="action_po_my_special_form2" model="ir.actions.act_window.view">
<field eval="2" name="sequence"/>
<field name="view_mode">form</field>
<field name="view_id" ref="po_my_special_form"/>
<field name="act_window_id" ref="action_po_my_special_tree"/>
</record>