Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to change a boolean field based on another field? (when a many2one is created)

By
Skander
on 1/20/16, 10:54 AM 459 views

Hello everyone, i'm new to odoo developing and this is my first module.

I want to assign material resources to project task.(most of the time vehicles, we have many)

I want to know which cars are free and which ones are assigned to tasks.

So i created a boolean field named assigned to be True when a material resource is added to a task(i.e task_id is no more null), but it is always false when i check the database.So the function i created seems to not work for some reason.

from openerp import models, fields, api
class MaterialResource(models.Model):
    _name = 'material.resource'
    name = fields.Char('Material Resource', required=True)
    description = fields.Selection(string='Description', selection=[('m', 'Mazda'), ('f', 'Ford')])
    task_id = fields.Many2one("project.task", inverse_name="material_resource_ids")
    assigned = fields.Boolean(compute="_get_material_status", store="True")
    @api.one
    @api.depends('task_id')
    def _get_material_status(self):
        if self.task_id is None:
            return False
        else:
            return True
class TaskMaterial(models.Model):
    _inherit = 'project.task'
    material_resource_ids = fields.One2many(comodel_name="material.resource", inverse_name="task_id", string="Material Resource")
1

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 1/21/16, 4:25 AM

Hi,

Try like this:

from openerp import models, fields, api

class MaterialResource(models.Model):

_name = 'material.resource'

name = fields.Char(string='Material Resource', required=True)

description = fields.Selection(string='Description', selection=[('m', 'Mazda'), ('f', 'Ford')])

task_id = fields.Many2one("project.task", string="Task")

assigned = fields.Boolean(compute="_get_material_status", string="Assigned")

@api.one

@api.depends('task_id')

def _get_material_status(self):

if self.task_id:

self.assigned = True

else:

self.assigned = False

class TaskMaterial(models.Model):

_inherit = 'project.task'

material_resource_ids = fields.One2many("material.resource",'task_id', string="Material Resources")

1

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
Tiny ERP Pvt Ltd
http://www.odoo.com
5975
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.

 

Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 

 

We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :

 

  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 1/20/16, 1:35 PM

Try following:

@api.one    
@api.depends('task_id')
def _get_material_status(self):
if self.task_id:
self.assigend=True
    else:
        self.assigned=False
   



 

0
Skander
On 1/21/16, 10:38 AM

Thank you i have tried all of these but it's still False.

task_id takes numbers (1,2,3...) which is normal when i execute select * from material_resource;

but when i test it in the view, <field name="task_id"/> shows the name of the task it's very strange i don't understand!

Anyway i've found another solution: i create a filter ( task_id is not set) which syntax is domain="[[u'task_id', u'=', False]]"

i can get the same result with it.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/20/16, 10:54 AM
Seen: 459 times
Last updated: 1/21/16, 10:38 AM