[FIX] base: duplicate company => duplicate partner

The name of a company is uniq. The name of a company comes from a
partner and is required.

Thus duplicating a company didn't work.

With this change, if no partner is overriding the copy, the current
partner is duplicated and associated to the new duplicated company.

opw-746106
closes #17532
This commit is contained in:
Nicolas Lempereur 2017-06-09 16:43:13 +02:00
parent c50745f1a1
commit ed61da6793
1 changed files with 14 additions and 1 deletions

View File

@ -22,7 +22,7 @@
import os
import re
import openerp
from openerp import SUPERUSER_ID, tools
from openerp import SUPERUSER_ID, tools, api
from openerp.osv import fields, osv
from openerp.tools.translate import _
from openerp.tools.safe_eval import safe_eval as eval
@ -154,6 +154,19 @@ class res_company(osv.osv):
('name_uniq', 'unique (name)', 'The company name must be unique !')
]
@api.multi
def copy(self, default=None):
"""
Duplicating a company without specifying a partner duplicate the partner
"""
self.ensure_one()
default = dict(default or {})
if not default.get('name') and not default.get('partner_id'):
copy_partner = self.partner_id.copy()
default['partner_id'] = copy_partner.id
default['name'] = copy_partner.name
return super(res_company, self).copy(default)
def onchange_footer(self, cr, uid, ids, custom_footer, phone, fax, email, website, vat, company_registry, bank_ids, context=None):
if custom_footer:
return {}