From ae3951e01b8ee602d0be4298627d187ebca6794c Mon Sep 17 00:00:00 2001 From: Pierre Masereel Date: Mon, 9 Dec 2019 09:23:01 +0000 Subject: [PATCH] [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 --- addons/point_of_sale/models/account_move.py | 8 +++++++- addons/point_of_sale/models/pos_order.py | 2 +- addons/point_of_sale/tests/test_anglo_saxon.py | 1 - 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/addons/point_of_sale/models/account_move.py b/addons/point_of_sale/models/account_move.py index dba398b7966..5223a4738d7 100644 --- a/addons/point_of_sale/models/account_move.py +++ b/addons/point_of_sale/models/account_move.py @@ -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' diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 166fee3f439..4ec1285dfa3 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -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: %s") % (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: diff --git a/addons/point_of_sale/tests/test_anglo_saxon.py b/addons/point_of_sale/tests/test_anglo_saxon.py index 2d22a9d5fef..d6cf96843ea 100644 --- a/addons/point_of_sale/tests/test_anglo_saxon.py +++ b/addons/point_of_sale/tests/test_anglo_saxon.py @@ -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