Browse Source

[ADD] - Add multi-company to forecasts

pull/283/head
sbejaoui 5 years ago
parent
commit
28d0d8d5fb
  1. 2
      contract_forecast/__manifest__.py
  2. 18
      contract_forecast/migrations/12.0.1.0.1/post-migration.py
  3. 1
      contract_forecast/models/contract_line.py
  4. 1
      contract_forecast/models/contract_line_forecast_period.py
  5. 8
      contract_forecast/security/contract_line_forecast_period.xml
  6. 2
      contract_forecast/views/contract_line_forecast_period.xml

2
contract_forecast/__manifest__.py

@ -5,7 +5,7 @@
"name": "Contract Forecast", "name": "Contract Forecast",
"description": """ "description": """
Contract forecast""", Contract forecast""",
"version": "12.0.1.0.0",
"version": "12.0.1.0.1",
"license": "AGPL-3", "license": "AGPL-3",
"author": "ACSONE SA/NV," "Odoo Community Association (OCA)", "author": "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "https://github.com/OCA/contract", "website": "https://github.com/OCA/contract",

18
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
""")

1
contract_forecast/models/contract_line.py

@ -27,6 +27,7 @@ class AccountAnalyticInvoiceLine(models.Model):
return { return {
"name": self._insert_markers(period_date_start, period_date_end), "name": self._insert_markers(period_date_start, period_date_end),
"contract_id": self.contract_id.id, "contract_id": self.contract_id.id,
"company_id": self.contract_id.company_id.id,
"contract_line_id": self.id, "contract_line_id": self.id,
"product_id": self.product_id.id, "product_id": self.product_id.id,
"date_start": period_date_start, "date_start": period_date_start,

1
contract_forecast/models/contract_line_forecast_period.py

@ -61,6 +61,7 @@ class ContractLineForecastPeriod(models.Model):
help='Discount that is applied in generated invoices.' help='Discount that is applied in generated invoices.'
' It should be less or equal to 100', ' It should be less or equal to 100',
) )
company_id = fields.Many2one(comodel_name="res.company", string="Company")
@api.multi @api.multi
@api.depends('quantity', 'price_unit', 'discount') @api.depends('quantity', 'price_unit', 'discount')

8
contract_forecast/security/contract_line_forecast_period.xml

@ -14,4 +14,12 @@
<field name="perm_unlink" eval="1"/> <field name="perm_unlink" eval="1"/>
</record> </record>
<record id="contract_line_forecast_period_comp_rule" model="ir.rule">
<field name="name">Forecast multi company rule</field>
<field name="model_id" ref="model_contract_line_forecast_period"/>
<field name="domain_force">
['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]
</field>
</record>
</odoo> </odoo>

2
contract_forecast/views/contract_line_forecast_period.xml

@ -13,6 +13,7 @@
<field name="arch" type="xml"> <field name="arch" type="xml">
<search> <search>
<field name="contract_id" string="Contract"/> <field name="contract_id" string="Contract"/>
<field name="company_id" groups="base.group_multi_company"/>
<group expand="0" string="Group By"> <group expand="0" string="Group By">
<filter string="Date Start" name="groupby_date_start" <filter string="Date Start" name="groupby_date_start"
context="{'group_by':'date_start'}"/> context="{'group_by':'date_start'}"/>
@ -37,6 +38,7 @@
<field name="date_start"/> <field name="date_start"/>
<field name="date_end"/> <field name="date_end"/>
<field name="date_invoice"/> <field name="date_invoice"/>
<field name="company_id" groups="base.group_multi_company"/>
</tree> </tree>
</field> </field>
</record> </record>

Loading…
Cancel
Save