Select from difiirents fields models Methode odoo8 - odoo

Can I select some data fields from different models and display these fields in my tree view, then I modify my selection and persist in other models?
'#api.v8
def get_data(self):
data = self.env['my.models]].browse(id)'

There are 3 ways to provide selection list values that is accepted by OpenERP:
Specifying directly in the field.selection definition: 'field_1':
fields.selection([('value1', 'String 1'), ('value2', 'String 2')],
'Field Label')
Specifying using a name list variable outside of the field.selection
definition: 'field_1': fields.selection(LIST_VARIABLE, 'Field
Label'). Where LIST_VARIABLE is defined beforehand: LIST_VARIABLE =
[('value1', 'String 1'), ('value2', 'String 2')]
Specifying using a method: 'field_1': fields.selection(_method_name,
'Field Label'). Where _method_name is defined beforehand:
def _method_name(self, cr, uid, context=None):
return [('value1', 'String 1'), ('value2', 'String 2')]
Now, you need to check first which one is your current selection field is. If it is using method No. 1, then you need to redefine it to use either method No 2 or method No 3. If it is using method No. 2 or 3, you just need to change either the variable (you can use LIST_VARIABLE.append(('value3', 'String 3'))) to return the new value.

Related

Dynamic ASSIGN of table row expression

In my ABAP report I have some structure:
data:
begin of struct1,
field1 type char10,
end of struct1.
I can access to it's field field1 directly:
data(val) = struct1-field1
or dynamically with assign:
assign ('struct1-field1') to field-symbol(<val>).
Also I have some internal table:
data: table1 like standard table of struct1 with default key.
append initial line to table1.
I can access to column field1 of first row directly:
data(val) = table1[ 1 ]-field1.
But I can not get access to field1 with dynamic assign:
assign ('table1[ 1 ]-field1') to field-symbol(<val>).
After assignment sy-subrc equals "4".
Why?
The syntax of ASSIGN (syntax1) ... is not the same as the syntax of the Right-Hand Side (RHS) of assignments ... = syntax2.
The syntax for ASSIGN is explained in the documentation of ASSIGN (variable_containing_name) ... or ASSIGN ('name') ... (chapter 1. (name) of page ASSIGN - dynamic_dobj).
Here is an abstract of what is accepted:
"name can contain a chain of names consisting of component selectors [(-)]"
"the first name [can be] followed by an object component selector (->)"
"the first name [can be] followed by a class component selector (=>)"
No mention of table expressions, so they are forbidden. Same for meshes...
Concerning the RHS of assignments, as described in the documentation, it can be :
Data Objects
They can be attributes or components using selectors -, ->, =>, which can be chained multiple times (see Names for Individual Operands
Return values or results of functional methods, return values or results of built-in functions and constructor expressions, or return values or results of table expressions
Results of calculation expressions
Sandra is absolutely right, if table expressions are not specified in help, then they are not allowed.
You can use ASSIGN COMPONENT statement for your dynamicity:
FIELD-SYMBOLS: <tab> TYPE INDEX TABLE.
ASSIGN ('table1') TO <tab>.
ASSIGN COMPONENT 'field1' OF STRUCTURE <tab>[ 1 ] TO FIELD-SYMBOL(<val>).
However, such dynamics is only possible with index tables (standard + sorted) due to the nature of this version of row specification. If you try to pass hashed table into the field symbol, it will dump.

Oracle APEX 18.2 -> need dynamic action based on list of values to make a field required

When overall_status in list ('Yellow Trend Up'...etc) then overall_description is required for user to enter information
overall_status:
Select List, Required-Above, Status Values(Red Trend Up, Yellow Trend Up) Dynamic Action * When Event=Custom, item=overall_status, condition=overall_status=Yellow Trend Up
True: Action=Show, Affect Elements=overall_description
overall_description:
Text Field * Appearance=Optional-Above
Validation=Value Required (YES)
When i run application/page and select Yellow Trend Up a Popup window appears with
Leave site? Changes you have made may not be saved Leave Cancel
Not sure what True: Action should be selected
Assuming you want the user to be required to fill in a description field when a certain value from the selection list is selected (like 'Yellow Trend Up' in this example), then a simple way to achieve this is to:
Create 'overall_status' as Select List.
For 'Page Action on Selection' choose: 'Redirect and Set Value'.
Create 'overall_description' as Text Field.
For 'Value Required' choose: 'Yes'.
In the 'Conditions' section of 'overall_description', choose 'Condition Type': 'Value of Item / Column in Expression 1 = Expression 2'.
For Expression 1 enter: 'overall_status'.
For Expression 2 enter: 'Yellow Trend Up'.
If you want to show this required description field if any value is selected in your 'overall_status' Select List, then choose 'Value of Item / Column in Expression 1 Is NOT NULL' and Expression 1 as 'overall_status'.

odoo 8 selection field self always empty

I have to create a selection field based on other column. i mean the data comes from other table but based on current table column value. so i created a selection field as below:
pull_location = fields.Selection(selection='_get_pull_locations',string='Pull Location')
and the function is as below:
#api.multi
def _get_pull_locations(self):
data=[]
** Get the values from other table based on current record **
return [('value1', 'String 1'), ('value2', 'String 2')]
Always when i debug i get self as empty class object ( stock.test()). the scenario is i have a column named zone in stock.test, i have another table called stock.location, so for current record i check the stock.location table where column pull_zone == zone of stock.test and if yes append the selection (pull_location) with that values.
But always the object is empty.
I tried #api.one, #api.multi, #api.model , Nothing happens.
Please help.
Thanks,
Replace your code with following:
#api.multi
def _get_pull_locations(self):
** Get the values from other table based on current record **
return [
('value1', 'String 1'),
('value2', 'String 2')
]
pull_location = fields.Selection('_get_pull_locations', string='Pull Location')
Afterwards, Restart Odoo server and upgrade your module.

How does domain works in openerp as well as xml?

I am working on domain and I'm not getting how it works exactly , below I have given my code pls tell me how could I use it and how it fits into my code.
class test_cl(osv.osv):
_name = 'test.cl'
_columns ={
'name':fields.char('Name',size=20),
'age':fields.integer('Age',size=10),
'gender':fields.selection([('m','M'),('f','F')],'gender'),
'tel_no':fields.char('Telephone',size=100,),
'emailid':fields.char('Email id',size=20),
'website':fields.char('Web address',size=20),
'company':fields.char(
'Company name',
size=100,
domain=[('choice','=',YES)],
change_default=True,
),
'desg':fields.char('Designation',size=100),
'wght':fields.float('Weight'),
'choice':fields.selection(
[('yes','YES'),('no','NO')],
'Working',
required=True,
),
}
_defaults = {
'age':30,
}
test_cl()
Domain restricts your record to display. It is a condition for your records. For example.
_columns = {
'partner_id': fields.many2one('res.partner', 'Partner', domain=[('name', '=', 'greywind')])
}
So when you click on the partner_id field on the web client. it will run a search method & execute a query like
select id from res_partner where name='greywind';
and you can see only partner with name greywind.
Domains are tuples, the structure is (field, operator, value).
Field is the data in the database, Operator is the comparison, = equal, != not equal, > greater than, < less than, etc. Value is the data you want to compare with the field, it can be another database field, a constant or a calculated value.
Domains limits possible choices for many2one, many2many and one2many fields to use only objects that satisfies . For example in stock.production.lot
'product_id': fields.many2one('product.product', 'Product', required=True, domain=[('type', '<>', 'service')]),
allows to use only products that are not service. In your code there is no fields related to other objects so there is no application for domains.

Keeping the previous value of an attribute

I have the following situation: If the name attribute of my student object changes, I want to keep the old value and save it to another table.
So, If I have a student object with the name attribute 'John 1', after a student.update_attributes(:name => 'John 2') I want to be able to capture the old name value 'John 1' in a before_update callback hook, for instance. What's the best way to do that ? Thanks in advance.
In the before_update hook, you can access special _was methods to get the previous value of each field
before_update do
new_name = self.name # 'John 2'
old_name = self.name_was # 'John 1'
end