← Back to team overview

openerp-india team mailing list archive

[Bug 1071691] Re: Integrity constrain error when duplicating Company

 

In trunk, I tried adding a new copy method to res.company as follows:
def copy(self, cr, uid, id, default=None, context=None):
        """
        Add (copy) in the name when duplicate record
        """
        if not context:
            context = {}
        if not default:
            default = {}
        company = self.browse(cr, uid, id, context=context)
        default = default.copy()
        default['name'] = company.name + _(' (copy)')
        return super(multi_company_default, self).copy(cr, uid, id, default, context=context)

However, this gives me the following exception:

2012-11-28 14:22:03,092 3448 ERROR None openerp.sql_db: bad query: update "res_company" set "name"='Ayoki Purchasing' where id = 19
Traceback (most recent call last):
  File "G:\installs\openerp\openobject-server\openerp\sql_db.py", line 227, in execute
    res = self._obj.execute(query, params)
IntegrityError: duplicate key value violates unique constraint "res_company_name_uniq"
DETAIL:  Key (name)=(Ayoki Purchasing) already exists.

2012-11-28 14:22:03,094 3448 ERROR None openerp.netsvc: Constraint Error
The company name must be unique !
Traceback (most recent call last):
  File "G:\installs\openerp\openobject-server\openerp\netsvc.py", line 361, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "G:\installs\openerp\openobject-server\openerp\service\web_services.py", line 585, in dispatch
    res = fn(db, uid, *params)
  File "G:\installs\openerp\openobject-server\openerp\osv\osv.py", line 167, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "G:\installs\openerp\openobject-server\openerp\osv\osv.py", line 131, in wrapper
    tr(osv_pool._sql_error[key], 'sql_constraint') or inst[0])
  File "G:\installs\openerp\openobject-server\openerp\netsvc.py", line 67, in abort_response
    raise openerp.osv.osv.except_osv(description, details)
except_osv: ('Constraint Error', 'The company name must be unique !')

-- 
You received this bug notification because you are a member of OpenERP
Indian Team, which is subscribed to OpenERP Server.
https://bugs.launchpad.net/bugs/1071691

Title:
  Integrity constrain error when duplicating Company

Status in OpenERP Server:
  Confirmed

Bug description:
  In OpenERP v6.1, when duplicating a Company I get an integrity
  constrain error on the name field.

  This can be perfectly solved by overwriting the copy function of the
  object res.company and modifying the name over there, like is done
  with other objects.

To manage notifications about this bug go to:
https://bugs.launchpad.net/openobject-server/+bug/1071691/+subscriptions


References