From 043dadaa913c9646cf83d2a7d0293b4766aae07f Mon Sep 17 00:00:00 2001 From: det Date: Fri, 24 Feb 2023 15:39:36 +0000 Subject: [PATCH] [FIX] hr_expense: currency and payable line discrepancy Explanation: A rework of hr_expense has been introduced in master and landed in 16.2. https://github.com/odoo/odoo/commit/f79ff3fb374650670e89f231aaf17bb8d6596c25 There was a need to backport it to 16.0 then 16.1. https://github.com/odoo/odoo/commit/90affb562962d0dc233526e3f15f5b60f383331d During the backport; - a computed fields 'journal_displayed_id' has been introduced and will need to be removed again in master. - 2 bugs have been discovered: -- the analytic.account were not created anymore (function not called) -- the payment terms for expense paid by company could not be modified as a filter was missing closes odoo/odoo#115650 X-original-commit: 672f4efd2c990ab6eef8f934c41625860b8ded46 Signed-off-by: Laurent Smet Signed-off-by: Detry Thomas (det) --- addons/account/tests/common.py | 14 ++--- addons/account/views/account_payment_view.xml | 6 +- addons/hr_expense/i18n/hr_expense.pot | 21 +++++++ addons/hr_expense/models/account_move.py | 4 +- addons/hr_expense/models/account_move_line.py | 6 -- addons/hr_expense/models/account_payment.py | 3 + addons/hr_expense/models/hr_expense.py | 13 +++- addons/hr_expense/tests/common.py | 13 ++++ addons/hr_expense/tests/test_expenses.py | 62 +++++++++---------- .../hr_expense/views/account_move_views.xml | 4 +- addons/sale_expense/models/hr_expense.py | 14 ----- .../sale_expense/models/hr_expense_sheet.py | 14 +++++ 12 files changed, 108 insertions(+), 66 deletions(-) diff --git a/addons/account/tests/common.py b/addons/account/tests/common.py index 50743012fc5..5d7d68de955 100644 --- a/addons/account/tests/common.py +++ b/addons/account/tests/common.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import fields +from odoo import fields, Command from odoo.tests.common import TransactionCase, HttpCase, tagged, Form import json @@ -60,7 +60,7 @@ class AccountTestInvoicingCommon(TransactionCase): cls.company_data = cls.setup_company_data('company_1_data', chart_template=chart_template_ref) user.write({ - 'company_ids': [(6, 0, (cls.company_data['company'] + cls.company_data_2['company']).ids)], + 'company_ids': [Command.set((cls.company_data['company'] + cls.company_data_2['company']).ids)], 'company_id': cls.company_data['company'].id, }) @@ -81,8 +81,8 @@ class AccountTestInvoicingCommon(TransactionCase): 'standard_price': 800.0, 'property_account_income_id': cls.company_data['default_account_revenue'].id, 'property_account_expense_id': cls.company_data['default_account_expense'].id, - 'taxes_id': [(6, 0, cls.tax_sale_a.ids)], - 'supplier_taxes_id': [(6, 0, cls.tax_purchase_a.ids)], + 'taxes_id': [Command.set(cls.tax_sale_a.ids)], + 'supplier_taxes_id': [Command.set(cls.tax_purchase_a.ids)], }) cls.product_b = cls.env['product.product'].create({ 'name': 'product_b', @@ -91,8 +91,8 @@ class AccountTestInvoicingCommon(TransactionCase): 'standard_price': 160.0, 'property_account_income_id': cls.copy_account(cls.company_data['default_account_revenue']).id, 'property_account_expense_id': cls.copy_account(cls.company_data['default_account_expense']).id, - 'taxes_id': [(6, 0, (cls.tax_sale_a + cls.tax_sale_b).ids)], - 'supplier_taxes_id': [(6, 0, (cls.tax_purchase_a + cls.tax_purchase_b).ids)], + 'taxes_id': [Command.set((cls.tax_sale_a + cls.tax_sale_b).ids)], + 'supplier_taxes_id': [Command.set((cls.tax_purchase_a + cls.tax_purchase_b).ids)], }) # ==== Fiscal positions ==== @@ -666,7 +666,7 @@ class TestAccountReconciliationCommon(AccountTestInvoicingCommon): 'name': 'product that cost %s' % invoice_amount, 'quantity': 1, 'price_unit': invoice_amount, - 'tax_ids': [(6, 0, [])], + 'tax_ids': [Command.set([])], })] } diff --git a/addons/account/views/account_payment_view.xml b/addons/account/views/account_payment_view.xml index 2132705d522..c2d1107eb1c 100644 --- a/addons/account/views/account_payment_view.xml +++ b/addons/account/views/account_payment_view.xml @@ -227,8 +227,10 @@ - + attrs="{'invisible': [('expense_sheet_id', '=', [])]}"/> diff --git a/addons/sale_expense/models/hr_expense.py b/addons/sale_expense/models/hr_expense.py index 6299dbb46b4..536cd75cea6 100644 --- a/addons/sale_expense/models/hr_expense.py +++ b/addons/sale_expense/models/hr_expense.py @@ -42,17 +42,3 @@ class Expense(models.Model): for split_value in vals: split_value['sale_order_id'] = self.sale_order_id.id return vals - - def action_move_create(self): - """ When posting expense, if the AA is given, we will track cost in that - If a SO is set, this means we want to reinvoice the expense. But to do so, we - need the analytic entries to be generated, so a AA is required to reinvoice. So, - we ensure the AA if a SO is given. - """ - for expense in self.filtered(lambda expense: expense.sale_order_id and not expense.analytic_distribution): - if not expense.sale_order_id.analytic_account_id: - expense.sale_order_id._create_analytic_account() - expense.write({ - 'analytic_distribution': {expense.sale_order_id.analytic_account_id.id: 100} - }) - return super(Expense, self).action_move_create() diff --git a/addons/sale_expense/models/hr_expense_sheet.py b/addons/sale_expense/models/hr_expense_sheet.py index b65d0ee4716..768373dbf59 100644 --- a/addons/sale_expense/models/hr_expense_sheet.py +++ b/addons/sale_expense/models/hr_expense_sheet.py @@ -34,3 +34,17 @@ class HrExpenseSheet(models.Model): 'name': _('Reinvoiced Sales Orders'), 'domain': [('id', 'in', self.expense_line_ids.sale_order_id.ids)], } + + def _do_create_moves(self): + """ When posting expense, if the AA is given, we will track cost in that + If a SO is set, this means we want to reinvoice the expense. But to do so, we + need the analytic entries to be generated, so a AA is required to reinvoice. So, + we ensure the AA if a SO is given. + """ + for expense in self.expense_line_ids.filtered(lambda expense: expense.sale_order_id and not expense.analytic_distribution): + if not expense.sale_order_id.analytic_account_id: + expense.sale_order_id._create_analytic_account() + expense.write({ + 'analytic_distribution': {expense.sale_order_id.analytic_account_id.id: 100} + }) + return super()._do_create_moves()