From c4f21c19612be2e0fab732aa292e08597aff4817 Mon Sep 17 00:00:00 2001 From: Thomas Rehn Date: Fri, 15 Nov 2013 11:09:34 +0100 Subject: [PATCH] change the scope of sequences to customers and suppliers --- base_partner_sequence/__init__.py | 2 +- base_partner_sequence/__openerp__.py | 4 +++- base_partner_sequence/partner.py | 12 ++++++------ 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/base_partner_sequence/__init__.py b/base_partner_sequence/__init__.py index 40b7591a3..a2cd05adc 100644 --- a/base_partner_sequence/__init__.py +++ b/base_partner_sequence/__init__.py @@ -18,5 +18,5 @@ # along with this program. If not, see . # ############################################################################## -import partner +from . import partner # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/base_partner_sequence/__openerp__.py b/base_partner_sequence/__openerp__.py index e985cd9ad..6fee88060 100644 --- a/base_partner_sequence/__openerp__.py +++ b/base_partner_sequence/__openerp__.py @@ -31,7 +31,9 @@ "description": """ This module adds the possibility to define a sequence for the partner code. This code is then set as default when you - create a new partner (not a contact), using the defined sequence. + create a new customer or supplier, using the defined sequence. + No codes are assigned for contacts such as shipping and + invoice addresses. This module is a migration of the original base_partner_sequence addon to OpenERP version 7.0. """, diff --git a/base_partner_sequence/partner.py b/base_partner_sequence/partner.py index 2123f3a7e..066f491cb 100644 --- a/base_partner_sequence/partner.py +++ b/base_partner_sequence/partner.py @@ -31,13 +31,13 @@ class ResPartner(orm.Model): def create(self, cr, uid, vals, context=None): context = context or {} - if not vals.get('ref') and self._needsRef(cr, uid, None, vals, context): + if not vals.get('ref') and self._needsRef(cr, uid, vals=vals, context=context): vals['ref'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner') return super(ResPartner, self).create(cr, uid, vals, context) def copy(self, cr, uid, id, default=None, context=None): default = default or {} - if not default.get('ref') and self._needsRef(cr, uid, id, None, context): + if not default.get('ref') and self._needsRef(cr, uid, id=id, context=context): default['ref'] = self.pool.get('ir.sequence').get(cr, uid, 'res.partner', context=context) return super(ResPartner, self).copy(cr, uid, id, default, context=context) @@ -53,11 +53,11 @@ class ResPartner(orm.Model): """ if not vals and not id: raise Exception('Either field values or an id must be provided.') - # only assign a 'ref' if it is not a child object - # (such as a shipping/invoice address) + # only assign a 'ref' if it is a customer or supplier and + # if it not a child object (such as a shipping/invoice address) if id: - vals = self.read(cr, uid, id, ['parent_id'], context=context) - return not vals.get('parent_id') + vals = self.read(cr, uid, id, ['parent_id','customer','supplier'], context=context) + return not vals.get('parent_id') and (vals.get('customer') or vals.get('supplier')) _columns = { 'ref': fields.char('Reference', size=64, readonly=True),