Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
1 ตอบกลับ
8879 มุมมอง

I have a model and I want to automatically fill one field of this model.

E.g. I have some test model and I want to automaticly genrate EAN13 for this after adding new product:

class product_test(osv.osv):
    _name = "product.test"
    _description = "Product test"
    _table = "product_test"
    _columns = {
        'name': fields.char('name', size=64, required=True, translate=True, select=True),
        'ean13': fields.char('EAN13', size=64, readonly=True),
    }
    _order = "name"
อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

must be overwrite method create

def create(self, cr, user, vals, context=None):           
        new_id = super(product_test, self).create(cr, user, vals, context)
        //your treatment
        return new_id

or use _defaults {}

  _columns = {  'ean13' : fields.char('ean13', size=64, ), }

  _defaults = {   'ean13': _get_ean13, }

  def _get_ref(self, cr, uid,context, *args):
        ean13 = // your treatment
        return ean13

Thanks.

อวตาร
ละทิ้ง
ผู้เขียน

Thank you! But when I install my addon with _defaults it writes the same EAN13 to all existing fileds.

in _defaults you make a call to a function _get_ean13 which treatment you want it can return a new ean13 for each new product and not same ean13.

Related Posts ตอบกลับ มุมมอง กิจกรรม
Change filename of binary field แก้ไขแล้ว
12
ธ.ค. 17
24714
2
มี.ค. 15
7292
1
มี.ค. 15
4226
0
ธ.ค. 24
9464
3
พ.ย. 24
29950