[FIX] point_of_sale: Invoice and close session without accounting
When you are POS user or manager and don't have any accounting acces rights, yau get and access error when you try to invoice or close the pos session because it tries to create account.move. As the behavior in previous version let it do, we are putting the missing sudo call to properly create an invoice and close a session. closes odoo/odoo#99902 X-original-commit: 84347b43063fc3032da3e03b49fc57375d8324fc Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
@@ -846,13 +846,13 @@ class PosOrder(models.Model):
|
||||
|
||||
def _apply_invoice_payments(self):
|
||||
receivable_account = self.env["res.partner"]._find_accounting_partner(self.partner_id).with_company(self.company_id).property_account_receivable_id
|
||||
payment_moves = self.payment_ids._create_payment_moves()
|
||||
payment_moves = self.payment_ids.sudo().with_company(self.company_id)._create_payment_moves()
|
||||
invoice_receivable = self.account_move.line_ids.filtered(lambda line: line.account_id == receivable_account)
|
||||
# Reconcile the invoice to the created payment moves.
|
||||
# But not when the invoice's total amount is zero because it's already reconciled.
|
||||
if not invoice_receivable.reconciled and receivable_account.reconcile:
|
||||
payment_receivables = payment_moves.mapped('line_ids').filtered(lambda line: line.account_id == receivable_account)
|
||||
(invoice_receivable | payment_receivables).reconcile()
|
||||
(invoice_receivable | payment_receivables).sudo().with_company(self.company_id).reconcile()
|
||||
return payment_moves
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -191,7 +191,7 @@ class PosSession(models.Model):
|
||||
"Cash Registers: %r", list(statement.name for statement in closed_statement_ids)))
|
||||
|
||||
def _check_invoices_are_posted(self):
|
||||
unposted_invoices = self.order_ids.account_move.filtered(lambda x: x.state != 'posted')
|
||||
unposted_invoices = self.order_ids.sudo().with_company(self.company_id).account_move.filtered(lambda x: x.state != 'posted')
|
||||
if unposted_invoices:
|
||||
raise UserError(_('You cannot close the POS when invoices are not posted.\n'
|
||||
'Invoices: %s') % str.join('\n',
|
||||
|
||||
Reference in New Issue
Block a user