[IMP] point_of_sale: make pos_session multi company aware

When creating a pos session we try to link the session to
the first cash journal we find.

The problem is that we cannot link a journal comming from another
company this is strictly forbidden by a constraint.

This is why we should make sure that we search only for journals in the
same company as the config.

Task 1913733
This commit is contained in:
RomainLibert
2019-02-18 16:16:20 +00:00
committed by Yannick Tivisse
parent ef048c24de
commit afde04dd54
+3 -3
View File
@@ -179,11 +179,11 @@ class PosSession(models.Model):
# define some cash journal if no payment method exists
if not pos_config.journal_ids:
Journal = self.env['account.journal']
journals = Journal.with_context(ctx).search([('journal_user', '=', True), ('type', '=', 'cash')])
journals = Journal.with_context(ctx).search([('journal_user', '=', True), ('type', '=', 'cash'), ('company_id', '=', pos_config.company_id.id)])
if not journals:
journals = Journal.with_context(ctx).search([('type', '=', 'cash')])
journals = Journal.with_context(ctx).search([('type', '=', 'cash'), ('company_id', '=', pos_config.company_id.id)])
if not journals:
journals = Journal.with_context(ctx).search([('journal_user', '=', True)])
journals = Journal.with_context(ctx).search([('journal_user', '=', True), ('company_id', '=', pos_config.company_id.id)])
journals.sudo().write({'journal_user': True})
pos_config.sudo().write({'journal_ids': [(6, 0, journals.ids)]})