Browse Source

change the scope of sequences to customers and suppliers

pull/2/head
Thomas Rehn 11 years ago
parent
commit
c4f21c1961
  1. 2
      base_partner_sequence/__init__.py
  2. 4
      base_partner_sequence/__openerp__.py
  3. 12
      base_partner_sequence/partner.py

2
base_partner_sequence/__init__.py

@ -18,5 +18,5 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import partner
from . import partner
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

4
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.
""",

12
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),

Loading…
Cancel
Save