how inherited with odoo I want to modify the type of consultation as on this code but I don't want to touch the source file - odoo

here is the code I want to change the type of consultation to: -new consultation -followed by consultation
class OeHealthPhysician (osv.osv):
"""New class the oeh.medical.physician"""
_name = "oeh.medical.physician"
_description = "Information about the doctor"
_inherits={
'hr.employee': 'employee_id',
}
CONSULTATION_TYPE = [
('Residential', 'Residential'),
('Visiting', 'Visiting'),
('Other', 'Other'),
]
this is what i have try to do and it doest work
class OeHealthPhysician (osv.osv):
"""New class the oeh.medical.physician"""
_name = "oeh.medical.physician"
_description = "Information about the doctor"
_inherits={
'hr.employee': 'employee_id',
}
CONSULTATION_TYPE = [
('New consultation', 'New consultationl'),
('Followed by consultation', 'Followed by consultation'),
]

You would need to inherit the model and overwrite the selection field with your new selections.
Class OeHealthPhysicianInherit(models.Model):
_inherit = 'oeh.medical.physician'
consultation_type = fields.Selection([
('New consultation', 'New consultation'),
('Followed by consultation', 'Followed by consultation')
])

To override the consultation field and add new selection values, use the selection_add parameter:
selection_add -- provides an extension of the selection in the case of an overridden field. It is a list of pairs (value, string).

Related

How to get value on one field based on two different fields

So Im creating a hotel management module . I have the option to filter rooms based on bed_type and tag. Tag contains different facilities like AC, TV etc. So an user will come and select a bed_type and the facilities he wants and in the third field it should show the rooms that have the given configuration if not available an error messages should come. SO i created a onchange function to do this , but i dint know how to include the tags in it. Im doing it on odoo v14. m
This is the model for the room
from odoo import api, fields, models, _
class HotelRoom(models.Model):
_name = 'hotel.room'
_description = 'hotel room'
_rec_name = 'room_number'
room_number = fields.Char('Room Number', required=True)
room_rent = fields.Monetary('Room Rent')
tag = fields.Many2many('hotel.tags', string='Facilities')
dormitory_count = fields.Integer('Dormitory count')
bed_type = fields.Selection([
('single', 'Single'),
('double', 'Double'),
('dormitory', 'Dormitory')
], required=True, default='other')
This is the model for the reception
class HotelAccommodation(models.Model):
_name = 'accommodation.room'
_description = 'Reception'
bed_type = fields.Selection([
('single', 'Single'),
('double', 'Double'),
('dormitory', 'Dormitory')
], required=True, string= 'Bed type')
state = fields.Selection([
('draft','Draft'),
('check-in','Check-In'),
('check-out', "Check-Out"),
('cancel','Cancel'),
], required=True, default='draft', tracking=True)
tag = fields.Many2many('hotel.tags', string='Facilities')
room_id = fields.Many2one('hotel.room', string='Room')
Using this I can filter the rooms based on the bed_type but I need to have the tags as well.I tried giving it inside the domain but its not working .
#api.onchange('bed_type')
def filter_room(self):
for rec in self:
return {'domain': {'room_id': [('bed_type', '=', rec.bed_type)]}}
You need also to add the tag field to the domain and to the onchange decorator, so the method will be called when the tag field is modified.
The method is invoked on a pseudo-record that contains the values present in the form, you do not need to loop over self.
Try the following example:
#api.onchange('bed_type', 'tag')
def filter_room(self):
return {'domain': {'room_id': [('bed_type', '=', self.bed_type), ('tag', 'in', self.tag.ids)]}}
You can use _compute fields with the store option = True
take a look https://www.odoo.com/documentation/14.0/reference/orm.html#computed-fields

odoo how to show the values of my two fields once I do a select

I have two models:
medical.lab.test.type
This is my class:
class MedicalLabTestType(models.Model):
_name = "medical.lab.test.type"
_description = "Medical Lab Test Types"
name = fields.Char(
'Test',
help='Name of test type, such as X-Ray, Hemogram, Biopsy, etc.',
required=True,
)
code = fields.Char(
'Code',
size=128,
help='Short name or code for test type.',
required=True,
)
description = fields.Text('Description')
Test_Prix = fields.Float(
string='Price of the test',
required=True,
)
Nbr_days = fields.Integer(
string='Number of days to have results',
required=True,
)
and
medical.lab
This is my class:
class MedicalLab(models.Model):
_name = 'medical.lab'
_description = "Medical Labs"
test_type_id = fields.Many2one(
string='Test Type',
comodel_name='medical.lab.test.type',
help='Lab test type.',
)
physician_id = fields.Many2one(
string='Pathologist',
comodel_name='medical.physician',
help='Pathologist that performed the exam.',
)
request_physician_id = fields.Many2one(
string='Requesting Physician',
comodel_name='medical.physician',
help='Physician that requested the exam.',
)
The problem is to show on the view the value of Test_Prix and Nbr_days once I choose a Test
How should i proceed?, should I use an onchange function!!!
to show field of selected m2o on the current view you should use
related field.
in your midecal.lab model add:
# related field should always keep the same type Foalt Float, Char Char
# and it's recommended that you put readonly because if you edit
# the value the value will be edited in the related record when you save
Test_Prix = fields.Float(
retlated='test_type_id.Test_Prix',
readonly=True
)
Nbr_days = fields.Integer(
retlated='test_type_id.Nbr_days',
readonly=True
)
and now you can add this two field to you view like
NB: related field are not stored in database they work as proxy if you
want to create the field in the database use store=True
EDITS :
use onchange not compute field is computed
date_perform = fields.Datetime( string='Date of Results', )
#api.onchange('date_request', 'Nbr_days')
def _compute_date_result(self):
for record in self:
business_days_to_add = record.Nbr_days
current_date = fields.Datetime.from_string(record.date_request)
.....

How to change the default value of a property field in Odoo (old API)?

I'm trying to change the default value of some property fields such as: 'cost_method', 'product_type' and 'valuation' of the 'product' module but I can only change the non-property fields only.
What I tried:
- I created a new module and inherited the 'product.template' model and overridden the '_default' dictionary only but it didn't work.
I created new fields with the same name but of another type (selection) not property but neither did this work.
The code:
_name = "product.template"
_inherit = "product.template"
_columns = {
'cost_method': fields.selection([('average', 'Average Price'),('standard', 'Standard Price'), ('real', 'Real Price')])
,'type': fields.selection([('product', 'Stockable Product'),('consu', 'Consumable'),('service','Service')], 'Product Type', required=True, help="Consumable are product where you don't manage stock, a service is a non-material product provided by a company or an individual.")
,'company_id': fields.many2one('res.company', 'Company', required=False)
}
_defaults = {
'company_id': False
,'type' : 'product'
, 'cost_method': 'average'
, 'barcode':'555'
}
Use only _inherit="product.template". In your case you don't need the _name property.
Did you add your py. File to your __init__.py?
Did you set the correct dependencies in your __openerp__.py. In your case "product"?
Hope that helps you. Let me know.
EDIT:
I could reproduce your problem. My Code for testing
# -*- coding: utf-8 -*-
from openerp.osv import osv, fields
class product_template(osv.osv):
_name = "product.template"
_inherit = "product.template"
_columns = {
'cost_method': fields.selection([('average', 'Average Price'),('standard', 'Standard Price'),('real', 'Real Price')]),
'type': fields.selection([('product', 'Stockable Product'),('consu', 'Consumable'),('service','Service')],'Product Type', required=True, help="Consumable are product where you don't manage stock, a service is a non-material product provided by a company or an individual.") ,
'company_id': fields.many2one('res.company', 'Company', required=False)
}
_defaults = {
'company_id': False,
'type' : 'consu',
'cost_method': 'average',
'barcode':'555'
}
Here the type-field never had the consu value. In my case I could solve the problem by opening the menu Settings -> Technical Settings -> Actions -> User-defined Defaults. I deleted all entries where the name is type and modelname is product.template.
Now if I create a new product the default type is consu. Same behaviour with cost_method-field.

How to create a field for project sale orders

I have fields for a quick access of the entities related to a project. For example:
class project(models.Model):
_name = "project.project"
_description = "Project"
_inherit = 'project.project'
production_order_ids = fields.One2many('mrp.production', 'project_id', 'Production orders')
purchase_order_ids = fields.One2many('purchase.order', 'project_id', 'Purchase orders')
....
I am trying to create a sale_order_ids in the project.project model. My first try did not work:
sale_order_ids = fields.One2many('sale.order', 'project_id', string='Sale orders')
because because the field sale.order.project_id is of type account.analytic.account.
A project.project object inherits from account.analytic.account. This query should work ok if they would share the same Id, but they do not. So the navigation would be:
"project.project".analytic_account_id" -> sale.order".project_id
And the result would be the corresponding sale.order(s).
Use a computed field:
sale_order_ids = fields.One2many('sale.order', compute='_get_sale_orders', string='Sale orders')
#api.model
def _get_sale_orders(self):
for record in self:
record.sale_order_ids = self.env['sale.order'].search([('project_id', '=', record.analytic_account_id.id)]).ids

Openerp dynamic domain filter

On my class folder a have many goods and many amounts. I need to use a domain filter on my field good_id of class amount, on that field I need to show the list of my object folder's goods.
so I create a function on my amount class (_get_folder_list_goods) that returns the list of folder's goods and I add a domain attribute on my field good_id of class amount.
here are my classes:
class folder(osv.osv):
_name = 'folder'
_columns = {
'name' : fields.char(u'Numéro',size=50, readonly=True),
'goods_ids': fields.many2many('good', 'doss_bien_rel', 'folder_id', 'good_id', 'Goods'),
'amount_id': fields.one2many('amount', 'folder_id', 'Amounts'),
....}
class good(osv.osv):
_name = 'good'
_columns = {
'name' : fields.function(_name_get_fnc, type="char", string=u''),
....}
class amount(osv.osv):
_name = 'amount'
def _get_folder_list_biens(self, cr, uid,folder_id, context={}):
liste_goods=[]
object_folder = self.pool.get('folder').browse(cr,uid,folder_id,context)
if object_folder.goods_ids:
for good in object_folder.goods_ids:
liste_goods.append(good.id)
return liste_goods
_columns = {
'folder_id': fields.many2one('folder', 'Ref folder', select=True),
'good_id':fields.many2one('good', Goos',domain="[('id', 'in', _get_folder_list_biens(folder_id))]"),
}
I got this error:
Uncaught Error: NameError: name '_get_folder_list_biens' is not defined
The domain is used on the client when the user starts to key (or lookup) and Good and it (the client) knows nothing about this method. What you need to do is create a functional field of type many2one that calls _get_folder_list_biens and returns a list of ids. Put the new functional field on your form as invisible and then make your domain ('id', 'in', my_functional_field)