I tried to create a simple Many2one field but the values are showing in this format: new.base,1 and new.base,2 and so on. Please let me know the fix so as to display value for the same.
class latest_base(osv.osv):
_inherit = ['mail.thread']
_name='latest.base'
_columns={
'name':fields.char('Name',required=True),
'image': fields.binary("Image", help="Select image here"),
'email':fields.char('Email'),
'code':fields.many2one('new.base','code'),
}
latest_base()
class new_base(osv.osv):
_name='new.base'
_columns={
'code':fields.char('Department'),
'hod':fields.char("Head of the Department"),
}
new_base()
try this, name is a Special fields in OpenERP and unique name used by default for labels in forms, lists, etc. If we don't use a name in table than we use _rec_name to specify another field to use.
class latest_base(osv.osv):
_inherit = ['mail.thread']
_name='latest.base'
_columns={
'name':fields.char('Name',required=True),
'image': fields.binary("Image", help="Select image here"),
'email':fields.char('Email'),
'code':fields.many2one('new.base','code'),
}
latest_base()
class new_base(osv.osv):
_name='new.base'
_rec_name = 'code'
_columns={
'code':fields.char('Department'),
'hod':fields.char("Head of the Department"),
}
new_base()
Hope this will solve your problem.
because you have not declared name field in your model, openerp returns name field value by default, if you want set other field as just define _rec_name='field_name' you will get value of that field.
Related
I would like to know if it's possible or not to call an Odoo studio field in a model like this ?
class sale_order(models.Model):
_inherit = "sale.order"
#api.onchange('x_studio_first_field')
def _onchange_firstfield(self):
if self.x_studio_first_field:
self.x_studio_second_field = self.x_studio_first_field
Thanks by advance
Apparently, the answer is what i've write in exemple. I tried it and it works !
class sale_order(models.Model):
_inherit = "sale.order"
#api.onchange('x_studio_first_field')
def _onchange_firstfield(self):
if self.x_studio_first_field:
self.x_studio_second_field = self.x_studio_first_field
I am trying to add a new field in the model of SaleOrderLine (Official Sale module).
It works perfect with the old API:
from openerp import _
from openerp.osv import osv, fields
class SaleOrderLineExt(osv.osv):
_inherit = ['sale.order.line']
_columns = {
'my_field_code': fields.float(string='My field Code'),
}
But, If I try to use the new API, the field is not created in the database.
from openerp import api, fields, models, _
class SaleOrderLineExt(models.Model):
_inherit = ['sale.order.line']
my_field_code = fields.Float(string='My field Code'),
I have read the Odoo new API guideline and it appears that my code is right, but it is not working.
What am I doing wrong?
Try with following code.
from openerp import api, fields, models, _
class SaleOrderLineExt(models.Model):
_inherit = 'sale.order.line'
my_field_code = fields.Float(string='My field Code')
Remove , at the end of field declaration.
Just Remove the semicolon which is at the end of field. You code will definitely work.
i'm trying to add product description to purchase advanced search menu
class purchase_order_line(osv.osv):
_inherit = 'purchase.order.line'
_columns = {
'name':fields.text(string='Description')
}
Your question is not clear for me. But i noticed an error in your code. You missed an equal sign after _columns. Try below code.
class purchase_order_line(osv.osv):
_inherit = 'purchase.order.line'
_columns = {
'name':fields.text(string='Description')
}
I have a custom module called admission form with some fields suppose name, phone, email, etc. how to add this form to website module using templatr to work like contact form in contact us page when filled data is automatically created in new leads. instead of leads i want it to transfer the information to my custom module.
Summary: instruction to relate website to custom module.
class AdmissionForm(models.Model):
_name = 'admission.form'
name = fields.Char()
phone = fields.Integer()
email = fields.Char()
faculty = field.Many2one('res.faculty')
In ODOO Whenever you want to performe some task at the time of creation ,then you must override create method in your model (:admission.form).
Let say you want to create a partner just after creation of the record in admission.form model then follow these steps:
Override create method .
Call the super with the argument and hold it value in result.
Now do your task .
return result.
Code snippet:
#api.model
def create(self, vals):
result = super(AdmissionForm, self).create(vals)
new_vals = dict(name=result.name,
phone=result.phone,
email=result.email,
is_company=1,
supplier=1,
customer=1,
)
self.env['res.partner'].create(new_vals)
return result
In case if you want to do some task before creation of record then follow these steps:
Override create method .
Do your task .
Call the super with the argument and return it.
#api.model
def create(self, vals):
new_vals = dict(name=vals.get('name'),
phone=vals.get('phone'),
email=vals.get('email'),
is_company=1,
supplier=1,
customer=1,
)
partner=self.env['res.partner'].create(new_vals)
return super(AdmissionForm, self).create(vals)
I am new at django and autocomplete-light. I try to get a different fields of the model from autocomplete-light, but it always return the same field. And the reason is because def in the Model defined one field. So I created another def, but can not make autocomplete-light to call that specific def. Here is my code.
models.py:
class Item(models.Model):
...
serial_number=models.CharField(max_length=100, unique=True)
barcode=models.CharField(max_length=25, unique=True)
def __unicode__(self):
return self.serial_number
def bar(self):
return self.barcode
.......
autocomplete_light_registry.py
autocomplete_light.register(Item,
name='AutocompleteItemserial',
search_fields=['serial_number'],
)
autocomplete_light.register(Item,
name='AutocompleteItembarcode',
search_fields=['barcode'],
)
Here is the issue: when I try to get the barcodes from the autocomplete-light, it returns serial_numbers. No matter what I try to get from the Item model, it always returns the serial number. I really appreciate for the answers. Thank you.
Just in case, here is the form.py
forms.py
class ItemForm(forms.ModelForm):
widgets = {
'serial_number': autocomplete_light.TextWidget('AutocompleteItemserial'),
'barcode': autocomplete_light.TextWidget('AutocompleteItembarcode'),
}
Although this is an old post but as I just faced the same issue therefore I am sharing my solution.
The reason autocomplete is returning serial_number is because django-autocomplete-light uses the __unicode__ method of the model to show the results. In your AutocompleteItembarcode all that is being done is autocomplete-light is searching by barcode field of Item.
Try the following.
In app/autocomplete_light_registry.py
from django.utils.encoding import force_text
class ItemAutocomplete(autocomplete_light.AutocompleteModelBase):
search_fields = ['serial_number']
model = Item
choices = Item.objects.all()
def choice_label(self, choice):
"""
Return the human-readable representation of a choice.
"""
barcode = Item.objects.get(pk=self.choice_value(choice)).barcode
return force_text(barcode)
autocomplete_light.register(ItemAutocomplete)
For more help you can have a look at the source code.