From 3b13d73b05735d99ecc5e2c74c49fccd03a8c15c Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Tue, 16 May 2017 17:12:13 +0200 Subject: [PATCH 1/3] Create employee & address_home if needed Create employee & address_home if needed --- odoo/local-src/specific_expense/README.rst | 6 +++ odoo/local-src/specific_expense/__init__.py | 5 +++ .../specific_expense/__manifest__.py | 17 +++++++++ .../data/res_partner_category.xml | 8 ++++ .../specific_expense/models/__init__.py | 5 +++ .../specific_expense/models/hr_employee.py | 38 +++++++++++++++++++ .../specific_expense/views/employee_views.xml | 17 +++++++++ 7 files changed, 96 insertions(+) create mode 100644 odoo/local-src/specific_expense/README.rst create mode 100644 odoo/local-src/specific_expense/__init__.py create mode 100644 odoo/local-src/specific_expense/__manifest__.py create mode 100644 odoo/local-src/specific_expense/data/res_partner_category.xml create mode 100644 odoo/local-src/specific_expense/models/__init__.py create mode 100644 odoo/local-src/specific_expense/models/hr_employee.py create mode 100644 odoo/local-src/specific_expense/views/employee_views.xml diff --git a/odoo/local-src/specific_expense/README.rst b/odoo/local-src/specific_expense/README.rst new file mode 100644 index 00000000000..4827b03c9d1 --- /dev/null +++ b/odoo/local-src/specific_expense/README.rst @@ -0,0 +1,6 @@ +============================ +Specific Expense for Roctool +============================ + +In odoo 10, the expense accounting uses the hr.employee address_home_id to find +some information. We want to facilitate this for roctool diff --git a/odoo/local-src/specific_expense/__init__.py b/odoo/local-src/specific_expense/__init__.py new file mode 100644 index 00000000000..955b6c58409 --- /dev/null +++ b/odoo/local-src/specific_expense/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/odoo/local-src/specific_expense/__manifest__.py b/odoo/local-src/specific_expense/__manifest__.py new file mode 100644 index 00000000000..5fd3ce68047 --- /dev/null +++ b/odoo/local-src/specific_expense/__manifest__.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "RocTool specific expense", + "version": "10.0.1.0.0", + "depends": ['hr', + ], + "author": "Camptocamp", + "website": "http://www.camptocamp.com", + "license": "AGPL-3", + "category": "Expense", + "data": ['data/res_partner_category.xml', + 'views/employee_views.xml', + ], + 'installable': True, +} diff --git a/odoo/local-src/specific_expense/data/res_partner_category.xml b/odoo/local-src/specific_expense/data/res_partner_category.xml new file mode 100644 index 00000000000..e4d84d2929a --- /dev/null +++ b/odoo/local-src/specific_expense/data/res_partner_category.xml @@ -0,0 +1,8 @@ + + + + + employee home + + + diff --git a/odoo/local-src/specific_expense/models/__init__.py b/odoo/local-src/specific_expense/models/__init__.py new file mode 100644 index 00000000000..ddd5ee3b148 --- /dev/null +++ b/odoo/local-src/specific_expense/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import hr_employee diff --git a/odoo/local-src/specific_expense/models/hr_employee.py b/odoo/local-src/specific_expense/models/hr_employee.py new file mode 100644 index 00000000000..c2f56e0156b --- /dev/null +++ b/odoo/local-src/specific_expense/models/hr_employee.py @@ -0,0 +1,38 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Camptocamp SA +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import models, fields, api + + +class Employee(models.Model): + _inherit = 'hr.employee' + + expense_refund_account_id = fields.Many2one( + 'account.account', + string='Expense Refund Account', + related='address_home_id.property_account_payable_id', + store=False, + readonly=False, + ) + + @api.model + def create(self, vals): + if vals['address_home_id']: + return super(Employee, self).create(vals) + country_id = None + if not vals['country_id']: + Company = self.env['res.company'] + country_id = Company.browse(vals['company_id']).country_id.id + Partner = self.env['res.partner'] + category_id = self.env.ref('specific_expense.employee_home').id + vals_address = { + 'name': vals.get('name'), + 'supplier': True, + 'customer': False, + 'country_id': country_id if country_id else vals.get('country_id'), + 'category_id': [(4, category_id)], + } + partner = Partner.create(vals_address) + vals['address_home_id'] = partner.id + return super(Employee, self).create(vals) diff --git a/odoo/local-src/specific_expense/views/employee_views.xml b/odoo/local-src/specific_expense/views/employee_views.xml new file mode 100644 index 00000000000..fa5892a485e --- /dev/null +++ b/odoo/local-src/specific_expense/views/employee_views.xml @@ -0,0 +1,17 @@ + + + + + hr.employee.form.expense + hr.employee + + + + + + + + + + + From 8f088c3546d0fbf2c1cae2226da916a9281b8433 Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Wed, 17 May 2017 09:53:58 +0200 Subject: [PATCH 2/3] Fix lint error from master --- odoo/local-src/specific_sale/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/odoo/local-src/specific_sale/models/sale_order.py b/odoo/local-src/specific_sale/models/sale_order.py index 0c4c9a448f4..1ca1e23e53e 100644 --- a/odoo/local-src/specific_sale/models/sale_order.py +++ b/odoo/local-src/specific_sale/models/sale_order.py @@ -153,6 +153,7 @@ def _compute_validation_required(self): if (cat.process_validation_required and not so.process_validation_id): so.process_validation_required = True + @api.multi @api.depends('amount_total', 'holding_currency_id') def _compute_holding_currency_amount(self): From 120afb69f3610f04774368779f6aee2b3fbc0a5c Mon Sep 17 00:00:00 2001 From: Denis Leemann Date: Wed, 17 May 2017 09:59:57 +0200 Subject: [PATCH 3/3] use vals.get in create employee --- HISTORY.rst | 1 + odoo/local-src/specific_expense/models/hr_employee.py | 8 ++++---- odoo/migration.yml | 1 + 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index d8743fe8b3b..ec402498d60 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -25,6 +25,7 @@ Latest (unreleased) * SO change validation button visibility/process given product_category * SO & crm.lead holding_amount_currency in tree view. Can be used as measure * Add module 'sale_company_currency' +* Add and install specific_expense **Bugfixes** diff --git a/odoo/local-src/specific_expense/models/hr_employee.py b/odoo/local-src/specific_expense/models/hr_employee.py index c2f56e0156b..442d00cae84 100644 --- a/odoo/local-src/specific_expense/models/hr_employee.py +++ b/odoo/local-src/specific_expense/models/hr_employee.py @@ -18,10 +18,10 @@ class Employee(models.Model): @api.model def create(self, vals): - if vals['address_home_id']: + if vals.get('address_home_id'): return super(Employee, self).create(vals) - country_id = None - if not vals['country_id']: + country_id = vals.get('country_id') + if not country_id: Company = self.env['res.company'] country_id = Company.browse(vals['company_id']).country_id.id Partner = self.env['res.partner'] @@ -30,7 +30,7 @@ def create(self, vals): 'name': vals.get('name'), 'supplier': True, 'customer': False, - 'country_id': country_id if country_id else vals.get('country_id'), + 'country_id': country_id, 'category_id': [(4, category_id)], } partner = Partner.create(vals_address) diff --git a/odoo/migration.yml b/odoo/migration.yml index 5ab3b2fb7c3..9fac34193da 100644 --- a/odoo/migration.yml +++ b/odoo/migration.yml @@ -184,3 +184,4 @@ migration: - sale_company_currency - specific_crm - specific_sale + - specific_expense