diff --git a/addons/point_of_sale/i18n/point_of_sale.pot b/addons/point_of_sale/i18n/point_of_sale.pot index 4463c31026f..5e0140f14ef 100644 --- a/addons/point_of_sale/i18n/point_of_sale.pot +++ b/addons/point_of_sale/i18n/point_of_sale.pot @@ -6671,6 +6671,14 @@ msgstr "" #: code:addons/point_of_sale/models/pos_session.py:0 #: code:addons/point_of_sale/models/pos_session.py:0 #, python-format +msgid "" +"You cannot close the POS when invoices are not posted.\n" +"Invoices: %s" +msgstr "" + +#. module: point_of_sale +#: code:addons/point_of_sale/models/pos_session.py:0 +#, python-format msgid "You cannot close the POS when orders are still in draft" msgstr "" diff --git a/addons/point_of_sale/models/pos_session.py b/addons/point_of_sale/models/pos_session.py index dcf180f00c8..2d485098d82 100644 --- a/addons/point_of_sale/models/pos_session.py +++ b/addons/point_of_sale/models/pos_session.py @@ -191,6 +191,14 @@ class PosSession(models.Model): raise UserError(_("Some Cash Registers are already posted. Please reset them to new in order to close the session.\n" "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') + if unposted_invoices: + raise UserError(_('You cannot close the POS when invoices are not posted.\n' + 'Invoices: %s') % str.join('\n', + ['%s - %s' % (invoice.name, invoice.state) for invoice in + unposted_invoices])) + @api.model def create(self, values): config_id = values.get('config_id') or self.env.context.get('default_config_id') @@ -321,6 +329,7 @@ class PosSession(models.Model): if self.state == 'closed': raise UserError(_('This session is already closed.')) self._check_if_no_draft_orders() + self._check_invoices_are_posted() if self.update_stock_at_closing: self._create_picking_at_end_of_session() self.order_ids.filtered(lambda o: not o.is_total_cost_computed)._compute_total_cost_at_session_closing(self.picking_ids.move_ids)