This question has been flagged

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

Avatar
Discard