Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
5893 Lượt xem

How to save the reference of every product as uppercase (when click on the "save" button)

please some help in both xml code and python code !

thank you

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

overwrite WRITE method and change the value passed through it as UPPERCASE conversion.

from openerp import models, api
class Product(models.Model):
    _inherit = 'product.product'

    @api.model
    def create(self, vals):
        if vals.get('default_code', False):
            vals['default_code'] = vals.get('default_code', '').upper()
        return super(Product, self).create(vals)

    @api.multi
    def write(self, vals):
        if vals.get('default_code', False):
            vals['default_code'] = vals.get('default_code', '').upper()
        return super(Product, self).write(vals)


To resolve old data, do an one time sql query
update product_product set default_code=UPPER(default_code) 

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Please, inside which class (product.product or product.template) should i insert the method ?

Ảnh đại diện
Huỷ bỏ
Actually, i created a new module and inherited the product form view in wich i added the reference field.
now it shows FALSE instead of being empty :p !!!

__________________
Hicham TAROQ
Élève Ingénieur à l'Institut National des Postes et Télécommunications-INPT Rabat



On Tue, Apr 14, 2015 at 3:52 PM, Atchuthan - Technical Consultant, Sodexis Inc <atchuthantu-gmail.com@mail.odoo.com> wrote:

Product.Product

--
Atchuthan - Technical Consultant, Sodexis Inc
Sent by Odoo Inc. using Odoo access your messages