odoo- add custom fields in advaced search? - odoo

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')
}

Related

Calling a studio field ? Odoo V14

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

Extend States for Model in Odoo 11

I want to extend the "state" column of the mrp.production model. There was an example I found in https://www.odoo.com/de_DE/forum/how-to/developers-13/how-to-extend-fields-selection-options-without-overwriting-them-21529 but it seems to not work in odoo 11.
i.e. the __init__ signature changed to __init__(self, pool, cr) (guessing this from the error trace that I saw referencing model.__init__(pool, cr))
from odoo import models, fields
import logging
_logger = logging.getLogger(__name__)
class mrp_production(models.Model):
_inherit = 'mrp.production'
def __init__(self, pool, cr):
super(mrp_production, self).__init__(pool, cr)
states = self._columns['state'].Selection
_logger.debug('extend state of mrp.production')
state_other = ('other_state', 'My State')
if state_other not in states:
states.append(state_other)
The Error I'm receiving is:
AttributeError: 'mrp.production' object has no attribute '_columns'
You don't need to extend the __init__. Please look into the documentation to get a first look how to extend odoo business models.
For your example the correct code:
from odoo import models, fields
class MrpProduction(models.Model):
_inherit = 'mrp.production'
state = fields.Selection(
selection_add=[('other_state', 'My State')])
The tutorial you follow is for old API.
You can try
https://www.odoo.yenthevg.com/extend-selection-odoo-10/
from odoo import models, fields, api, _
class HrEmployee(models.Model):
_inherit = 'hr.employee'
gender = fields.Selection(selection_add=[('transgender', 'Transgender')])

How to get all customization from product in prestashop 1.6

I create a module. Which add new tab in product, back office. In this tab I want to display all customization text. Which is define in customization tab. The problem is I don't know how to do that. There is a product, customization or customizationField classes.
I my module I have:
public function getCustomizationFields(){
$getCustomizationFields = Product::getCustomizationFieldIds();
return $getCustomizationFields;
}
There is no error. Always I have output like this:
array(0) { }
Is there any class which I can use for my purpose ? Thanks for any help.
Kind regards
If you have an instance of the Product class, you can do this:
$instance = new Product($product_id);
$instance->getCustomizationFields();
How about
public function getCustomizationFields(){
$productId = (int)Tools::getValue('id_product');
$product = new Product($productId);
$getCustomizationFields = $product->getCustomizationFieldIds();
return $getCustomizationFields;
}

How can I add a field in a model in odoo 9 new API?

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.

Many2one value display in OpenERP

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.