diff --git a/account_invoice_constraint_chronology/i18n/account_invoice_constraint_chronology.pot b/account_invoice_constraint_chronology/i18n/account_invoice_constraint_chronology.pot
new file mode 100644
index 00000000..c13b71e5
--- /dev/null
+++ b/account_invoice_constraint_chronology/i18n/account_invoice_constraint_chronology.pot
@@ -0,0 +1,44 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * account_invoice_constraint_chronology
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: Odoo Server 8.0rc1\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2014-08-20 14:51+0000\n"
+"PO-Revision-Date: 2014-08-20 14:51+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_invoice_constraint_chronology
+#: field:account.journal,check_chronology:0
+msgid "Check Chronology"
+msgstr ""
+
+#. module: account_invoice_constraint_chronology
+#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:58
+#, python-format
+msgid "Chronology Error. Please confirm older draft invoices before %s and try again."
+msgstr ""
+
+#. module: account_invoice_constraint_chronology
+#: code:addons/account_invoice_constraint_chronology/model/account_invoice.py:76
+#, python-format
+msgid "Chronology Error. There exist at least one invoice with a date posterior to %s."
+msgstr ""
+
+#. module: account_invoice_constraint_chronology
+#: model:ir.model,name:account_invoice_constraint_chronology.model_account_invoice
+msgid "Invoice"
+msgstr ""
+
+#. module: account_invoice_constraint_chronology
+#: model:ir.model,name:account_invoice_constraint_chronology.model_account_journal
+msgid "Journal"
+msgstr ""
+
diff --git a/account_invoice_constraint_chronology/model/account.py b/account_invoice_constraint_chronology/model/account.py
index 5a03f336..9a7d3633 100644
--- a/account_invoice_constraint_chronology/model/account.py
+++ b/account_invoice_constraint_chronology/model/account.py
@@ -30,15 +30,15 @@
from openerp import models, fields, api
-class account_jounrnal(models.Model):
+class account_journal(models.Model):
_inherit = ['account.journal']
check_chronology = fields.Boolean(string='Check Chronology', default=False)
- @api.multi
- def on_change_type(self, type_journal, context=None):
- value = {}
- if type_journal not in ['sale', 'purchase', 'sale_refund',
- 'purchase_refund']:
- value.update({'check_chronology': False})
- return {'value': value}
+ @api.one
+ @api.onchange('type')
+ def on_change_type(self):
+ if self.type not in ['sale', 'purchase', 'sale_refund',
+ 'purchase_refund']:
+ self.check_chronology = False
+ return True
diff --git a/account_invoice_constraint_chronology/model/account_invoice.py b/account_invoice_constraint_chronology/model/account_invoice.py
index 63f9402c..c9ac805f 100644
--- a/account_invoice_constraint_chronology/model/account_invoice.py
+++ b/account_invoice_constraint_chronology/model/account_invoice.py
@@ -27,8 +27,11 @@
#
#
-from openerp import models, api
+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
class account_invoice(models.Model):
@@ -41,29 +44,40 @@ class account_invoice(models.Model):
if inv.journal_id.check_chronology:
invoices = \
self.search([('state', 'not in',
- ['open', 'paid', 'cancel', 'proforma']),
+ ['open', 'paid', 'cancel', 'proforma',
+ 'proforma2']),
('date_invoice', '!=', False),
('date_invoice', '<', inv.date_invoice),
- ('journal_id', '=', inv.journal_id.id)])
+ ('journal_id', '=', inv.journal_id.id)],
+ limit=1)
if len(invoices) > 0:
- raise models.except_orm(_('Error !'),
- _("Chronology Error!"
- " Please confirm older draft"
- " invoices before %s and"
- " try again.") %
- inv.date_invoice)
+ date_invoice_format = datetime\
+ .strptime(inv.date_invoice,
+ DEFAULT_SERVER_DATE_FORMAT)
+ 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:
invoices = self.search([('state', 'in', ['open', 'paid']),
('date_invoice', '>',
inv.date_invoice),
('journal_id', '=',
- inv.journal_id.id)])
+ inv.journal_id.id)],
+ limit=1)
if len(invoices) > 0:
- raise models.except_orm(_('Error !'),
- _("Chronology Error! There"
- " exist at least one invoice"
- " with a date posterior"
- " to %s.") %
- inv.date_invoice)
+ date_invoice_format = datetime\
+ .strptime(inv.date_invoice,
+ DEFAULT_SERVER_DATE_FORMAT)
+ 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)
return res
diff --git a/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py b/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py
index c51c4e6e..70895831 100644
--- a/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py
+++ b/account_invoice_constraint_chronology/tests/test_account_constraint_chronology.py
@@ -29,34 +29,26 @@
import openerp.tests.common as common
from openerp import workflow
-from openerp.osv import orm
+from openerp import exceptions
from datetime import datetime, timedelta
+from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
DB = common.DB
ADMIN_USER_ID = common.ADMIN_USER_ID
def get_simple_product_id(self):
- return self.registry('product.product').create(self.cr,
- self.uid,
- {'name': 'product_test_01',
- 'lst_price': 2000.00,
- }, context={})
+ 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')
- journal_id = self.registry('account.journal').copy(self.cr,
- self.uid,
- sale_journal_id,
- {},
- context={})
- self.registry('account.journal').write(self.cr,
- self.uid,
- [journal_id],
- {'check_chronology': value},
- context={})
- return journal_id
+ 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):
@@ -70,7 +62,7 @@ def get_simple_account_invoice_line_values(self, product_id):
def create_simple_invoice(self, journal_id, date):
partner_id = self.ref('base.res_partner_2')
- product_id = get_simple_product_id(self)
+ product = get_simple_product_id(self)
return self.env['account.invoice']\
.create({'partner_id': partner_id,
'account_id':
@@ -83,7 +75,7 @@ def create_simple_invoice(self, journal_id, date):
self.ref('account.a_sale'),
'price_unit': 2000.00,
'quantity': 1,
- 'product_id': product_id,
+ 'product_id': product.id,
}
)
],
@@ -94,40 +86,42 @@ class TestAccountConstraintChronology(common.TransactionCase):
def setUp(self):
super(TestAccountConstraintChronology, self).setUp()
+ self.context = self.registry("res.users").context_get(self.cr,
+ self.uid)
def test_invoice_draft(self):
- journal_id = get_journal_check(self, True)
+ journal = get_journal_check(self, True)
today = datetime.now()
yesterday = today - timedelta(days=1)
- date = yesterday.strftime('%Y-%m-%d')
- create_simple_invoice(self, journal_id, date)
- date = today.strftime('%Y-%m-%d')
- invoice_2 = create_simple_invoice(self, journal_id, date)
- self.assertRaises(orm.except_orm, workflow.trg_validate, self.uid,
+ date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT)
+ create_simple_invoice(self, 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)
def test_invoice_validate(self):
- journal_id = get_journal_check(self, True)
+ journal = get_journal_check(self, True)
today = datetime.now()
tomorrow = today + timedelta(days=1)
- date = tomorrow.strftime('%Y-%m-%d')
- invoice = create_simple_invoice(self, journal_id, date)
+ 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 = today.strftime('%Y-%m-%d')
- invoice_2 = create_simple_invoice(self, journal_id, date)
- self.assertRaises(orm.except_orm, workflow.trg_validate, self.uid,
+ 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)
def test_invoice_without_date(self):
- journal_id = get_journal_check(self, True)
+ journal = get_journal_check(self, True)
today = datetime.now()
yesterday = today - timedelta(days=1)
- date = yesterday.strftime('%Y-%m-%d')
- create_simple_invoice(self, journal_id, date)
- invoice_2 = create_simple_invoice(self, journal_id, False)
- self.assertRaises(orm.except_orm, workflow.trg_validate, self.uid,
+ 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)
diff --git a/account_invoice_constraint_chronology/view/account_view.xml b/account_invoice_constraint_chronology/view/account_view.xml
index 892ef81b..1fc86dfe 100644
--- a/account_invoice_constraint_chronology/view/account_view.xml
+++ b/account_invoice_constraint_chronology/view/account_view.xml
@@ -9,10 +9,7 @@
-
- on_change_type(type)
-
-
\ No newline at end of file
+