diff --git a/contract_forecast/__manifest__.py b/contract_forecast/__manifest__.py
index afa38589..d32bb87b 100644
--- a/contract_forecast/__manifest__.py
+++ b/contract_forecast/__manifest__.py
@@ -5,7 +5,7 @@
"name": "Contract Forecast",
"description": """
Contract forecast""",
- "version": "12.0.1.0.0",
+ "version": "12.0.1.0.1",
"license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/contract",
diff --git a/contract_forecast/migrations/12.0.1.0.1/post-migration.py b/contract_forecast/migrations/12.0.1.0.1/post-migration.py
new file mode 100644
index 00000000..deb6df76
--- /dev/null
+++ b/contract_forecast/migrations/12.0.1.0.1/post-migration.py
@@ -0,0 +1,18 @@
+# Copyright 2019 ACSONE SA/NV
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
+
+import logging
+
+_logger = logging.getLogger(__name__)
+
+
+def migrate(cr, version):
+ """Set company_id for all forecasts"""
+ _logger.info("Set company_id for all forecasts")
+ cr.execute("""
+ UPDATE contract_line_forecast_period AS forecast
+ SET company_id=contract.company_id
+ FROM account_analytic_account AS contract
+ WHERE forecast.contract_id=contract.id
+ AND forecast.contract_id IS NOT NULL
+ """)
diff --git a/contract_forecast/models/contract_line.py b/contract_forecast/models/contract_line.py
index e6a8a2de..72a175d0 100644
--- a/contract_forecast/models/contract_line.py
+++ b/contract_forecast/models/contract_line.py
@@ -27,6 +27,7 @@ class AccountAnalyticInvoiceLine(models.Model):
return {
"name": self._insert_markers(period_date_start, period_date_end),
"contract_id": self.contract_id.id,
+ "company_id": self.contract_id.company_id.id,
"contract_line_id": self.id,
"product_id": self.product_id.id,
"date_start": period_date_start,
diff --git a/contract_forecast/models/contract_line_forecast_period.py b/contract_forecast/models/contract_line_forecast_period.py
index eb34f461..921cd6af 100644
--- a/contract_forecast/models/contract_line_forecast_period.py
+++ b/contract_forecast/models/contract_line_forecast_period.py
@@ -61,6 +61,7 @@ class ContractLineForecastPeriod(models.Model):
help='Discount that is applied in generated invoices.'
' It should be less or equal to 100',
)
+ company_id = fields.Many2one(comodel_name="res.company", string="Company")
@api.multi
@api.depends('quantity', 'price_unit', 'discount')
diff --git a/contract_forecast/security/contract_line_forecast_period.xml b/contract_forecast/security/contract_line_forecast_period.xml
index deb68801..f58b3042 100644
--- a/contract_forecast/security/contract_line_forecast_period.xml
+++ b/contract_forecast/security/contract_line_forecast_period.xml
@@ -14,4 +14,12 @@
+
+ Forecast multi company rule
+
+
+ ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]
+
+
+
diff --git a/contract_forecast/views/contract_line_forecast_period.xml b/contract_forecast/views/contract_line_forecast_period.xml
index 381cc47c..2f155916 100644
--- a/contract_forecast/views/contract_line_forecast_period.xml
+++ b/contract_forecast/views/contract_line_forecast_period.xml
@@ -13,6 +13,7 @@
+
@@ -37,6 +38,7 @@
+