create sequence depending on a Many2one field - odoo-8

I have this object project.task that has many situations project.task.situation . In project.task.situation model I want to create a sequence so I added this record:
<record id="sequence_project_task_situation_seq" model="ir.sequence">
<field name="name">Project Task Situation Sequence</field>
<field name="code">project.task.situation</field>
<field name="prefix">Situation N°</field>
<field eval="1" name="number_next"/>
<field eval="1" name="number_increment"/>
<field eval="False" name="company_id"/>
</record>
In python code I added this:
name = fields.Char(string='Situation Number', readonly=True)
#api.model
def create(self, vals):
seq = self.env['ir.sequence'].next_by_code('project.task.situation') or '/'
vals['name'] = seq
return super(ProjectTaskSituation, self).create(vals)
what I want is each task has its own situation sequence. For example for task1 I create 2 situations so I have Situation N°1 and Situation N°2 after that I want to create situations for task2 so I'll get Situation N°3 and Situation N°4 . Which is not good cause I want for each task to start count sequence from the start. Is this possible? How is that?

Related

How to store image name as File Content in(ir.attachment) in odoo?

When I created a product in 'product.template' that time I give the image for the particular record. So the record creates successfully but when I check the attachment of that record using Postgres.
select * from ir_attachment where res_id=107 and res_model='product.template'
After I go to attachment record and check the File Content name is blank. So When I was the download the image name is given False.
So how to resolve this issue and it is odoo default flow.
In Odoo 11 this is a problem. So that you have to add an extra field for the name itself. For example;
in python class
attachment = fields.Binary(string="Attachment", track_visibility="onchange")
fname = fields.Char(string="File Name", track_visibility="onchange")
in XML:
<group>
<field name="attachment" filename="fname" widget="download_link" string="Attachment"/>
<field name="fname" invisible="1"/>
</group>
Try this, this will work. Don't forget to upvote and put tick mark too. Thanks in advance !
In Odoo 12
Python:
file_name = fields.Char("File Name")
attachment = fields.Binary("Image")
XML
<field name="file_name" invisible="1"/>
<field name="attachment" filename="file_name" widget="FieldBinary"/>

How to show specific values in radio field?

Suppose I have a field in a view like below:
<field name="some_name" widget="radio"/>
where,
some_name = fields.Selection([
('val1', 'val1'),
('val2', 'val2'),
('val3', 'val3')
])
Now, suppose I have another view. There I want to get the field using xpath like:
<xpath expr="//field[#name='some_name']"></xpath>
and there I want to display only the first two options of some_name. In odoo 11, How can I do that ?
You should try this in XML file:
<field name="some_name" attrs="{'invisible':[('some_name','==','val3')]}" invisible="1"/>

Odoo. I'd like to make invisible the record in tree view, depending value of one field

Openerp, Odoo question.
I'd like to hide the row in tree view depending one field (e.g. item is not in stock).
Maybe I need to put this somewhere in tree_view.xml:
attrs="{'invisible': [('in_stock','=', 0)]}"
It would be fine, if this works, like the res_partner 'Active' flag
When 'Active' field is False, all record is disappeared.
Any advice would be appreciated!
If you want to hide the record completely than use this domain in the window action. To show only the records that matches the domain.
<field name="domain">[('in_stock', '=', 0)]</field>
You can hide using the following syntax:
<field name="flag" invisible="1"/>
<field name="x" attrs="{'invisible': [('flag','=', False)]}"/>
Here flag should be a computed field which computes the stock of current item.
so in script just make the field as:
flag = fields.Boolean("String", compute="get_stock_status")
def get_stock_status(self):
# do your computation and change values of flag accordingly
self.flag = False

How can I set the attribute of a field to required=True or required=False based on the value of another field?

I have a selection field in the res.partner model which is employmentstatus and the options there are employed
or unemployed. I want another field employmenttype have the attribute required=True if the employmentstatus='employed'
or required=False if the employmentstatus='unemployed'. The field right now sets required to True whether Partner is
employed or not (See attached image here).
Here is my code:
from openerp.osv import osv, fields
from openerp import tools
class custom_fields_partner(osv.Model):
_inherit = 'res.partner'
_columns = {
'employmentstatus' : fields.selection([
('employed','Employed'),
('unemployed','Unemployed')
],'Employment status', required=True, default='unemployed'),
'employmenttype' : fields.selection([
('0','Public'),
('1','Private'),
('2','Mission')],'Nature of employment', required="fieldproperty"),
}
#api.one
def fieldproperty(self):
if self.employmentstatus == 'employed':
return True
else:
return False
The required attribute is expected to be stored in the database and is not meant to be calculated on the fly. Best bet is to do it client side. If you look in the model ir.model.fields you will notice the the required field is stored in the db and is not meant to be computed.
In your xml use the attrs attribute. Here is an example.
<field name="field_name" attrs="{'required':[('other_field','=','other_value')]}"/>
So in this example the field called field_name is required only if the field other_field has a value of other_value but your can create a domain criteria that is more complex or less complex depending on your needs.
The field other_field mush be present in your view in order for this to work because the evaluation takes place client side. If you need to include a field for evaluation but do not want to display it you can make it invisible. Like this.
<field name="other_field" invisible="1"/>

Populate (tree) view from list generated in model?

What I'm trying to achieve is simple: I made a wizard that asks the user to provide a RMA ID (that's a pop-up). Once that is submitted, I perform some operations in the backend and build a list containing all the other products in the order that's being RMA'd. I then need to ask the user to verify that all those products are in the physical RMA.
Now, I'm stuck right after building my list. How can I send that list to OpenERP, have it generate a TreeView from it so that the user can individually select products that have been located (and the ones that haven't)?
I'm assuming I'll need an additional view.xml, buy I have no idea about:
1) What to insert in the <field name="arch" type="xml> node
2) How to send my custom list/object to OpenERP/odoo
In other words, I have a list that I'm trying to send to OpenERP/odoo to be displayed in a TreeView. How?
Thanks for your help!
#Pier
Considering for Odoo-v8.
From my understanding you can try the following:
In you wizard you need to have a one2many field say product_line_ids, which will shown in your wizard.
So you will two classes, see the following structure
class rma_wizard(models.Model):
_name = 'rma.wizard'
rma_id = fields.Many2one('rma.master',string="RMA")
prodcut_line_ids = fields.One2many('product.line','wizard_id',string="Products")
#api.onchange('rma_id')
def rma_id_change(self):
code to get the list of products and use the following code to add in the wizard
final_products_list = []
products= {}
for product in product_list:
result = {}
result.update({'product_id':product.id})
final_product_list.append(result)
self.product_line_ids= final_product_list
class product_line(models.Model):
_name='product.line'
wizard_id = fields.Many2one('rma.wizard',stirng="RMA")
product_id=fields.Many2one('product.product',string="Products")
select_product=fields.Boolean("Select")`
and the Views:
<record name="rma_wizard_view" model="ir.ui.view"/>
<field name="name">RMA Wizard</fieeld>
<field name="model">rma.wizard</field>
<field name="type">form</field>
<field name="arch" type="xml">
<field name="rma_id"/>
<field name="product_line_ids>
<tree string="Products">
<field name="product_id"/>
<field name="select_product"/>
</tree>
</field>
</field>
</record>
Now you can put the check mark select as per your need and perform operation on it
Hope this helps!!

Resources