parent
d939126735
commit
59422550d8
9
party.py
9
party.py
|
@ -210,6 +210,7 @@ class Party(metaclass=PoolMeta):
|
|||
def set_companies_field(cls, parties, name, value):
|
||||
pool = Pool()
|
||||
PartyCompany = pool.get('party.company.rel')
|
||||
Data = pool.get('ir.model.data')
|
||||
|
||||
party_company = PartyCompany.__table__()
|
||||
cursor = Transaction().connection.cursor()
|
||||
|
@ -253,7 +254,15 @@ class Party(metaclass=PoolMeta):
|
|||
PartyCompany.create(to_create)
|
||||
|
||||
if to_remove:
|
||||
groups = Transaction().context.get('groups', [])
|
||||
group_admin = Data.get_id('res', 'group_admin')
|
||||
if group_admin not in groups:
|
||||
raise UserError(gettext('party_company.can_not_remove_companies'))
|
||||
to_delete = PartyCompany.search([
|
||||
('party', 'in', parties),
|
||||
('company', 'in', to_remove),
|
||||
])
|
||||
PartyCompany.delete(to_delete)
|
||||
|
||||
|
||||
class PartyCompanyMixin(object):
|
||||
|
|
|
@ -83,3 +83,16 @@ Create new parties::
|
|||
True
|
||||
>>> party5.companies[0] == company2_user.company
|
||||
True
|
||||
|
||||
Delete companies in parties::
|
||||
|
||||
>>> party6 = Party()
|
||||
>>> len(party6.companies) == 1
|
||||
True
|
||||
>>> company, = party6.companies
|
||||
>>> party6.companies.remove(company)
|
||||
>>> len(party6.companies) == 0
|
||||
True
|
||||
>>> party6.save()
|
||||
>>> len(party6.companies) == 0
|
||||
True
|
||||
|
|
Loading…
Reference in New Issue