Skip to content

Commit

Permalink
Merge PR #496 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by aheficent
  • Loading branch information
OCA-git-bot committed Oct 22, 2019
2 parents 57bc7de + 3b57ce0 commit 59adf38
Show file tree
Hide file tree
Showing 15 changed files with 357 additions and 0 deletions.
65 changes: 65 additions & 0 deletions account_invoice_blocking/README.rst
@@ -0,0 +1,65 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

========================
Account Invoice Blocking
========================

This module allows the user to set a blocking (No Follow-up) flag directly on the invoice. This facilitates the blocking of the invoice's move lines.

Usage
=====

You can set the No Follow-up flag on invoices

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/95/11.0


Known issues / Roadmap
======================

Future possible improvement :
Blocking invoice can also mean "do not send overdue reminders", so the blocking flag could be displayed on both supplier and customer invoices.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/account-invoicing/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.

Contributors
------------

* Adrien Peiffer <adrien.peiffer@acsone.eu>
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
* Thomas Binsfeld <thomas.binsfeld@acsone.eu>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Nikul Chaudhary <nikulchaudhary2112@gmail.com>

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
3 changes: 3 additions & 0 deletions account_invoice_blocking/__init__.py
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import models
18 changes: 18 additions & 0 deletions account_invoice_blocking/__manifest__.py
@@ -0,0 +1,18 @@
# Copyright 2016 Acsone SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
'name': 'Account Invoice Blocking',
'summary': 'Set a blocking (No Follow-up) flag on invoices',
'version': '12.0.1.0.0',
'license': 'AGPL-3',
'category': 'Accounting',
'author': 'Acsone SA/NV,Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/account-invoicing/',
'depends': [
'account'
],
'data': [
'views/account_invoice.xml',
],
}
31 changes: 31 additions & 0 deletions account_invoice_blocking/i18n/account_invoice_blocking.pot
@@ -0,0 +1,31 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_blocking
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: <>\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: account_invoice_blocking
#: model:ir.model,name:account_invoice_blocking.model_account_invoice
msgid "Invoice"
msgstr ""

#. module: account_invoice_blocking
#: model:ir.model.fields,field_description:account_invoice_blocking.field_account_invoice_blocked
#: model:ir.model.fields,field_description:account_invoice_blocking.field_account_invoice_draft_blocked
msgid "No Follow-up"
msgstr ""

#. module: account_invoice_blocking
#: model:ir.model.fields,help:account_invoice_blocking.field_account_invoice_draft_blocked
msgid "This flag facilitates the blocking of the invoice's move lines."
msgstr ""

34 changes: 34 additions & 0 deletions account_invoice_blocking/i18n/nl.po
@@ -0,0 +1,34 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_invoice_blocking
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 11.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2018-12-14 10:58+0000\n"
"Last-Translator: Yung-Wa <yw.ng@onestein.nl>\n"
"Language-Team: none\n"
"Language: nl\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 3.3\n"

#. module: account_invoice_blocking
#: model:ir.model,name:account_invoice_blocking.model_account_invoice
msgid "Invoice"
msgstr "Factuur"

#. module: account_invoice_blocking
#: model:ir.model.fields,field_description:account_invoice_blocking.field_account_invoice_blocked
#: model:ir.model.fields,field_description:account_invoice_blocking.field_account_invoice_draft_blocked
msgid "No Follow-up"
msgstr "Geen opvolging"

#. module: account_invoice_blocking
#: model:ir.model.fields,help:account_invoice_blocking.field_account_invoice_draft_blocked
msgid "This flag facilitates the blocking of the invoice's move lines."
msgstr ""
"De optie maakt het mogelijk om factuuregels uit te sluiten van opvolging."
3 changes: 3 additions & 0 deletions account_invoice_blocking/models/__init__.py
@@ -0,0 +1,3 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from . import account_invoice
85 changes: 85 additions & 0 deletions account_invoice_blocking/models/account_invoice.py
@@ -0,0 +1,85 @@
# Copyright 2016 Acsone SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class AccountInvoice(models.Model):
_inherit = 'account.invoice'

@api.multi
def _get_move_line(self):
"""
This method searches for payable or receivable move line
of the invoice
:returns payable or receivable move line of the invoice
"""
self.ensure_one()
type_receivable = self.env.ref('account.data_account_type_receivable')
type_payable = self.env.ref('account.data_account_type_payable')
user_type_id_list = [type_receivable.id, type_payable.id]
return self.env['account.move.line'].search([
('account_id.user_type_id', 'in', user_type_id_list),
('invoice_id', '=', self.id)
])

@api.multi
def _update_blocked(self, value):
"""
This method updates the boolean field 'blocked' of the move line
of the passed invoice with the passed value
:param value: value to set to the 'blocked' field of the move line
"""
self.ensure_one()
if self.move_id:
move_line_ids = self._get_move_line()
move_line_ids.write({'blocked': value})

@api.multi
def _inverse_move_blocked(self):
"""
Inverse method of the computed field 'blocked'
This method calls the update of the invoice's move line based on
the value of the field 'blocked'
"""
for invoice in self:
invoice._update_blocked(invoice.blocked)

@api.multi
def action_move_create(self):
"""
This method overrides the invoice's move line creation
This method calls the update of the invoice's move lines based on
the value of the field 'draft_blocked'
"""
res = super(AccountInvoice, self).action_move_create()
for invoice in self:
invoice._update_blocked(invoice.draft_blocked)
return res

@api.depends('move_id')
def _compute_move_blocked(self):
"""
This method set the value of the field 'invoice.blocked' to True
If every line of the invoice's move is actualy blocked
"""
for invoice in self:
if not invoice.move_id:
invoice.blocked = False
continue

move_lines = invoice._get_move_line()
invoice.blocked = all(
(line.blocked for line in move_lines)
) if move_lines else False

blocked = fields.Boolean(
'No Follow-up',
states={'draft': [('readonly', True)]},
compute='_compute_move_blocked',
inverse='_inverse_move_blocked'
)

draft_blocked = fields.Boolean(
help="This flag facilitates the blocking of the invoice's move lines."
)
5 changes: 5 additions & 0 deletions account_invoice_blocking/readme/CONTRIBUTORS.rst
@@ -0,0 +1,5 @@
* Adrien Peiffer <adrien.peiffer@acsone.eu>
* Stéphane Bidoul <stephane.bidoul@acsone.eu>
* Thomas Binsfeld <thomas.binsfeld@acsone.eu>
* Andrea Stirpe <a.stirpe@onestein.nl>
* Nikul Chaudhary <nikulchaudhary2112@gmail.com>
1 change: 1 addition & 0 deletions account_invoice_blocking/readme/DESCRIPTION.rst
@@ -0,0 +1 @@
This module allows the user to set a blocking (No Follow-up) flag directly on the invoice. This facilitates the blocking of the invoice's move lines.
2 changes: 2 additions & 0 deletions account_invoice_blocking/readme/ROADMAP.rst
@@ -0,0 +1,2 @@
Future possible improvement :
Blocking invoice can also mean "do not send overdue reminders", so the blocking flag could be displayed on both supplier and customer invoices.
1 change: 1 addition & 0 deletions account_invoice_blocking/readme/USAGE.rst
@@ -0,0 +1 @@
You can set the No Follow-up flag on invoices.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions account_invoice_blocking/tests/__init__.py
@@ -0,0 +1 @@
from . import test_account_invoice_blocking
90 changes: 90 additions & 0 deletions account_invoice_blocking/tests/test_account_invoice_blocking.py
@@ -0,0 +1,90 @@
# Copyright 2016 Acsone SA/NV
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase


class TestAccountInvoiceBlocking(TransactionCase):

def setUp(self):
"""
Setup test instances
"""
super(TestAccountInvoiceBlocking, self).setUp()
company = self.env.ref('base.main_company')
# Instance: account type (receivable)
self.type_recv = self.env.ref('account.data_account_type_receivable')
# Instance: account type (payable)
self.type_payable = self.env.ref('account.data_account_type_payable')
# account (receivable)
account_recv = self.env['account.account'].create({
'name': 'test_account_receivable',
'code': '123',
'user_type_id': self.type_recv.id,
'company_id': company.id,
'reconcile': True})

# account (payable)
account_payable = self.env['account.account'].create({
'name': 'test_account_payable',
'code': '321',
'user_type_id': self.type_payable.id,
'company_id': company.id,
'reconcile': True})

partner = self.env.ref('base.res_partner_2')
journal = self.env['account.journal'].search([('code', '=', 'BILL')])
product = self.env.ref('product.product_product_4')

invoice_line = self.env['account.invoice.line'].create({
'name': 'test',
'account_id': account_payable.id,
'price_unit': 2000.00,
'quantity': 1,
'product_id': product.id})

# Instance: invoice
self.invoice = self.env['account.invoice'].create({
'partner_id': partner.id,
'account_id': account_recv.id,
'payment_term_id': False,
'journal_id': journal.id,
'invoice_line_ids': [(4, invoice_line.id)]})

def test_01_invoice_blocking(self):
"""
Test Blocking Invoice
"""

self.invoice.draft_blocked = True
self.invoice.action_invoice_open()

types_list = [self.type_recv.id, self.type_payable.id]
move_lines = self.env['account.move.line'].search([
('account_id.user_type_id', 'in', types_list),
('invoice_id', '=', self.invoice.id)
])
self.assertTrue(move_lines)
for move_line in move_lines:
self.assertTrue(move_line.blocked)
self.assertEqual(
self.invoice.blocked, move_line.blocked,
'Blocked values are not equals')

self.invoice = self.env['account.invoice'].search([
('id', '=', self.invoice.id)
])
for move_line in move_lines:
move_line.blocked = False
self.assertEqual(
self.invoice.blocked, move_line.blocked,
'Blocked values are not equals')

self.invoice = self.env['account.invoice'].search([
('id', '=', self.invoice.id)
])
self.invoice.blocked = True
for move_line in move_lines:
self.assertEqual(
self.invoice.blocked, move_line.blocked,
'Blocked values are not equals')
18 changes: 18 additions & 0 deletions account_invoice_blocking/views/account_invoice.xml
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 Acsone SA/NV
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->

<odoo>

<record id="account_invoice_form_view" model="ir.ui.view">
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<field name="move_id" position="after">
<field name="blocked" attrs="{'invisible': [('move_id', '=', False)]}"/>
<field name="draft_blocked" string="No Follow-up" attrs="{'invisible': [('move_id', '!=', False)]}"/>
</field>
</field>
</record>

</odoo>

0 comments on commit 59adf38

Please sign in to comment.