summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan de Pryck <nde@odoo.com>2019-07-23 09:12:11 +0000
committerNathan de Pryck <nde@odoo.com>2019-07-31 13:24:42 +0000
commit4f33ae16154b9c5203c231f8dbe9425696e3291d (patch)
tree634ea409f2750ec5ae23a346f67c8cf22e705794
parentb499c3308cd036e464578045996b63cfa877aa92 (diff)
[IMP] iap: multi-company for iap account
The "company_id" fields for the iap account has been changed by the "company_ids" fields to allow the use of an iap account with multiple company. closes odoo/odoo#35093 Signed-off-by: Rémi Rahir (rar) <rar@odoo.com>
-rw-r--r--addons/iap/models/iap.py17
-rw-r--r--addons/iap/security/ir_rule.xml2
-rw-r--r--addons/iap/views/iap_views.xml4
3 files changed, 17 insertions, 6 deletions
diff --git a/addons/iap/models/iap.py b/addons/iap/models/iap.py
index 7dd9b6c206b..1e6990f10b5 100644
--- a/addons/iap/models/iap.py
+++ b/addons/iap/models/iap.py
@@ -158,17 +158,28 @@ class IapAccount(models.Model):
service_name = fields.Char()
account_token = fields.Char(default=lambda s: uuid.uuid4().hex)
- company_id = fields.Many2one('res.company', default=lambda self: self.env.company)
+ company_ids = fields.Many2many('res.company')
@api.model
def get(self, service_name, force_create=True):
- account = self.search([('service_name', '=', service_name), ('company_id', 'in', [self.env.company.id, False])], limit=1, order='company_id desc, id desc')
- if not account and force_create:
+ accounts = self.search([
+ ('service_name', '=', service_name),
+ '|',
+ ('company_ids', 'in', self.env.context['allowed_company_ids']),
+ ('company_ids','=',False)],
+ order='id desc')
+ if not accounts and force_create:
account = self.create({'service_name': service_name})
# Since the account did not exist yet, we will encounter a NoCreditError,
# which is going to rollback the database and undo the account creation,
# preventing the process to continue any further.
self.env.cr.commit()
+ else:
+ accounts_with_company = accounts.filtered(lambda acc: acc.company_ids)
+ if accounts_with_company:
+ account = accounts_with_company[0]
+ else:
+ account = accounts[0]
return account
@api.model
diff --git a/addons/iap/security/ir_rule.xml b/addons/iap/security/ir_rule.xml
index 05e8dcd4b72..a81e1542854 100644
--- a/addons/iap/security/ir_rule.xml
+++ b/addons/iap/security/ir_rule.xml
@@ -5,7 +5,7 @@
<field name="model_id" ref="model_iap_account"/>
<field name="groups" eval="[(4, ref('base.group_user'))]"/>
<!-- partners can CUD services linked to themselves -->
- <field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
+ <field name="domain_force">['|', ('company_ids', '=', False), ('company_ids', 'in', company_ids)]</field>
</record>
</data>
</odoo> \ No newline at end of file
diff --git a/addons/iap/views/iap_views.xml b/addons/iap/views/iap_views.xml
index f2f7825f358..e6da74da002 100644
--- a/addons/iap/views/iap_views.xml
+++ b/addons/iap/views/iap_views.xml
@@ -10,7 +10,7 @@
<sheet>
<group name="account" string="Account Information">
<field name="service_name"/>
- <field name="company_id"/>
+ <field name="company_ids" widget="many2many_tags" domain="[('id', 'in', allowed_company_ids)]"/>
<field name="account_token"/>
</group>
</sheet>
@@ -23,7 +23,7 @@
<field name="arch" type="xml">
<tree string="IAP Accounts">
<field name="service_name"/>
- <field name="company_id"/>
+ <field name="company_ids" widget="many2many_tags"/>
<field name="account_token" readonly="1"/>
</tree>
</field>