Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

how to import partner-reference when module base_partner_sequence is installed?

By
René
on 3/12/13, 5:25 AM 1,613 views

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()


0

Andreas Brueckl

--Andreas Brueckl--
5056
| 7 8 7
Vienna, Austria
--Andreas Brueckl--
OpenERP Consulting and Development
Andreas Brueckl
On 3/12/13, 5:52 AM

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 = [..]).

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

Asked: 3/12/13, 5:25 AM
Seen: 1613 times
Last updated: 3/16/15, 8:10 AM