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 create conditions in Odoo 8.0 New API

By
Dr Obx
on 4/11/15, 10:31 AM 818 views

Guys, need help with this code.

Whatever a'm doing it still gives me an error.


class Product_Template(models.Model):

_inherit = "product.template"

prod_name = fields.Char(compute="_get_prod_name", string="Product Name")

@api.one

@api.depends("product_lines_id", "condition", "processor", "product_brand_id", "product_sermod_id", "product_connection_id", "product_casesize_id", "product_capacity_id", "oddtype")

def _get_prod_name(self):

condition = self.condition or ' '

processor = self.processor.name or ' '

product_brand_id = self.product_brand_id.name or ' '

product_sermod_id = self.product_sermod_id.name or ' '

product_connection_id = self.product_connection_id.name or ' '

product_casesize_id = self.product_casesize_id.name or ' '

product_capacity_id = self.product_capacity_id.name or ' '

oddtype = self.oddtype or ' '

@api.onchange('product_lines_id')

def _onchange_product_lines_id(self):       # depending on what is the value of product_lines_i

if self.product_lines_id is ('Computer",):     # i would like to change set of elements combined into "name"

name = ustr(condition) + ' ' + ustr(product_brand_id) + ' ' + ustr(product_sermod_id)

if self.product_lines_id is ('Monitor",): 

=>here i would like to add some "if" (conditions), depending on what kind of product was chosen.

for example:

if product_type = 'computer':

name = ustr(processor) + ' ' + ustr(product_connection_id) + ' ' + ustr(product_casesize_id) + ' ' + ustr(product_capacity_id)

if product_type = 'monitor':

name = ustr(brand) + ' ' + ustr(product_connection_id) + ' ' + ustr(product_size_id) + ' ' + ustr(product_ratio_id)

and so on.....


self.name = name

self.prod_name = name

So at the end name will be created from specified variables/elements

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: 4/11/15, 10:31 AM
Seen: 818 times
Last updated: 6/17/15, 12:02 PM