From e5d9653910458602922d69ae374c5cee49d66351 Mon Sep 17 00:00:00 2001 From: Vincent Van Rossem Date: Tue, 22 Sep 2020 18:35:10 +0200 Subject: [PATCH] [ADD] beesdoo_account : validate invoice with negative total amount --- beesdoo_account/README.rst | 9 ++++++ beesdoo_account/__init__.py | 1 + beesdoo_account/__manifest__.py | 12 ++++++-- beesdoo_account/models/__init__.py | 2 ++ beesdoo_account/models/account_invoice.py | 29 ++++++++++++++++++ beesdoo_account/models/res_config.py | 11 +++++++ beesdoo_account/readme/CONFIGURE.rst | 5 ++++ beesdoo_account/security/invoice_security.xml | 9 ++++++ beesdoo_account/static/description/index.html | 30 ++++++++++++------- beesdoo_account/views/res_config_view.xml | 23 ++++++++++++++ 10 files changed, 118 insertions(+), 13 deletions(-) create mode 100644 beesdoo_account/models/__init__.py create mode 100644 beesdoo_account/models/account_invoice.py create mode 100644 beesdoo_account/models/res_config.py create mode 100644 beesdoo_account/readme/CONFIGURE.rst create mode 100644 beesdoo_account/security/invoice_security.xml create mode 100644 beesdoo_account/views/res_config_view.xml diff --git a/beesdoo_account/README.rst b/beesdoo_account/README.rst index eaa14b8..23f6cc2 100644 --- a/beesdoo_account/README.rst +++ b/beesdoo_account/README.rst @@ -26,6 +26,15 @@ Module that customize account module for Beescoop. .. contents:: :local: +Configuration +============= + +The setting *Validate an invoice with a negative total amount* needs to be checked. +This can be done in these following ways: + +* on the Access Rights (Technical Settings) of the user (Validate an invoice with a negative total amount) +* on the Invoicing Settings inside of the section `Invoices` (Allow validating an invoice with a negative total amount) + Bug Tracker =========== diff --git a/beesdoo_account/__init__.py b/beesdoo_account/__init__.py index e69de29..9a7e03e 100644 --- a/beesdoo_account/__init__.py +++ b/beesdoo_account/__init__.py @@ -0,0 +1 @@ +from . import models \ No newline at end of file diff --git a/beesdoo_account/__manifest__.py b/beesdoo_account/__manifest__.py index a05b5b9..0cf27df 100644 --- a/beesdoo_account/__manifest__.py +++ b/beesdoo_account/__manifest__.py @@ -1,19 +1,25 @@ # Copyright 2017 - 2020 BEES coop SCRLfs # - Rémy Taymans +# - Vincent Van Rossem # - Elise Dupont # - Augustin Borsu # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { "name": "Beescoop Account Module", "summary": """ - Makes date_invoice field required in account.invoice_form and + - Makes date_invoice field required in account.invoice_form and account.invoice_supplier_form + - Allow validating an invoice with a negative total amount """, "author": "Beescoop - Cellule IT, Coop IT Easy SCRLfs", "website": "https://github.com/beescoop/Obeesdoo", "category": "Account Module", - "version": "12.0.1.0.0", + "version": "12.0.1.1.0", "depends": ["account", "beesdoo_base"], - "data": ["views/account_invoice.xml"], + "data": [ + "security/invoice_security.xml", + "views/account_invoice.xml", + "views/res_config_view.xml", + ], "license": "AGPL-3", } diff --git a/beesdoo_account/models/__init__.py b/beesdoo_account/models/__init__.py new file mode 100644 index 0000000..60c298b --- /dev/null +++ b/beesdoo_account/models/__init__.py @@ -0,0 +1,2 @@ +from . import account_invoice +from . import res_config diff --git a/beesdoo_account/models/account_invoice.py b/beesdoo_account/models/account_invoice.py new file mode 100644 index 0000000..458ff29 --- /dev/null +++ b/beesdoo_account/models/account_invoice.py @@ -0,0 +1,29 @@ +from odoo import api, fields, models, _ +from odoo.exceptions import UserError + + +class AccountInvoice(models.Model): + _inherit = "account.invoice" + + @api.multi + def action_invoice_open(self): + if self.user_has_groups( + 'beesdoo_account.' + 'group_validate_invoice_negative_total_amount'): + return self.action_invoice_negative_amount_open() + return super(AccountInvoice, self).action_invoice_open() + + @api.multi + def action_invoice_negative_amount_open(self): + """Identical to action_invoice_open without UserError on an invoice with a negative total amount""" + to_open_invoices = self.filtered(lambda inv: inv.state != 'open') + if to_open_invoices.filtered(lambda inv: not inv.partner_id): + raise UserError(_("The field Vendor is required, please complete it to validate the Vendor Bill.")) + if to_open_invoices.filtered(lambda inv: inv.state != 'draft'): + raise UserError(_("Invoice must be in draft state in order to validate it.")) + if to_open_invoices.filtered(lambda inv: not inv.account_id): + raise UserError( + _('No account was found to create the invoice, be sure you have installed a chart of account.')) + to_open_invoices.action_date_assign() + to_open_invoices.action_move_create() + return to_open_invoices.invoice_validate() diff --git a/beesdoo_account/models/res_config.py b/beesdoo_account/models/res_config.py new file mode 100644 index 0000000..4d91f6d --- /dev/null +++ b/beesdoo_account/models/res_config.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + group_validate_invoice_negative_total_amount = fields.Boolean( + """Allow validating an invoice with a negative total amount""", + implied_group="beesdoo_account." "group_validate_invoice_negative_total_amount", + help="""Allows you to validate an invoice with a negative total amount""", + ) \ No newline at end of file diff --git a/beesdoo_account/readme/CONFIGURE.rst b/beesdoo_account/readme/CONFIGURE.rst new file mode 100644 index 0000000..6e3f5c4 --- /dev/null +++ b/beesdoo_account/readme/CONFIGURE.rst @@ -0,0 +1,5 @@ +The setting *Validate an invoice with a negative total amount* needs to be checked. +This can be done in these following ways: + +* on the Access Rights (Technical Settings) of the user (Validate an invoice with a negative total amount) +* on the Invoicing Settings inside of the section `Invoices` (Allow validating an invoice with a negative total amount) \ No newline at end of file diff --git a/beesdoo_account/security/invoice_security.xml b/beesdoo_account/security/invoice_security.xml new file mode 100644 index 0000000..5e1a69e --- /dev/null +++ b/beesdoo_account/security/invoice_security.xml @@ -0,0 +1,9 @@ + + + + + Validate an invoice with a negative total amount + + + diff --git a/beesdoo_account/static/description/index.html b/beesdoo_account/static/description/index.html index d2834e3..3bb264b 100644 --- a/beesdoo_account/static/description/index.html +++ b/beesdoo_account/static/description/index.html @@ -372,17 +372,27 @@ ul.auto-toc {

Table of contents

+
+

Configuration

+

The setting Validate an invoice with a negative total amount needs to be checked. +This can be done in these following ways:

+
    +
  • on the Access Rights (Technical Settings) of the user (Validate an invoice with a negative total amount)
  • +
  • on the Invoicing Settings inside of the section Invoices (Allow validating an invoice with a negative total amount)
  • +
+
-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us smashing it by providing a detailed and welcomed @@ -390,23 +400,23 @@ If you spotted it first, help us smashing it by providing a detailed and welcome

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • Beescoop - Cellule IT
  • Coop IT Easy SCRLfs
-

Contributors

+

Contributors

  • Beescoop - Cellule IT
  • Coop IT Easy SCRLfs
-

Maintainers

+

Maintainers

This module is part of the beescoop/obeesdoo project on GitHub.

You are welcome to contribute.

diff --git a/beesdoo_account/views/res_config_view.xml b/beesdoo_account/views/res_config_view.xml new file mode 100644 index 0000000..8954aa1 --- /dev/null +++ b/beesdoo_account/views/res_config_view.xml @@ -0,0 +1,23 @@ + + + + + res invoice negative total amount settings + res.config.settings + + + +
+
+ +
+
+
+
+
+
+
+