[FIX] point_of_sale: prevent deletion of POS bank statement

Nothing prevents to delete a bank statement linked to an open pos session,
which leads to a KeyError when validating and posting entries at closure.

closes odoo/odoo#44787

X-original-commit: 7416340e0ff96bdabb0578f9c1eccd79baf83e17
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
This commit is contained in:
alt-odoo
2020-02-06 17:41:12 +00:00
parent 43af0c73b6
commit 0758a02ee4
2 changed files with 11 additions and 0 deletions
@@ -5110,6 +5110,12 @@ msgstr ""
msgid "You cannot create a session before the accounting lock date."
msgstr ""
#. module: point_of_sale
#: code:addons/point_of_sale/models/account_bank_statement.py:0
#, python-format
msgid "You cannot delete a bank statement used in an open Point of Sale session."
msgstr ""
#. module: point_of_sale
#: code:addons/point_of_sale/models/product.py:0
#: code:addons/point_of_sale/models/product.py:0
@@ -17,6 +17,11 @@ class AccountBankStatement(models.Model):
raise UserError(_("You can't validate a bank statement that is used in an opened Session of a Point of Sale."))
return super(AccountBankStatement, self).check_confirm_bank()
def unlink(self):
for bs in self:
if bs.pos_session_id:
raise UserError(_("You cannot delete a bank statement used in an open Point of Sale session."))
return super( AccountBankStatement, self).unlink()
class AccountBankStatementLine(models.Model):
_inherit = 'account.bank.statement.line'