Skip to content

Commit

Permalink
[FIX] fix init hooks as company_id is not stored anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
Cédric Pigeon committed May 11, 2017
1 parent 2f1d0d5 commit d670f30
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
1 change: 1 addition & 0 deletions base_multi_company/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Contributors
* Dave Lasley <[email protected]>
* Pedro M. Baeza <[email protected]>
* Laurent Mignon <[email protected]>
* Cédric Pigeon <[email protected]>

Maintainer
----------
Expand Down
18 changes: 10 additions & 8 deletions base_multi_company/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,16 @@ def post_init_hook(cr, rule_ref, model_name):
})
# Copy company values
model = env[model_name]
groups = model.read_group([], ['company_id'], ['company_id'])
for group in groups:
if not group['company_id']:
continue
records = model.search(group['__domain'])
records.write({
'company_ids': [(6, 0, [group['company_id'][0]])],
})

table_name = model._fields['company_ids'].relation
column1 = model._fields['company_ids'].column1
column2 = model._fields['company_ids'].column2
SQL = """
INSERT INTO %s
(%s, %s)
SELECT id, company_id FROM %s
""" % (table_name, column1, column2, model._table)
env.cr.execute(SQL)


def uninstall_hook(cr, rule_ref):
Expand Down

0 comments on commit d670f30

Please sign in to comment.