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

Hello I need to have an automatic sequence on the field "ref" when a partner is created. The module base_partner_sequence works well. But then when I import partners after installation of base_parter_sequence I am not able to import a csv-file with a value for "ref" because the value is always set automatically based on the sequence. Does someone has an idea how to import records with a value in csv when there is a sequence on a field? Maybe it is necessary to modify the code somewhere? Please see my code below.

Can yomeone help? René


class partner_sequence(osv.osv): _inherit = 'res.partner' _columns = { 'ref': fields.char('Code', size=64, readonly=False), }

def create(self, cr, uid, vals, context={}):
    vals['ref'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner')
    res = super(partner_sequence, self).create(cr, uid, vals, context)
    return res

_sql_constraints = [
('ref_unique', 'unique(ref)', 'reference per customer must be unique!'),
]

partner_sequence()


อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can try the following:

def create(self, cr, uid, vals, context={}):
    if not vals.get('ref', False):
        vals['ref'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner')
    res = super(partner_sequence, self).create(cr, uid, vals, context)
    return res

But normally in OpenERP sequences are assigned using defaults (_defaults = [..]).

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
3
มิ.ย. 20
3738
1
พ.ย. 18
9282
11
ก.พ. 17
63528
Import contacts through CSV แก้ไขแล้ว
2
มี.ค. 15
10703
4
พ.ย. 24
10938