[FIX] point_of_sale: post refund invoice and avoid payment

When a refund of pos order is made in the POS backend, the invoice was
created in draft, which is a different behavior than when an order is
created.

So we now automatically post the refund invoice once it is created, and
hide the button 'Payment', because if the invoice is reconciled with an
account payment, the session cannot be closed anymore as the invoice
should be reconciled with POS recievable.

We are also fixing a multi-company issue, because the validation of the
invoice was made in the company of the user, instead of the company of
the order.

closes odoo/odoo#41734

Issue-id: 2129357
X-original-commit: 1c0e5d1ad56802b23174809cdfd4b22914fc1ba5
Signed-off-by: pimodoo <pimodoo@users.noreply.github.com>
This commit is contained in:
Pierre Masereel
2019-12-10 15:47:58 +00:00
parent b649b18dd5
commit ae3951e01b
3 changed files with 8 additions and 3 deletions
+7 -1
View File
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
from odoo import fields, models, api
class AccountMove(models.Model):
@@ -17,6 +17,12 @@ class AccountMove(models.Model):
stock_moves += invoice.sudo().mapped('pos_order_ids.picking_ids.move_lines').filtered(lambda x: x.state == 'done' and x.location_id.usage == 'customer')
return stock_moves
def _compute_amount(self):
super(AccountMove, self)._compute_amount()
pos_invoices = self.filtered(lambda i: i.type in ['out_invoice', 'out_refund'] and i.pos_order_ids)
for invoice in pos_invoices:
invoice.invoice_payment_state = 'paid'
class AccountMoveLine(models.Model):
_inherit = 'account.move.line'
+1 -1
View File
@@ -140,7 +140,6 @@ class PosOrder(models.Model):
pos_order._create_order_picking()
if pos_order.to_invoice and pos_order.state == 'paid':
pos_order.action_pos_order_invoice()
pos_order.account_move.sudo().post()
return pos_order.id
@@ -404,6 +403,7 @@ class PosOrder(models.Model):
message = _("This invoice has been created from the point of sale session: <a href=# data-oe-model=pos.order data-oe-id=%d>%s</a>") % (order.id, order.name)
new_move.message_post(body=message)
order.write({'account_move': new_move.id, 'state': 'invoiced'})
new_move.sudo().with_company(order.company_id).post()
moves += new_move
if not moves:
@@ -214,7 +214,6 @@ class TestAngloSaxonFlow(TestAngloSaxonCommon):
# Create the customer invoice
pos_order_pos0.action_pos_order_invoice()
pos_order_pos0.account_move.post()
# validate the session
current_session_id = self.pos_config.current_session_id