How to get create and edit option in dropdown in openerp - openerp-7

i have separate drop down field and at present i have given static values. i need to get dynamic values like a user should able to add the values and should show in the drop down.
Thanks in advance.

You can define many2one field for this purpose.
_columns = {
'your_field_name' : fields.many2one('object', string='My field')
}
Example
_columns = {
user_id = fields.Many2one('res.users', string=u"User")
}
So you will got list of users. Whatever object list you can define many2one field.

Related

Get value from customer_entity_varchar - Magento

I created a customer attribute in backend magento, but I want to show this attribute to the user so that he can alter its value in the frontend. My input field is being displayed in the frontend, but the value is not there. I am not able to get this value. I found that the value that I need to display is in the apscustomer_entity_varchar table and the column is called 'value'. How can I get that value from that table? I was trying this:
$collection = Mage::getModel('eav/entity_attribute')->getCollection();
foreach ($collection as $data) {
return $data;
}
but it was not working, so I used SQL code and it worked. However I know that's not a nice way to do that in Magento. What I did was something like:
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT * FROM `apscustomer_entity_varchar ` WHERE `entity_id`='$id'";
$rows = $connection->fetchAll($sql);
How can I get the value column from my apscustomer_entity_varchar table in the magento way, using the getModel?
You need to retrieve the customer of the session and then you can get the attribute you want :
Mage::getSingleton('customer/session')->getData('attributeName');
Mage::getSingleton('customer/session')->getAttributeName(); //Magic getter
Where attributeName is the name of the attribute you want to get the value.
I found out how to do that :D
It's actually very simple. Even if this is a custom customer attribute (created in Magento admin panel), I need to get the attribute not using the 'eav/entity_attribute' model, but using the 'customer/customer' model. So I just need to do that:
$customer_data = Mage::getModel('customer/customer')->load($customer_id)->getData();
echo $customer_data['attributeThatYouWant'];
If you are not sure what is the name of your attribute you can look at Magento Admin Panel under Customer/Manage-Attributes, or you can use that after getting the model:
var_dump($customer_data);
Now you are able to get the name of all customer attributes.

How to get data is on a remote server using odoo

On a remote server I have data in this form:
A project contains one or more tranches
A tranche contains one or more units
On my class odoo, I added these fields:
project_id: this is a many2one field to select the project. I can get back the list of project from the remote server
Tranche_id: A many2one field to select the tranche. I need when I change the project, this field should just list the tranches of the selected project.
Entity_id: A many2one field to select the Entity. I need when I change the tranche, this field should just list the entities of the selected tranche.
Is it possible to implement the many2one relation on Odoo with the constraint that the data is on a remote server and consumable REST API?
Help me please
Kindly.
Try this code:
#api.onchange('project_id')
def onchange_project_id(self):
res = {}
if self.object_id:
res['domain'] = {'tranche_id': [('project_id', '=', self.project_id.id)]}
return res
#api.onchange('tranche_id')
def onchange_tranche_id(self):
res = {}
if self.object_id:
res['domain'] = {'entity_id': [('tranche_id', '=', self.tranche_id.id)]}
return res
It may help in your case.

access to many2one fields

I have a many2one field like this
state = fields.Many2one ("ags.traffic.operation.state")
state has the following fields
name = fields.Char
sequence = fields.Integer
type = fields.Selection
in my view i have
<field name = "state" widget = "statusbar" clickable = "True" / >
how can i access those fields to set a default value?
if you want to define the field that gets shown in the drop-down in your view in your model define _rec_name this tells odoo to display that field (in a drop down or in a many2many tag field) when a many2one or one2one relationship is created between that model and another model. for example if you want the sequence number to display in the drop down just set
_recname = 'sequence'
but by default odoo checks the model's field and if it finds a name field (just like you have defined in your model). it uses that as the default display name.
if you want to search records in odoo you can use the search method. please see the documentation for more information about the odoo ORM
https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model.browse
search(args[, offset=0][, limit=None][, order=None][, count=False])
but a typical example is
search_records = self.env['your.model'].search([('id', 'in', ids)])

Openerp 7 many2one dropdown should display field of related record

If you install Openerp 7 with recruitment module. And create a simple entry with following values e.g.
Subject (internal field name = 'name') = 10 Year Experience
Applicant Name = Jhon Smith
Then if you create a custom module with following columns
_columns = {
'applicant_id': fields.many2one('hr.applicant', 'Applicant', required=True),
}
The view widget by default will show a drop-down with the Subject (internal field name ='name') field but i want to show applicant name (internal field name='partner_name') field in drop down, when creating a new record in my custom module.
In Summary how can I display Applicant's Name instead of Subject in drop-down widget in my custom module.
In openerp there is a function called name_get().This function returns a list of tuples containing ID of the record and name tobe displayed. So override this function and return list of tuples containing ID of the record and applicant name
You need to define applicant_id in _rec_name in your custom module.
Try this:
_rec_name = 'applicant_id'
Have a look at Predefined fields.

SPListItem id from SPField object

I am working on create a custom field type and for implementation issue I need to retrieve the ID of the SPListItem in the SPField class which belong to these field type but I can't retrieve it.
For example:
public class myField:SPFieldText
{
// I need ListItemID in this class
}
Can anyone help me please?
SPFieldText is an SPField, which is the schema definition for a field. Its like saying, given an SQL create table statement, give me the id of row x. Can't be done.
I think the logic you are trying to perform should be done in an event receiver, so say when an item is saved, you take the ID and add it to the text field.
I didn't find a solution but I've tried another solution which is
I can get the ID of the item in the New and Edit forms so I saved the ID and the field value as a one value separated by '/' and in the SPFieldText class I've been able to retrieve the ID value from the value of the field