Skip to content

Commit

Permalink
[MIG] product_multi_company: Migration to 9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrobaeza committed Dec 9, 2016
1 parent 381e937 commit 8b9e9eb
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 53 deletions.
12 changes: 4 additions & 8 deletions product_multi_company/README.rst
Expand Up @@ -26,27 +26,23 @@ be visible in all of them. The default value is the current one.

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/133/8.0
:target: https://runbot.odoo-community.org/runbot/133/9.0

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/multi-company/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed `feedback
<https://github.com/OCA/
multi-company/issues/new?body=module:%20
product_multi_company%0Aversion:%20
8.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
help us smashing it by providing a detailed and welcomed feedback.

Credits
=======

Contributors
------------

* Pedro M. Baeza <pedro.baeza@serviciosbaeza.com>
* Pedro M. Baeza <pedro.baeza@tecnativa.com>

Maintainer
----------
Expand All @@ -61,4 +57,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
To contribute to this module, please visit https://odoo-community.org.
10 changes: 4 additions & 6 deletions product_multi_company/__openerp__.py
@@ -1,20 +1,18 @@
# -*- coding: utf-8 -*-
# (c) 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# Copyright 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': "Product multi-company",
'summary': "Select individually the product visibility on each company",
'author': "Serv. Tecnol. Avanzados - Pedro M. Baeza,"
'author': "Tecnativa,"
"Odoo Community Association (OCA)",
'website': "http://serviciosbaeza.com",
'website': "https://www.tecnativa.com",
'category': 'Product Management',
'version': '8.0.1.0.0',
'version': '9.0.1.0.0',
'license': 'AGPL-3',
'depends': [
'product',
'purchase',
'sale_stock',
],
'data': [
'views/product_template_view.xml',
Expand Down
21 changes: 15 additions & 6 deletions product_multi_company/hooks.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (c) 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# Copyright 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, SUPERUSER_ID
Expand All @@ -12,9 +12,13 @@ def post_init_hook(cr, registry):
env = api.Environment(cr, SUPERUSER_ID, {})
# Change access rule
rule = env.ref('product.product_comp_rule')
rule.domain_force = ("['|', "
"('company_ids', 'in', user.company_id.id), "
"('company_id', '=', False)]")
rule.write({
'active': True,
'domain_force': (
"['|', ('company_ids', 'in', user.company_id.ids),"
" ('company_id', '=', False)]"
),
})
# Copy company values
template_model = env['product.template']
groups = template_model.read_group([], ['company_id'], ['company_id'])
Expand All @@ -31,5 +35,10 @@ def uninstall_hook(cr, registry):
with api.Environment.manage():
env = api.Environment(cr, SUPERUSER_ID, {})
rule = env.ref('product.product_comp_rule')
rule.domain_force = (" ['|',('company_id','=',user.company_id.id),"
"('company_id','=',False)]")
rule.write({
'active': True,
'domain_force': (
" ['|',('company_id','=',user.company_id.id),"
"('company_id','=',False)]"
),
})
2 changes: 1 addition & 1 deletion product_multi_company/i18n/es.po
Expand Up @@ -16,7 +16,7 @@ msgstr ""
"Plural-Forms: \n"

#. module: product_multi_company
#: field:product.template,company_ids:0
#: model:ir.model.fields,field_description:product_multi_company.field_product_template_company_ids
msgid "Companies"
msgstr "Compañías"

Expand Down
13 changes: 8 additions & 5 deletions product_multi_company/models/product_template.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
# (c) 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# Copyright 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp import api, fields, models
Expand All @@ -10,14 +10,17 @@ class ProductTemplate(models.Model):

def _default_company_ids(self):
company_model = self.env['res.company']
return [(6, 0,
[company_model._company_default_get('product.template')])]
return [
(6, 0, company_model._company_default_get('product.template').ids),
]

company_ids = fields.Many2many(
comodel_name='res.company', string="Companies",
default=_default_company_ids)
default=_default_company_ids,
)
company_id = fields.Many2one(
comodel_name='res.company', compute="_compute_company_id", store=True)
comodel_name='res.company', compute="_compute_company_id", store=True,
)

@api.multi
@api.depends('company_ids')
Expand Down
1 change: 0 additions & 1 deletion product_multi_company/tests/__init__.py
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# (c) 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from . import test_product_multi_company
14 changes: 8 additions & 6 deletions product_multi_company/tests/test_product_multi_company.py
@@ -1,11 +1,13 @@
# -*- coding: utf-8 -*-
# (c) 2015 Serv. Tecnol. Avanzados - Pedro M. Baeza
# Copyright 2015-2016 Pedro M. Baeza <pedro.baeza@tecnativa.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from openerp.tests import common
from openerp.osv.osv import except_orm as AccessError
from openerp.exceptions import AccessError


@common.at_install(False)
@common.post_install(True)
class TestProductMultiCompany(common.TransactionCase):
def setUp(self):
super(TestProductMultiCompany, self).setUp()
Expand Down Expand Up @@ -42,9 +44,9 @@ def setUp(self):

def test_create_product(self):
product = self.env['product.product'].create({'name': 'Test'})
company_id = (
self.env['res.company']._company_default_get('product.template'))
self.assertTrue(company_id in product.company_ids.ids)
company = self.env['res.company']._company_default_get(
'product.template')
self.assertTrue(company in product.company_ids)

def test_company_none(self):
self.assertFalse(self.product_company_none.company_id)
Expand All @@ -71,7 +73,7 @@ def test_company_2(self):
self.product_company_1.sudo(self.user_company_2).name = "Test"

def test_uninstall(self):
from openerp.addons.product_multi_company.hooks import uninstall_hook
from ..hooks import uninstall_hook
uninstall_hook(self.env.cr, None)
rule = self.env.ref('product.product_comp_rule')
domain = (" ['|',('company_id','=',user.company_id.id),"
Expand Down
38 changes: 18 additions & 20 deletions product_multi_company/views/product_template_view.xml
@@ -1,24 +1,22 @@
<?xml version="1.0"?>
<openerp>
<data>
<odoo>

<record model="ir.ui.view" id="product_template_form_view">
<field name="name">Product template form view (with multi-company)</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="company_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
<field name="company_id" position="after">
<field name="company_ids"
groups="base.group_multi_company"
widget="many2many_tags"
options="{'no_create': True}"
/>
</field>
<record model="ir.ui.view" id="product_template_form_view">
<field name="name">Product template form view (with multi-company)</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view" />
<field name="arch" type="xml">
<field name="company_id" position="attributes">
<attribute name="invisible">1</attribute>
</field>
</record>
<field name="company_id" position="after">
<field name="company_ids"
groups="base.group_multi_company"
widget="many2many_tags"
options="{'no_create': True}"
/>
</field>
</field>
</record>

</data>
</openerp>
</odoo>

0 comments on commit 8b9e9eb

Please sign in to comment.