Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX] hr_expense: bill partner child contact #159911

Draft
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

Conversation

agr-odoo
Copy link
Contributor

Open a [DEMO] employee record
Set the Bank Account Number under 'Private Information'
Open the contact (res.partner) of [DEMO]
Set the parent contact to be the current company
Add a bank account on the contact for current company
Go to Expenses and create a new expense for [DEMO], with Paid By "Employee (to reimburse)"
Create Report, Submit Report, Approve, then Post Journal Entries.

Issue: On the created bill, partner will be the parent company and also
the bank account will be the one of the parent company.
When registering payment from:

  • bill: the user will see the bank account of the company
  • expense: the user will see the bank account of the employee

opw-3800134

@robodoo
Copy link
Contributor

robodoo commented Mar 29, 2024

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Mar 29, 2024
@agr-odoo agr-odoo requested a review from Levizar April 12, 2024 14:01
@agr-odoo
Copy link
Contributor Author

Hello @Levizar
When it is possible could you give a look at this? I'm not sure it is functionally sound, but at the same time the current behavior of the system seems not consistent

@Levizar
Copy link
Contributor

Levizar commented Apr 18, 2024

@JulienAlardot Could you have a look at it?

OFC, @agr-odoo is right, it doesn't make sense to reimburse the company instead of the employee.

Copy link
Contributor

@JulienAlardot JulienAlardot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% a bug, but this fix confuses me a lot 🤔

Comment on lines 1292 to 1293
if self.payment_mode == 'company_account':
partner_id = self.employee_id.sudo().address_home_id.commercial_partner_id.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should never be the case, as only own_account expenses call this one

if self.payment_mode == 'company_account':
partner_id = self.employee_id.sudo().address_home_id.commercial_partner_id.id
else:
partner_id = self.employee_id.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.env['res.partner'] != self.env['hr.employee']

if self.payment_mode == 'company_account':
partner_id = self.employee_id.sudo().address_home_id.commercial_partner_id.id
else:
partner_id = self.employee_id.id
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you test the fix because I'm surprised it works.
We discussed it a bit with JUAL and unless I'm mistaken, self.employee_id isn't a res.partner and thus it is probably working by chance. :/

@agr-odoo
Copy link
Contributor Author

agr-odoo commented Apr 18, 2024

My bad, it seems I left this 'fix' in an inconsistent state and forgot about it 😅
However thanks for the functional check, I'll fix the fix and add a test for this case

Open a [DEMO] employee record
Set the Bank Account Number under 'Private Information'
Open the contact (res.partner) of [DEMO]
Set the parent contact to be the current company
Add a bank account on the contact for current company
Go to Expenses and create a new expense for [DEMO], with Paid By "Employee (to reimburse)"
Create Report, Submit Report, Approve, then Post Journal Entries.

Issue: On the created bill, partner will be the parent company and also
the bank account will be the one of the parent company.
When registering payment from:
- bill: the user will see the bank account of the company
- expense: the user will see the bank account of the employee

opw-3800134
@agr-odoo
Copy link
Contributor Author

First of all I apologize If I pinged you on a very much draft PR
I checked everything again and in my opinion this might be a technical limitation.

By default the move partner is the commercial partner, so in this use case, it would be the parent company, from which the system computes the appropriate bank account
If we force partner_id on the move vals, we can't set the bank_partner_id because it's a computed field and this will be used to get the partner_bank_id
If we force partner_id and partner_bank_id, the bank account shown on the move is correct, but in the register payment wizard is not. The wizard partner_bank_id is not directly taken from the move but it is recomputed taking into account the partner of the payment term aml, which is, again, the commercial partner.

Then, if we look at the register payment wizardon the expense form, we find this override to select the employee account

if expense_sheet and not line.move_id.partner_bank_id:

In conclusion, this might be an expected limitation so the user should either:

  • Register a payment from the expense payment widget
  • Avoid setting a parent company for the employee related partner

@Levizar
Copy link
Contributor

Levizar commented Apr 26, 2024

@agr-odoo Couldn´t we set a context key before retrieving the account to use and in the method that finaly retrieves it, check for the context key to early return the partnerś bank account and avoid using the company one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants