Skip to content

Commit

Permalink
Merge pull request OCA#70 from gurneyalex/fix_interco
Browse files Browse the repository at this point in the history
add specific inter company
  • Loading branch information
gurneyalex authored May 9, 2017
2 parents 9ae7e58 + 9d9588d commit cea7b6f
Show file tree
Hide file tree
Showing 11 changed files with 147 additions and 4 deletions.
9 changes: 9 additions & 0 deletions odoo/local-src/specific_inter_company/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
----------------------
specific inter company
----------------------


This module handles the specifics of intercompany rules for Roctool:

* the sale orders have some additional required fields => we provide some
values from them when a SO is created from a PO.
1 change: 1 addition & 0 deletions odoo/local-src/specific_inter_company/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions odoo/local-src/specific_inter_company/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Author: Alexandre Fayolle
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "RocTool specific inter company rules",
"version": "10.0.1.0.0",
"depends": [
"inter_company_rules",
"specific_sale",
],
"author": "Camptocamp,Odoo Community Association (OCA)",
"website": "http://www.camptocamp.com",
"license": "GPL-3 or any later version",
"category": "Sale",
"data": [
],
'installable': True,
}
1 change: 1 addition & 0 deletions odoo/local-src/specific_inter_company/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import purchase_order
53 changes: 53 additions & 0 deletions odoo/local-src/specific_inter_company/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
# Author: Damien Crier
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
import base64

from odoo import models, api, _
from odoo.exceptions import UserError


class PurchaseOrder(models.Model):
_inherit = 'purchase.order'

@api.one
def _prepare_sale_order_data(self, name, partner, company,
direct_delivery_address):
values = super(PurchaseOrder, self)._prepare_sale_order_data(
name, partner, company, direct_delivery_address
)[0]
analytic = self.mapped('order_line.account_analytic_id')
if len(analytic) != 1:
raise UserError(_('All the lines of the purchase must '
'be on the same analytic account'))
if not analytic.project_zone_id:
raise UserError(
_('The analytic account %s '
'does not have a Project Zone') % analytic.name
)
if not analytic.project_process_id:
raise UserError(
_('The analytic account %s '
'does not have a Project Process') % analytic.name
)
if not analytic.project_market_id:
raise UserError(
_('The analytic account %s '
'does not have a Project Market') % analytic.name
)
values.update({
'project_zone_id': analytic.project_zone_id.id,
'project_process_id': analytic.project_process_id.id,
'project_market_id': analytic.project_market_id.id,
'sales_condition': base64.encodestring(
'Intercompany sales conditions.'
),
'sales_condition_filename': 'intercompany.txt',
'engineering_validation_id': 1,
'process_validation_id': 1,
'system_validation_id': 1,
'force_project_name': analytic.name,
}
)
return values
1 change: 1 addition & 0 deletions odoo/local-src/specific_sale/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
from . import mrp_bom
from . import project_task
from . import procurement_order
from . import account_analytic_account
17 changes: 17 additions & 0 deletions odoo/local-src/specific_sale/models/account_analytic_account.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Author: Alexandre Fayolle
# Copyright 2017 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models, fields


class AccountAnalyticAccount(models.Model):
_inherit = 'account.analytic.account'

project_zone_id = fields.Many2one(comodel_name='project.zone',
string='Project Zone')
project_process_id = fields.Many2one(comodel_name='project.process',
string='Project Process')
project_market_id = fields.Many2one(comodel_name='project.market',
string='Project Market')
14 changes: 10 additions & 4 deletions odoo/local-src/specific_sale/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SaleOrder(models.Model):
project_market_id = fields.Many2one(comodel_name='project.market',
string='Project Market',
required=True)

forced_project_name = fields.Char()
engineering_validation_id = fields.Many2one(
'res.users',
string='Engineering Validation',
Expand Down Expand Up @@ -69,7 +69,7 @@ def _setup_fields(self, partial):
if not exists:
selection.insert(position + 1, ('final_quote', _('Final Quote')))

def _generate_acc_name(self, use_existing_one=None):
def _generate_acc_name(self):
""" Generate analytic account name
According to the following structure:
Expand All @@ -80,8 +80,8 @@ def _generate_acc_name(self, use_existing_one=None):
YY: Code of the project process
ZZ: Code of the project market
"""
if use_existing_one:
return use_existing_one
if self.forced_project_name:
return self.forced_project_name

seq = self.env['ir.sequence'].next_by_code('project')
return ''.join([seq,
Expand All @@ -97,6 +97,12 @@ def _create_analytic_account(self, prefix=None):
for order in self:
name = order._generate_acc_name()
order.project_id.name = name
# propagage the information on the project
order.project_id.write(
{'project_zone_id': order.project_zone_id.id,
'project_process_id': order.project_process_id.id,
'project_market_id': order.project_market_id.id}
)

@api.onchange('opportunity_id')
def onchange_opportunity_id(self):
Expand Down
8 changes: 8 additions & 0 deletions odoo/migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,11 @@ migration:
upgrade:
- specific_crm
- website_contract
- version: 10.0.14
addons:
upgrade:
- specific_sale
- specific_inter_company
operations:
post:
- anthem songs.upgrade.10_0_14.intercompany::main
Empty file.
28 changes: 28 additions & 0 deletions odoo/songs/upgrade/10_0_14/intercompany.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Copyright 2016 Camptocamp SA
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)

import anthem


@anthem.log
def set_intercompany_rules(ctx):
warehouse = ctx.env['stock.warehouse']
holding = ctx.env.ref('__setup__.roctool_holding')
for company in ctx.env['res.company'].search([('id', '!=', holding.id)]):
warehouse_id = warehouse.search([('company_id', '=', company.id)])[0]
vals = {
'so_from_po': (company.name == 'RocTool SA'),
'po_from_so': False,
'warehouse_id': warehouse_id.id,
'ref': 'r%s' % company.country_id.code.lower(),
'customer': 1,
'supplier': (company.name == 'RocTool SA'),
}
company.write(vals)


@anthem.log
def main(ctx):
""" Main: creating intercompany rules """
set_intercompany_rules(ctx)

0 comments on commit cea7b6f

Please sign in to comment.