diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py index 768b5cd1dbb..78e1b99c613 100644 --- a/addons/point_of_sale/models/pos_order.py +++ b/addons/point_of_sale/models/pos_order.py @@ -281,7 +281,7 @@ class PosOrder(models.Model): ) payment_ids = fields.One2many('pos.payment', 'pos_order_id', string='Payments', readonly=True) session_move_id = fields.Many2one('account.move', string='Session Journal Entry', related='session_id.move_id', readonly=True, copy=False) - to_invoice = fields.Boolean('To invoice') + to_invoice = fields.Boolean('To invoice', copy=False) to_ship = fields.Boolean('To ship') is_invoiced = fields.Boolean('Is Invoiced', compute='_compute_is_invoiced') is_tipped = fields.Boolean('Is this already tipped?', readonly=True) diff --git a/addons/point_of_sale/tests/test_point_of_sale_flow.py b/addons/point_of_sale/tests/test_point_of_sale_flow.py index 0a2a49df634..fd73b8a5c2a 100644 --- a/addons/point_of_sale/tests/test_point_of_sale_flow.py +++ b/addons/point_of_sale/tests/test_point_of_sale_flow.py @@ -1104,3 +1104,53 @@ class TestPointOfSaleFlow(TestPointOfSaleCommon): self.assertEqual(len(picking_mls_no_stock), 0) self.assertEqual(len(picking_mls_stock), 1) self.assertEqual(len(pickings.picking_type_id), 2) + + def test_order_refund_picking(self): + self.pos_config.open_session_cb() + current_session = self.pos_config.current_session_id + current_session.update_stock_at_closing = True + # I create a new PoS order with 1 line + order = self.PosOrder.create({ + 'company_id': self.env.company.id, + 'session_id': current_session.id, + 'partner_id': self.partner1.id, + 'pricelist_id': self.partner1.property_product_pricelist.id, + 'lines': [(0, 0, { + 'name': "OL/0001", + 'product_id': self.product3.id, + 'price_unit': 450, + 'discount': 5.0, + 'qty': 2.0, + 'tax_ids': [(6, 0, self.product3.taxes_id.ids)], + 'price_subtotal': 450 * (1 - 5/100.0) * 2, + 'price_subtotal_incl': 450 * (1 - 5/100.0) * 2, + })], + 'amount_total': 1710.0, + 'amount_tax': 0.0, + 'amount_paid': 0.0, + 'amount_return': 0.0, + 'to_invoice': True + }) + + payment_context = {"active_ids": order.ids, "active_id": order.id} + order_payment = self.PosMakePayment.with_context(**payment_context).create({ + 'amount': order.amount_total, + 'payment_method_id': self.cash_payment_method.id + }) + order_payment.with_context(**payment_context).check() + + # I create a refund + refund_action = order.refund() + refund = self.PosOrder.browse(refund_action['res_id']) + + payment_context = {"active_ids": refund.ids, "active_id": refund.id} + refund_payment = self.PosMakePayment.with_context(**payment_context).create({ + 'amount': refund.amount_total, + 'payment_method_id': self.cash_payment_method.id, + }) + + # I click on the validate button to register the payment. + refund_payment.with_context(**payment_context).check() + + refund.action_pos_order_invoice() + self.assertEqual(refund.picking_count, 1)