Here is what I want to do:
in the invoice screen, when creating new invoice, we select partner (customer or supplier). when you start typing characters the system bring partner name starting with those characters. I want the system to search not only name but also partner_code (this column I added to res.partner). So, the solution I though about is to override the display_name which is a compute field to make ti include both partner_code and name, instead of name only. i linked the display_name field with a compute method. But, my problem is that compute method is not triggered at all.
Please help me find out why it is not triggered.
here is the code:
from openerp import fields, models, api, _ # TODO: make the 'Code and Name' labels in Partner and Product dynamic calling a method so the text can be translatable # -------------------------- Product # noinspection PyPep8Naming class product_template(models.Model): #_name = 'product.template' # this is Odoo object product.product which is related to table product_product _inherit = 'product.template' # TODO: add default_code to tree view product_supplier_code = fields.Char(string=_("Product Supplier Code"), help=_("Product Code that your supplier uses")) product_brand = fields.Char(string=_("Brand Name")) @api.one @api.onchange('default_code') def make_pc_uppercase(self): if (self.default_code): self.default_code = (self.default_code).upper() # TODO: in product module, upon change check uniqueness @api.onchange('product_supplier_code') def make_spc_uppercase(self): if (self.product_supplier_code): self.product_supplier_code = (self.product_supplier_code).upper() class product_product(models.Model): #_name = 'product.product' _inherit = 'product.product' _sql_constraints = [ ('default_code','unique(default_code)',_('Product Code Already Exists !!')) ] class res_partner(models.Model): # _name="res.partner" _inherit = "res.partner" partner_code = fields.Char(string="Partner Code", help=_("Partner (Customer / Supplier) Code")) display_name = fields.Char(string="Name", compute='_display_name_compute') #, search='_search_partner') _sql_constraints = [ ('partner_code','unique(partner_code)',_('Partner Code Already Exists !!')) ] # def _search_partner(self): # return "00000000000000000" # # what? @api.one @api.constrains @api.depends('name', 'partner_code') # this definition is recursive def _display_name_compute(self): self.display_name = self.partner_code + ' - ' + self.name print "===========================================================" # if self.partner_code: # self.display_name = self.partner_code + ' / ' + self.display_name + ' / ' + self.name # else: # self.display_name = '-' + self.name + ' / ' @api.one @api.onchange('partner_code') # @api.constrains('partner_code') def onchange_partner_code(self): if (self.partner_code): self.partner_code = (self.partner_code).upper() records = self.search([('partner_code', '=', self.partner_code)]) print "==========================================================::::::: ", len(records) if len(records) > 1: # if only 1 record is found means we are ok. we just found the record we are creating. raise Warning(_("This Partner Code already exists!")) # if raise XXX is called the method will exit from here and will not continue return True else: print "partner code is still FALSE :::::::::::::::::::::::::::::::::::::" # def redirect_partner_form(self, cr, uid, partner_id, context=None): # search_view = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'odootec_view_res_partner_filter') # value = { # 'domain': "[]", # 'view_type': 'form', # 'view_mode': 'form,tree', # 'res_model': 'res.partner', # 'res_id': int(partner_id), # 'view_id': False, # 'context': context, # 'type': 'ir.actions.act_window', # 'search_view_id': search_view and search_view[1] or False # } # return value
Sorry code is scrambled. I posted another question regarding that.