From 8438286478e111b231e7c680e8262310a4c8bf43 Mon Sep 17 00:00:00 2001 From: Nidhi Patel Date: Fri, 14 Feb 2020 13:23:48 +0000 Subject: [PATCH] [IMP] account,hr(_expense): Employee private address should be 'private' instead of 'contact' Purpose of this task is,lots of business flows can be crashed if the field Private Address(address_home_id) is a private address instead of a regular contact. so in this commit,we change the demo data for employee and set the private type address on employee for private address and also fix the flows on which errors could occur. Currently billing administrator does not have right for private address and while creating payment from expense it was going to set the customer from the employee's private address on payment so give the private address right to the billing adminnistrator. Also chaned admin/demo user's private address as 'private' instead of regular contact. and on hr_expense use the Sudo while accessing the home address this method is used from payslip too. TaskID:2170016 closes odoo/odoo#46628 Closes: #46628 Related: odoo/enterprise#8924 Signed-off-by: Yannick Tivisse (yti) --- addons/account/security/account_security.xml | 2 +- addons/hr/data/hr_data.xml | 10 +++++++- addons/hr/data/hr_demo.xml | 24 ++++++++++++++++++++ addons/hr_expense/data/hr_expense_demo.xml | 8 ------- addons/hr_expense/models/hr_expense.py | 8 +++---- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/addons/account/security/account_security.xml b/addons/account/security/account_security.xml index 8a55998f811..fd9b95655b7 100644 --- a/addons/account/security/account_security.xml +++ b/addons/account/security/account_security.xml @@ -40,7 +40,7 @@ Billing Administrator - + diff --git a/addons/hr/data/hr_data.xml b/addons/hr/data/hr_data.xml index 2e7fca012b7..da3e2ffa34a 100644 --- a/addons/hr/data/hr_data.xml +++ b/addons/hr/data/hr_data.xml @@ -10,11 +10,19 @@ Sales + + Administrator + + admin@example.com + + private + + - + diff --git a/addons/hr/data/hr_demo.xml b/addons/hr/data/hr_demo.xml index 4c2270834f6..0860970a3f6 100644 --- a/addons/hr/data/hr_demo.xml +++ b/addons/hr/data/hr_demo.xml @@ -133,6 +133,29 @@ If you have development competencies, we can propose you specific traineeships + + + + Mitchell Admin + 215 Vine St + Scranton + 18503 + + + +1 555-555-5555 + admin@yourcompany.example.com + + + Mark Demo + 361-7936 Feugiat St. + 58521 + Williston + + +1 555-555-5757 + demo@yourcompany.example.com + private + + @@ -215,6 +238,7 @@ If you have development competencies, we can propose you specific traineeships + Experienced Developer diff --git a/addons/hr_expense/data/hr_expense_demo.xml b/addons/hr_expense/data/hr_expense_demo.xml index fab19ada1e3..2841c7f77de 100644 --- a/addons/hr_expense/data/hr_expense_demo.xml +++ b/addons/hr_expense/data/hr_expense_demo.xml @@ -24,14 +24,6 @@ private - - - - - - - - diff --git a/addons/hr_expense/models/hr_expense.py b/addons/hr_expense/models/hr_expense.py index f1dd1607e55..334535eb993 100644 --- a/addons/hr_expense/models/hr_expense.py +++ b/addons/hr_expense/models/hr_expense.py @@ -383,9 +383,9 @@ class HrExpense(models.Model): raise UserError(_("No credit account found for the %s journal, please configure one.") % (self.sheet_id.bank_journal_id.name)) account_dest = self.sheet_id.bank_journal_id.default_credit_account_id.id else: - if not self.employee_id.address_home_id: + if not self.employee_id.sudo().address_home_id: raise UserError(_("No Home Address found for the employee %s, please configure one.") % (self.employee_id.name)) - partner = self.employee_id.address_home_id.with_company(self.company_id) + partner = self.employee_id.sudo().address_home_id.with_company(self.company_id) account_dest = partner.property_account_payable_id.id or partner.parent_id.property_account_payable_id.id return account_dest @@ -404,7 +404,7 @@ class HrExpense(models.Model): taxes = expense.tax_ids.with_context(round=True).compute_all(expense.unit_amount, expense.currency_id, expense.quantity, expense.product_id) total_amount = 0.0 total_amount_currency = 0.0 - partner_id = expense.employee_id.address_home_id.commercial_partner_id.id + partner_id = expense.employee_id.sudo().address_home_id.commercial_partner_id.id # source move line amount = taxes['total_excluded'] @@ -509,7 +509,7 @@ class HrExpense(models.Model): payment = self.env['account.payment'].create({ 'payment_method_id': payment_methods and payment_methods[0].id or False, 'payment_type': 'outbound' if total_amount < 0 else 'inbound', - 'partner_id': expense.employee_id.address_home_id.commercial_partner_id.id, + 'partner_id': expense.employee_id.sudo().address_home_id.commercial_partner_id.id, 'partner_type': 'supplier', 'journal_id': journal.id, 'date': expense.date,