Skip to content
Snippets Groups Projects
Commit 0bcf3518 authored by Xavier ALT's avatar Xavier ALT
Browse files

[FIX] account: fix payment posting when user encoding one for another company


Consider a multi-company database with user A allowed on multiple
companies (ex: YourCompany (USD), Belgian Company (EUR))

- user A switch to "YourCompany"
- Go to Accounting / Sales / Documents / Payment
- Create a new payment, with:

  * Payment Type = "Received Money"
  * Partner Type = "Customer"
  * Partner = "Agrolait"
  * Payment Journal = "Bank (EUR)"
    (i.e. journal of "Belgiam Company")
  * Payment Amount = "200" "EUR"

- Click on "Confirm"

=> An error is raised "Cannot create moves for different companies."

This commit ensure that when creating the payment journal entry, the
`destination account` is always computed relative to the payment's
company and not the current company of the user.

OPW-2192639

closes odoo/odoo#52802

Signed-off-by: default avatarLaurent Smet <smetl@users.noreply.github.com>
parent 625da813
No related branches found
No related tags found
No related merge requests found
......@@ -370,15 +370,16 @@ class account_payment(models.Model):
raise UserError(_('Transfer account not defined on the company.'))
self.destination_account_id = self.company_id.transfer_account_id.id
elif self.partner_id:
partner = self.partner_id.with_context(force_company=self.company_id.id)
if self.partner_type == 'customer':
self.destination_account_id = self.partner_id.property_account_receivable_id.id
self.destination_account_id = partner.property_account_receivable_id.id
else:
self.destination_account_id = self.partner_id.property_account_payable_id.id
self.destination_account_id = partner.property_account_payable_id.id
elif self.partner_type == 'customer':
default_account = self.env['ir.property'].get('property_account_receivable_id', 'res.partner')
default_account = self.env['ir.property'].with_context(force_company=self.company_id.id).get('property_account_receivable_id', 'res.partner')
self.destination_account_id = default_account.id
elif self.partner_type == 'supplier':
default_account = self.env['ir.property'].get('property_account_payable_id', 'res.partner')
default_account = self.env['ir.property'].with_context(force_company=self.company_id.id).get('property_account_payable_id', 'res.partner')
self.destination_account_id = default_account.id
@api.onchange('partner_type')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment