Skip to content

Commit

Permalink
[FIX] account: fix payment posting when user encoding one for another…
Browse files Browse the repository at this point in the history
… 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#53039

X-original-commit: 0bcf351
Signed-off-by: Laurent Smet <[email protected]>
  • Loading branch information
xavieralt committed Jun 16, 2020
1 parent e796485 commit 3d05714
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions addons/account/models/account_payment.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,15 +375,16 @@ def _compute_destination_account_id(self):
raise UserError(_('There is no Transfer Account defined in the accounting settings. Please define one to be able to confirm this transfer.'))
payment.destination_account_id = payment.company_id.transfer_account_id.id
elif payment.partner_id:
partner = self.partner_id.with_context(force_company=self.company_id.id)
if payment.partner_type == 'customer':
payment.destination_account_id = payment.partner_id.property_account_receivable_id.id
payment.destination_account_id = partner.property_account_receivable_id.id
else:
payment.destination_account_id = payment.partner_id.property_account_payable_id.id
payment.destination_account_id = partner.property_account_payable_id.id
elif payment.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')
payment.destination_account_id = default_account.id
elif payment.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')
payment.destination_account_id = default_account.id

@api.depends('move_line_ids.matched_debit_ids', 'move_line_ids.matched_credit_ids')
Expand Down

0 comments on commit 3d05714

Please sign in to comment.