Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] Cancel invoice that is linked with a payment line #7

Open
wants to merge 4 commits into
base: 8.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ addons:

env:
- VERSION="8.0" LINT_CHECK="1"
- VERSION="8.0" ODOO_REPO="odoo/odoo" LINT_CHECK="0"
- VERSION="8.0" ODOO_REPO="OCA/OCB" LINT_CHECK="0"
- VERSION="8.0" ODOO_REPO="odoo/odoo" EXCLUDE="account_default_draft_move,account_payment_include_draft_move" LINT_CHECK="0"
- VERSION="8.0" ODOO_REPO="OCA/OCB" EXCLUDE="account_default_draft_move,account_payment_include_draft_move" LINT_CHECK="0"
- VERSION="8.0" ODOO_REPO="odoo/odoo" INCLUDE="account_payment_include_draft_move" LINT_CHECK="0"
- VERSION="8.0" ODOO_REPO="OCA/OCB" INCLUDE="account_payment_include_draft_move" LINT_CHECK="0"

virtualenv:
system_site_packages: true

install:
- git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools
- git clone https://github.com/OCA/account-financial-tools.git ${HOME}/account-financial-tools
- export PATH=${HOME}/maintainer-quality-tools/travis:${PATH}
- pip install unidecode
- travis_install_nightly
Expand Down
1 change: 1 addition & 0 deletions account_payment_include_draft_move/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
##############################################################################

from . import wizard
from . import models
9 changes: 7 additions & 2 deletions account_payment_include_draft_move/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@
"website": "http://www.acsone.eu",
"images": [],
"category": "Accounting",
"depends": ["account_banking_payment_export"],
"data": [],
"depends": ["account_banking_payment_export",
"account_default_draft_move",
],
"data": [
'views/account_invoice_view.xml',
'wizard/validate_invoice_cancel_view.xml',
],
"demo": [],
"test": [],
"licence": "AGPL-3",
Expand Down
54 changes: 54 additions & 0 deletions account_payment_include_draft_move/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_include_draft_move
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-05-20 12:25+0000\n"
"PO-Revision-Date: 2015-05-20 12:25+0000\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_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "Cancel"
msgstr "Annuler"

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "I accept and force invoice's cancellation"
msgstr "J'accepte et force l'annulation de la facture"

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

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "This process can be dangerous. You assume the possible consequences of this action."
msgstr "Cette procédure peut être dangereuse. Vous assumez les consquénces possible de cette action."

#. module: account_payment_include_draft_move
#: code:addons/account_payment_include_draft_move/models/account_invoice.py:53
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
#, python-format
msgid "Validate Invoice Cancel"
msgstr "Validation de l'annulation de la facture"

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "WARNING ! You try to cancel an invoice related to a payment order."
msgstr "ATTENTION ! Vous tentez d'annuler une facture liée à une ligne de paiement."

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "or"
msgstr "ou"

54 changes: 54 additions & 0 deletions account_payment_include_draft_move/i18n/fr_BE.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * account_payment_include_draft_move
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 8.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2015-05-20 12:25+0000\n"
"PO-Revision-Date: 2015-05-20 12:25+0000\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_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "Cancel"
msgstr "Annuler"

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "I accept and force invoice's cancellation"
msgstr "J'accepte et force l'annulation de la facture"

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

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "This process can be dangerous. You assume the possible consequences of this action."
msgstr "Cette procédure peut être dangereuse. Vous assumez les consquénces possible de cette action."

#. module: account_payment_include_draft_move
#: code:addons/account_payment_include_draft_move/models/account_invoice.py:53
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
#, python-format
msgid "Validate Invoice Cancel"
msgstr "Validation de l'annulation de la facture"

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "WARNING ! You try to cancel an invoice related to a payment order."
msgstr "ATTENTION ! Vous tentez d'annuler une facture liée à une ligne de paiement."

#. module: account_payment_include_draft_move
#: view:validate.invoice.cancel:account_payment_include_draft_move.validate_invoice_cancel
msgid "or"
msgstr "ou"

23 changes: 23 additions & 0 deletions account_payment_include_draft_move/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from . import account_invoice
71 changes: 71 additions & 0 deletions account_payment_include_draft_move/models/account_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2015 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

from openerp import models, api, workflow, _


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

@api.model
def get_payment_line_linked(self, invoice):
payment_line_obj = self.env['payment.line']
payment_lines = []
if invoice.move_id.id and invoice.move_id.line_id:
inv_mv_lines = [x.id for x in invoice.move_id.line_id]
payment_lines = payment_line_obj\
.search([('move_line_id', 'in', inv_mv_lines)])
return payment_lines

@api.model
def check_payment_line_linked(self, invoice):
payment_lines = self.get_payment_line_linked(invoice)
if len(payment_lines) > 0:
return True
else:
return False

@api.model
def open_validate_invoice_cancel(self, invoice):
wizard = self.env['validate.invoice.cancel'].create({})
ctx = self.env.context.copy()
ctx['invoice_id'] = invoice.id
return {
'name': _("Validate Invoice Cancel"),
'view_mode': 'form',
'view_type': 'form',
'res_model': 'validate.invoice.cancel',
'res_id': wizard.id,
'type': 'ir.actions.act_window',
'target': 'new',
'context': ctx
}

@api.multi
def invoice_cancel(self):
for invoice in self:
if self.check_payment_line_linked(invoice):
return self.open_validate_invoice_cancel(invoice)
else:
return workflow.trg_validate(self._uid, str(self._model),
invoice.id, 'invoice_cancel',
self._cr)
24 changes: 24 additions & 0 deletions account_payment_include_draft_move/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
#

from . import test_cancel_invoice
107 changes: 107 additions & 0 deletions account_payment_include_draft_move/tests/test_cancel_invoice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# -*- coding: utf-8 -*-
#
##############################################################################
#
# Authors: Adrien Peiffer
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################

import openerp.tests.common as common
from openerp import workflow, fields


def create_simple_invoice(self, date):
journal_id = self.ref('account.sales_journal')
partner_id = self.ref('base.res_partner_4')
product_id = self.ref('product.product_product_4')
return self.env['account.invoice']\
.create({'partner_id': partner_id,
'account_id':
self.ref('account.a_pay'),
'journal_id':
journal_id,
'date_invoice': date,
'date_due': date,
'type': 'in_invoice',
'invoice_line': [(0, 0, {'name': 'test',
'account_id':
self.ref('account.a_expense'),
'price_unit': 2000.00,
'quantity': 1,
'product_id': product_id,
}
)
],
})


class TestCancelInvoice(common.TransactionCase):

def setUp(self):
super(TestCancelInvoice, self).setUp()
self.context = self.registry("res.users").context_get(self.cr,
self.uid)

def test_cancel_invoice(self):
date = fields.Date.today()
invoice = create_simple_invoice(self, date)
workflow.trg_validate(self.uid, 'account.invoice', invoice.id,
'invoice_open', self.cr)
# I check if created invoice isn't linked with a payment line
invoice_obj = self.env['account.invoice']
payment_lines = invoice_obj.get_payment_line_linked(invoice)
self.assertTrue(len(payment_lines) == 0,
"Invoice is linked with a payment line")
# I click on cancel invoice button
res = invoice.invoice_cancel()
# I check if the wizard is correctly instantiated
self.assertFalse(isinstance(res, dict), "wizard action is returned")
# I check if invoice is cancelled
self.assertEqual(invoice.state, 'cancel', 'Invoice isn\'t cancelled')

def test_payment_cancel_invoice(self):
date = fields.Date.today()
invoice = create_simple_invoice(self, date)
workflow.trg_validate(self.uid, 'account.invoice', invoice.id,
'invoice_open', self.cr)
payment_order_create_obj = self.env['payment.order.create']
account_payment_id = self.ref('account_payment.payment_order_1')
payment_order_create = payment_order_create_obj.create(
{'duedate': date,
'populate_results': True})
ctx = self.context.copy()
ctx.update({'active_id': account_payment_id})
res = payment_order_create.with_context(ctx).search_entries()
payment_order_create.entries = res['context']['line_ids']
payment_order_create.with_context(ctx).create_payment()
# I check if created invoice is linked with a payment line
invoice_obj = self.env['account.invoice']
payment_lines = invoice_obj.get_payment_line_linked(invoice)
self.assertTrue(len(payment_lines) > 0,
"Invoice isn't on a payment line")
# I click on cancel invoice button
res = invoice.invoice_cancel()
# I check if the wizard is correctly instantiated
self.assertTrue(isinstance(res, dict), "Not return wizard action")
ctx = res.get('context')
wizard_id = res.get('res_id')
wizard_obj = self.env['validate.invoice.cancel']
wizard = wizard_obj.browse([wizard_id])[0]
# click on force cancel button
wizard.with_context(ctx).validate_cancel()
# I check if invoice is cancelled
self.assertEqual(invoice.state, 'cancel', 'Invoice isn\'t cancelled')
15 changes: 15 additions & 0 deletions account_payment_include_draft_move/views/account_invoice_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="invoice_supplier_form_inherit" model="ir.ui.view">
<field name="name">account.invoice.supplier.form (account_payment_include_draft_move)</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account_default_draft_move.invoice_form_supplier_group_invoice"/>
<field name="arch" type="xml">
<xpath expr="//button[@name='invoice_cancel' and @states='open']" position="attributes">
<attribute name="type">object</attribute>
</xpath>
</field>
</record>
</data>
</openerp>
Loading