parent
d939126735
commit
59422550d8
11
party.py
11
party.py
|
@ -210,6 +210,7 @@ class Party(metaclass=PoolMeta):
|
||||||
def set_companies_field(cls, parties, name, value):
|
def set_companies_field(cls, parties, name, value):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
PartyCompany = pool.get('party.company.rel')
|
PartyCompany = pool.get('party.company.rel')
|
||||||
|
Data = pool.get('ir.model.data')
|
||||||
|
|
||||||
party_company = PartyCompany.__table__()
|
party_company = PartyCompany.__table__()
|
||||||
cursor = Transaction().connection.cursor()
|
cursor = Transaction().connection.cursor()
|
||||||
|
@ -253,7 +254,15 @@ class Party(metaclass=PoolMeta):
|
||||||
PartyCompany.create(to_create)
|
PartyCompany.create(to_create)
|
||||||
|
|
||||||
if to_remove:
|
if to_remove:
|
||||||
raise UserError(gettext('party_company.can_not_remove_companies'))
|
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):
|
class PartyCompanyMixin(object):
|
||||||
|
|
|
@ -83,3 +83,16 @@ Create new parties::
|
||||||
True
|
True
|
||||||
>>> party5.companies[0] == company2_user.company
|
>>> party5.companies[0] == company2_user.company
|
||||||
True
|
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