mirror of
https://github.com/OCA/account-financial-tools.git
synced 2025-02-02 12:47:26 +02:00
Merge pull request #457 from acsone/10.0-mig_account_invoice_constraint_chronology_mgs
[MIG][10.0] account_invoice_constraint_chronology
This commit is contained in:
58
account_invoice_constraint_chronology/README.rst
Normal file
58
account_invoice_constraint_chronology/README.rst
Normal file
@@ -0,0 +1,58 @@
|
||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
|
||||
=====================================
|
||||
Account Invoice Constraint Chronology
|
||||
=====================================
|
||||
|
||||
This module helps ensuring the chronology of invoice numbers.
|
||||
|
||||
It prevents the validation of invoices when:
|
||||
|
||||
* there are draft invoices with an anterior date
|
||||
* there are validated invoices with a posterior date
|
||||
|
||||
Configuration
|
||||
=============
|
||||
|
||||
To configure this module, go to the menu *Accounting > Configuration > Journals > Journals* and activate the option *Check Chronology* on the relevant journals. After the installation of the module, this option will be active on *sale* and *sale refund* journals.
|
||||
|
||||
Usage
|
||||
=====
|
||||
|
||||
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
|
||||
:alt: Try me on Runbot
|
||||
:target: https://runbot.odoo-community.org/runbot/92/10.0
|
||||
|
||||
Bug Tracker
|
||||
===========
|
||||
|
||||
Bugs are tracked on `GitHub Issues
|
||||
<https://github.com/OCA/account-financial-tools/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 feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Adrien Peiffer (`Acsone SA/NV <http://www.acsone.eu>`_)
|
||||
* Gilles Gilles <meyomesse.gilles@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.
|
||||
@@ -1,31 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# 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 model
|
||||
from . import tests
|
||||
|
||||
@@ -1,60 +1,15 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
#
|
||||
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
"name": "Account Invoice Constraint Chronology",
|
||||
"version": "8.0.1.0.0",
|
||||
"version": "10.0.1.0.0",
|
||||
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
|
||||
"maintainer": "ACSONE SA/NV",
|
||||
"website": "http://www.acsone.eu",
|
||||
"license": "AGPL-3",
|
||||
"images": [],
|
||||
"category": "Accounting",
|
||||
"depends": ["account"],
|
||||
"description": """
|
||||
Account Invoice Constraint Chronology
|
||||
=====================================
|
||||
|
||||
This module helps ensuring the chronology of invoice numbers.
|
||||
|
||||
It prevents the validation of invoices when:
|
||||
* there are draft invoices with an anterior date
|
||||
* there are validated invoices with a posterior date
|
||||
|
||||
The check can be activated on a per-journal basis
|
||||
(for sale and purchase journals).
|
||||
""",
|
||||
"data": ["view/account_view.xml"],
|
||||
"demo": [],
|
||||
"test": [],
|
||||
"licence": "AGPL-3",
|
||||
'installable': False,
|
||||
"auto_install": False,
|
||||
"application": True,
|
||||
'installable': True,
|
||||
}
|
||||
|
||||
@@ -1,31 +1,2 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# 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
|
||||
from . import account
|
||||
|
||||
@@ -1,44 +1,16 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
#
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, fields, api
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
class account_journal(models.Model):
|
||||
class AccountJournal(models.Model):
|
||||
_inherit = ['account.journal']
|
||||
|
||||
check_chronology = fields.Boolean(string='Check Chronology', default=False)
|
||||
|
||||
@api.one
|
||||
@api.onchange('type')
|
||||
def on_change_type(self):
|
||||
if self.type not in ['sale', 'purchase', 'sale_refund',
|
||||
'purchase_refund']:
|
||||
def _onchange_type(self):
|
||||
if self.type not in ['sale', 'purchase']:
|
||||
self.check_chronology = False
|
||||
return True
|
||||
|
||||
@@ -1,45 +1,18 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
#
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from openerp import models, api, fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
from datetime import datetime
|
||||
from openerp import exceptions
|
||||
from odoo import models, api, fields, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class account_invoice(models.Model):
|
||||
class AccountInvoice(models.Model):
|
||||
_inherit = "account.invoice"
|
||||
|
||||
@api.multi
|
||||
def action_move_create(self):
|
||||
res = super(account_invoice, self).action_move_create()
|
||||
previously_validated = self.filtered(lambda inv: inv.move_name)
|
||||
res = super(AccountInvoice, self).action_move_create()
|
||||
for inv in self:
|
||||
if inv.journal_id.check_chronology:
|
||||
invoices = \
|
||||
@@ -50,34 +23,30 @@ class account_invoice(models.Model):
|
||||
('date_invoice', '<', inv.date_invoice),
|
||||
('journal_id', '=', inv.journal_id.id)],
|
||||
limit=1)
|
||||
if len(invoices) > 0:
|
||||
date_invoice_format = datetime\
|
||||
.strptime(inv.date_invoice,
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
if invoices:
|
||||
date_invoice_format = fields.Date.\
|
||||
from_string(inv.date_invoice)
|
||||
date_invoice_tz = fields\
|
||||
.Date.context_today(self, date_invoice_format)
|
||||
raise exceptions.Warning(_("Chronology Error."
|
||||
" Please confirm older draft"
|
||||
" invoices before %s and"
|
||||
" try again.") %
|
||||
date_invoice_tz)
|
||||
|
||||
if inv.internal_number is False:
|
||||
raise UserError(_("Chronology Error. "
|
||||
"Please confirm older draft "
|
||||
"invoices before %s and try again.")
|
||||
% date_invoice_tz)
|
||||
if inv not in previously_validated:
|
||||
invoices = self.search([('state', 'in', ['open', 'paid']),
|
||||
('date_invoice', '>',
|
||||
inv.date_invoice),
|
||||
('journal_id', '=',
|
||||
inv.journal_id.id)],
|
||||
limit=1)
|
||||
if len(invoices) > 0:
|
||||
date_invoice_format = datetime\
|
||||
.strptime(inv.date_invoice,
|
||||
DEFAULT_SERVER_DATE_FORMAT)
|
||||
|
||||
if invoices:
|
||||
date_invoice_format = fields.Date.\
|
||||
from_string(inv.date_invoice)
|
||||
date_invoice_tz = fields\
|
||||
.Date.context_today(self, date_invoice_format)
|
||||
raise exceptions.Warning(_("Chronology Error. There"
|
||||
" exist at least one"
|
||||
" invoice with a date"
|
||||
" posterior to %s.") %
|
||||
date_invoice_tz)
|
||||
raise UserError(_("Chronology Error. "
|
||||
"There exist at least one invoice "
|
||||
"with a date posterior to %s.") %
|
||||
date_invoice_tz)
|
||||
return res
|
||||
|
||||
@@ -1,30 +1 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# 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_account_constraint_chronology
|
||||
|
||||
@@ -1,124 +1,115 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#
|
||||
#
|
||||
# Authors: Adrien Peiffer
|
||||
# Copyright (c) 2014 Acsone SA/NV (http://www.acsone.eu)
|
||||
# All Rights Reserved
|
||||
#
|
||||
# WARNING: This program as such is intended to be used by professional
|
||||
# programmers who take the whole responsibility of assessing all potential
|
||||
# consequences resulting from its eventual inadequacies and bugs.
|
||||
# End users who are looking for a ready-to-use solution with commercial
|
||||
# guarantees and support are strongly advised to contact a Free Software
|
||||
# Service Company.
|
||||
#
|
||||
# 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/>.
|
||||
#
|
||||
#
|
||||
# Copyright 2015-2017 ACSONE SA/NV (<http://acsone.eu>)
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import openerp.tests.common as common
|
||||
from openerp import workflow
|
||||
from openerp import exceptions
|
||||
import odoo.tests.common as common
|
||||
from odoo.exceptions import UserError
|
||||
from datetime import datetime, timedelta
|
||||
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
|
||||
def get_simple_product_id(self):
|
||||
return self.env['product.product'].create({'name': 'product_test_01',
|
||||
'lst_price': 2000.00,
|
||||
})
|
||||
|
||||
|
||||
def get_journal_check(self, value):
|
||||
sale_journal_id = self.ref('account.sales_journal')
|
||||
sale_journal = self.env['account.journal'].browse([sale_journal_id])
|
||||
journal = sale_journal.copy()
|
||||
journal.check_chronology = value
|
||||
return journal
|
||||
|
||||
|
||||
def get_simple_account_invoice_line_values(self, product_id):
|
||||
return {'name': 'test',
|
||||
'account_id': self.ref('account.a_sale'),
|
||||
'price_unit': 2000.00,
|
||||
'quantity': 1,
|
||||
'product_id': product_id,
|
||||
}
|
||||
|
||||
|
||||
def create_simple_invoice(self, journal_id, date):
|
||||
partner_id = self.ref('base.res_partner_2')
|
||||
product = get_simple_product_id(self)
|
||||
return self.env['account.invoice']\
|
||||
.create({'partner_id': partner_id,
|
||||
'account_id':
|
||||
self.ref('account.a_recv'),
|
||||
'journal_id':
|
||||
journal_id,
|
||||
'date_invoice': date,
|
||||
'invoice_line': [(0, 0, {'name': 'test',
|
||||
'account_id':
|
||||
self.ref('account.a_sale'),
|
||||
'price_unit': 2000.00,
|
||||
'quantity': 1,
|
||||
'product_id': product.id,
|
||||
}
|
||||
)
|
||||
],
|
||||
})
|
||||
from odoo.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||
|
||||
|
||||
class TestAccountConstraintChronology(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestAccountConstraintChronology, self).setUp()
|
||||
self.context = self.registry("res.users").context_get(self.cr,
|
||||
self.uid)
|
||||
|
||||
# Needed to create invoice
|
||||
|
||||
self.account_type1 = self.env['account.account.type'].\
|
||||
create({'name': 'acc type test 1',
|
||||
'type': 'receivable',
|
||||
'include_initial_balance': True})
|
||||
self.account_type2 = self.env['account.account.type']. \
|
||||
create({'name': 'acc type test 2',
|
||||
'type': 'other',
|
||||
'include_initial_balance': True})
|
||||
self.account_account = self.env['account.account'].\
|
||||
create({'name': 'acc test',
|
||||
'code': 'X2020',
|
||||
'user_type_id': self.account_type1.id,
|
||||
'reconcile': True})
|
||||
self.account_account_line = self.env['account.account']. \
|
||||
create({'name': 'acc inv line test',
|
||||
'code': 'X2021',
|
||||
'user_type_id': self.account_type2.id,
|
||||
'reconcile': True})
|
||||
self.sequence = self.env['ir.sequence'].create(
|
||||
{'name': 'Journal Sale',
|
||||
'prefix': 'SALE', 'padding': 6,
|
||||
'company_id': self.env.ref("base.main_company").id})
|
||||
self.account_journal_sale = self.env['account.journal']\
|
||||
.create({'name': 'Sale journal',
|
||||
'code': 'SALE',
|
||||
'type': 'sale',
|
||||
'sequence_id': self.sequence.id})
|
||||
self.product = self.env['product.product'].create(
|
||||
{'name': 'product name'})
|
||||
self.analytic_account = self.env['account.analytic.account'].\
|
||||
create({'name': 'test account'})
|
||||
|
||||
def get_journal_check(self, value):
|
||||
journal = self.account_journal_sale.copy()
|
||||
journal.check_chronology = value
|
||||
return journal
|
||||
|
||||
def create_simple_invoice(self, journal_id, date):
|
||||
invoice = self.env['account.invoice'].create(
|
||||
{'partner_id': self.env.ref('base.res_partner_2').id,
|
||||
'account_id': self.account_account.id,
|
||||
'type': 'in_invoice',
|
||||
'journal_id': journal_id,
|
||||
'date_invoice': date,
|
||||
'state': 'draft',
|
||||
})
|
||||
|
||||
self.env['account.invoice.line'].create(
|
||||
{'product_id': self.product.id,
|
||||
'quantity': 1.0,
|
||||
'price_unit': 100.0,
|
||||
'invoice_id': invoice.id,
|
||||
'name': 'product that cost 100',
|
||||
'account_id': self.account_account_line.id,
|
||||
'account_analytic_id': self.analytic_account.id,
|
||||
})
|
||||
return invoice
|
||||
|
||||
def test_invoice_draft(self):
|
||||
journal = get_journal_check(self, True)
|
||||
journal = self.get_journal_check(True)
|
||||
today = datetime.now()
|
||||
yesterday = today - timedelta(days=1)
|
||||
date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
create_simple_invoice(self, journal.id, date)
|
||||
self.create_simple_invoice(journal.id, date)
|
||||
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice_2 = create_simple_invoice(self, journal.id, date)
|
||||
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||
'account.invoice', invoice_2.id, 'invoice_open',
|
||||
self.cr)
|
||||
invoice_2 = self.create_simple_invoice(journal.id, date)
|
||||
self.assertTrue((invoice_2.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
with self.assertRaises(UserError):
|
||||
invoice_2.action_invoice_open()
|
||||
|
||||
def test_invoice_validate(self):
|
||||
journal = get_journal_check(self, True)
|
||||
journal = self.get_journal_check(True)
|
||||
today = datetime.now()
|
||||
tomorrow = today + timedelta(days=1)
|
||||
date = tomorrow.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice = create_simple_invoice(self, journal.id, date)
|
||||
workflow.trg_validate(self.uid, 'account.invoice', invoice.id,
|
||||
'invoice_open', self.cr)
|
||||
date_tomorrow = tomorrow.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice_1 = self.create_simple_invoice(journal.id, date_tomorrow)
|
||||
self.assertTrue((invoice_1.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
invoice_1.action_invoice_open()
|
||||
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
invoice_2 = create_simple_invoice(self, journal.id, date)
|
||||
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||
'account.invoice', invoice_2.id, 'invoice_open',
|
||||
self.cr)
|
||||
invoice_2 = self.create_simple_invoice(journal.id, date)
|
||||
self.assertTrue((invoice_2.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
with self.assertRaises(UserError):
|
||||
invoice_2.action_invoice_open()
|
||||
|
||||
def test_invoice_without_date(self):
|
||||
journal = get_journal_check(self, True)
|
||||
journal = self.get_journal_check(True)
|
||||
today = datetime.now()
|
||||
yesterday = today - timedelta(days=1)
|
||||
date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||
create_simple_invoice(self, journal.id, date)
|
||||
invoice_2 = create_simple_invoice(self, journal.id, False)
|
||||
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||
'account.invoice', invoice_2.id, 'invoice_open',
|
||||
self.cr)
|
||||
self.create_simple_invoice(journal.id, date)
|
||||
invoice_2 = self.create_simple_invoice(journal.id, False)
|
||||
self.assertTrue((invoice_2.state == 'draft'),
|
||||
"Initial invoice state is not Draft")
|
||||
with self.assertRaises(UserError):
|
||||
invoice_2.action_invoice_open()
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<record id="view_account_journal_form" model="ir.ui.view">
|
||||
<field name="name">account.journal.form (account_constraint_chronology)</field>
|
||||
<field name="model">account.journal</field>
|
||||
<field name="inherit_id" ref="account.view_account_journal_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="entry_posted" position="after">
|
||||
<field name="check_chronology" attrs="{'readonly': [('type', 'not in', ['sale', 'purchase', 'sale_refund', 'purchase_refund'])]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
<!-- Copyright 2015-2017 ACSONE SA/NV
|
||||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
|
||||
<odoo>
|
||||
<record id="view_account_journal_form" model="ir.ui.view">
|
||||
<field name="name">account.journal.form (account_constraint_chronology)</field>
|
||||
<field name="model">account.journal</field>
|
||||
<field name="inherit_id" ref="account.view_account_journal_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="refund_sequence" position="after">
|
||||
<field name="check_chronology" attrs="{'readonly': [('type', 'not in', ['sale', 'purchase'])]}"/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
</odoo>
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
__import__('pkg_resources').declare_namespace(__name__)
|
||||
@@ -0,0 +1 @@
|
||||
__import__('pkg_resources').declare_namespace(__name__)
|
||||
@@ -0,0 +1 @@
|
||||
../../../../account_invoice_constraint_chronology
|
||||
6
setup/account_invoice_constraint_chronology/setup.py
Normal file
6
setup/account_invoice_constraint_chronology/setup.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import setuptools
|
||||
|
||||
setuptools.setup(
|
||||
setup_requires=['setuptools-odoo'],
|
||||
odoo_addon=True,
|
||||
)
|
||||
Reference in New Issue
Block a user