From 98d977a9459c9704939967aea52f1f3620d0803e Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Thu, 4 May 2017 17:55:36 +0200 Subject: [PATCH 1/2] add specific inter company this module allows to fill in required values in the sale.order from the purchase.order --- .../specific_inter_company/README.rst | 9 ++++ .../specific_inter_company/__init__.py | 1 + .../specific_inter_company/__manifest__.py | 19 +++++++ .../specific_inter_company/models/__init__.py | 1 + .../models/purchase_order.py | 53 +++++++++++++++++++ .../specific_sale/models/__init__.py | 1 + .../models/account_analytic_account.py | 17 ++++++ .../specific_sale/models/sale_order.py | 14 +++-- odoo/migration.yml | 5 ++ 9 files changed, 116 insertions(+), 4 deletions(-) create mode 100644 odoo/local-src/specific_inter_company/README.rst create mode 100644 odoo/local-src/specific_inter_company/__init__.py create mode 100644 odoo/local-src/specific_inter_company/__manifest__.py create mode 100644 odoo/local-src/specific_inter_company/models/__init__.py create mode 100644 odoo/local-src/specific_inter_company/models/purchase_order.py create mode 100644 odoo/local-src/specific_sale/models/account_analytic_account.py diff --git a/odoo/local-src/specific_inter_company/README.rst b/odoo/local-src/specific_inter_company/README.rst new file mode 100644 index 00000000000..63303999e22 --- /dev/null +++ b/odoo/local-src/specific_inter_company/README.rst @@ -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. diff --git a/odoo/local-src/specific_inter_company/__init__.py b/odoo/local-src/specific_inter_company/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/odoo/local-src/specific_inter_company/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/odoo/local-src/specific_inter_company/__manifest__.py b/odoo/local-src/specific_inter_company/__manifest__.py new file mode 100644 index 00000000000..73135604ed0 --- /dev/null +++ b/odoo/local-src/specific_inter_company/__manifest__.py @@ -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, +} diff --git a/odoo/local-src/specific_inter_company/models/__init__.py b/odoo/local-src/specific_inter_company/models/__init__.py new file mode 100644 index 00000000000..9f03530643d --- /dev/null +++ b/odoo/local-src/specific_inter_company/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_order diff --git a/odoo/local-src/specific_inter_company/models/purchase_order.py b/odoo/local-src/specific_inter_company/models/purchase_order.py new file mode 100644 index 00000000000..ff035121473 --- /dev/null +++ b/odoo/local-src/specific_inter_company/models/purchase_order.py @@ -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 diff --git a/odoo/local-src/specific_sale/models/__init__.py b/odoo/local-src/specific_sale/models/__init__.py index 18b25191dae..39a35f56a1e 100644 --- a/odoo/local-src/specific_sale/models/__init__.py +++ b/odoo/local-src/specific_sale/models/__init__.py @@ -9,3 +9,4 @@ from . import mrp_bom from . import project_task from . import procurement_order +from . import account_analytic_account diff --git a/odoo/local-src/specific_sale/models/account_analytic_account.py b/odoo/local-src/specific_sale/models/account_analytic_account.py new file mode 100644 index 00000000000..165c44962eb --- /dev/null +++ b/odoo/local-src/specific_sale/models/account_analytic_account.py @@ -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') diff --git a/odoo/local-src/specific_sale/models/sale_order.py b/odoo/local-src/specific_sale/models/sale_order.py index 48b8b2d31ad..01d25d2fbad 100644 --- a/odoo/local-src/specific_sale/models/sale_order.py +++ b/odoo/local-src/specific_sale/models/sale_order.py @@ -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', @@ -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: @@ -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, @@ -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): diff --git a/odoo/migration.yml b/odoo/migration.yml index eadde0672ff..d7f67e66acb 100644 --- a/odoo/migration.yml +++ b/odoo/migration.yml @@ -170,3 +170,8 @@ migration: upgrade: - specific_crm - website_contract + - version: 10.0.14 + addons: + upgrade: + - specific_sale + - specific_inter_company From 9d9588df1cff05fa84b388cb6028f2647ab4ce5c Mon Sep 17 00:00:00 2001 From: Alexandre Fayolle Date: Mon, 8 May 2017 16:49:55 +0200 Subject: [PATCH 2/2] update migration script --- odoo/migration.yml | 3 +++ odoo/songs/upgrade/10_0_14/__init__.py | 0 odoo/songs/upgrade/10_0_14/intercompany.py | 28 ++++++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 odoo/songs/upgrade/10_0_14/__init__.py create mode 100644 odoo/songs/upgrade/10_0_14/intercompany.py diff --git a/odoo/migration.yml b/odoo/migration.yml index d7f67e66acb..b3bd1b2f117 100644 --- a/odoo/migration.yml +++ b/odoo/migration.yml @@ -175,3 +175,6 @@ migration: upgrade: - specific_sale - specific_inter_company + operations: + post: + - anthem songs.upgrade.10_0_14.intercompany::main diff --git a/odoo/songs/upgrade/10_0_14/__init__.py b/odoo/songs/upgrade/10_0_14/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/odoo/songs/upgrade/10_0_14/intercompany.py b/odoo/songs/upgrade/10_0_14/intercompany.py new file mode 100644 index 00000000000..d6192e0fc57 --- /dev/null +++ b/odoo/songs/upgrade/10_0_14/intercompany.py @@ -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)