[IMP] Exclude proforma2 state for draft invoice check on account_invoice_constraint_chronology
[IMP] DEFAULT_SERVER_DATE_FORMAT [IMP] display formatted date with context timezone in exception popup for account_invoice_constraint_chronology addons [ADD] Add context in tests for account_invoice_constraint_chronology addons [IMP] Use exceptions.warning for account_invoice_constraint_chronology addons [IMP] Remove exclamation mark [ADD] Add .pot file for account_invoice_constraint_chronology [IMP] Use .env for account_invoice_constraint_chronology tests [IMP] Use onchange decorator, add white space at end of file, correct ypo mistake for account_invoice_constraint_chronology [IMP] Improve performance
This commit is contained in:
parent
305ed382d8
commit
9a51a1c1cb
@ -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 ""
|
||||||
|
|
@ -30,15 +30,15 @@
|
|||||||
from openerp import models, fields, api
|
from openerp import models, fields, api
|
||||||
|
|
||||||
|
|
||||||
class account_jounrnal(models.Model):
|
class account_journal(models.Model):
|
||||||
_inherit = ['account.journal']
|
_inherit = ['account.journal']
|
||||||
|
|
||||||
check_chronology = fields.Boolean(string='Check Chronology', default=False)
|
check_chronology = fields.Boolean(string='Check Chronology', default=False)
|
||||||
|
|
||||||
@api.multi
|
@api.one
|
||||||
def on_change_type(self, type_journal, context=None):
|
@api.onchange('type')
|
||||||
value = {}
|
def on_change_type(self):
|
||||||
if type_journal not in ['sale', 'purchase', 'sale_refund',
|
if self.type not in ['sale', 'purchase', 'sale_refund',
|
||||||
'purchase_refund']:
|
'purchase_refund']:
|
||||||
value.update({'check_chronology': False})
|
self.check_chronology = False
|
||||||
return {'value': value}
|
return True
|
||||||
|
@ -27,8 +27,11 @@
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
from openerp import models, api
|
from openerp import models, api, fields
|
||||||
from openerp.tools.translate import _
|
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):
|
class account_invoice(models.Model):
|
||||||
@ -41,29 +44,40 @@ class account_invoice(models.Model):
|
|||||||
if inv.journal_id.check_chronology:
|
if inv.journal_id.check_chronology:
|
||||||
invoices = \
|
invoices = \
|
||||||
self.search([('state', 'not in',
|
self.search([('state', 'not in',
|
||||||
['open', 'paid', 'cancel', 'proforma']),
|
['open', 'paid', 'cancel', 'proforma',
|
||||||
|
'proforma2']),
|
||||||
('date_invoice', '!=', False),
|
('date_invoice', '!=', False),
|
||||||
('date_invoice', '<', inv.date_invoice),
|
('date_invoice', '<', inv.date_invoice),
|
||||||
('journal_id', '=', inv.journal_id.id)])
|
('journal_id', '=', inv.journal_id.id)],
|
||||||
|
limit=1)
|
||||||
if len(invoices) > 0:
|
if len(invoices) > 0:
|
||||||
raise models.except_orm(_('Error !'),
|
date_invoice_format = datetime\
|
||||||
_("Chronology Error!"
|
.strptime(inv.date_invoice,
|
||||||
" Please confirm older draft"
|
DEFAULT_SERVER_DATE_FORMAT)
|
||||||
" invoices before %s and"
|
date_invoice_tz = fields\
|
||||||
" try again.") %
|
.Date.context_today(self, date_invoice_format)
|
||||||
inv.date_invoice)
|
raise exceptions.Warning(_("Chronology Error."
|
||||||
|
" Please confirm older draft"
|
||||||
|
" invoices before %s and"
|
||||||
|
" try again.") %
|
||||||
|
date_invoice_tz)
|
||||||
|
|
||||||
if inv.internal_number is False:
|
if inv.internal_number is False:
|
||||||
invoices = self.search([('state', 'in', ['open', 'paid']),
|
invoices = self.search([('state', 'in', ['open', 'paid']),
|
||||||
('date_invoice', '>',
|
('date_invoice', '>',
|
||||||
inv.date_invoice),
|
inv.date_invoice),
|
||||||
('journal_id', '=',
|
('journal_id', '=',
|
||||||
inv.journal_id.id)])
|
inv.journal_id.id)],
|
||||||
|
limit=1)
|
||||||
if len(invoices) > 0:
|
if len(invoices) > 0:
|
||||||
raise models.except_orm(_('Error !'),
|
date_invoice_format = datetime\
|
||||||
_("Chronology Error! There"
|
.strptime(inv.date_invoice,
|
||||||
" exist at least one invoice"
|
DEFAULT_SERVER_DATE_FORMAT)
|
||||||
" with a date posterior"
|
date_invoice_tz = fields\
|
||||||
" to %s.") %
|
.Date.context_today(self, date_invoice_format)
|
||||||
inv.date_invoice)
|
raise exceptions.Warning(_("Chronology Error. There"
|
||||||
|
" exist at least one"
|
||||||
|
" invoice with a date"
|
||||||
|
" posterior to %s.") %
|
||||||
|
date_invoice_tz)
|
||||||
return res
|
return res
|
||||||
|
@ -29,34 +29,26 @@
|
|||||||
|
|
||||||
import openerp.tests.common as common
|
import openerp.tests.common as common
|
||||||
from openerp import workflow
|
from openerp import workflow
|
||||||
from openerp.osv import orm
|
from openerp import exceptions
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
from openerp.tools import DEFAULT_SERVER_DATE_FORMAT
|
||||||
|
|
||||||
DB = common.DB
|
DB = common.DB
|
||||||
ADMIN_USER_ID = common.ADMIN_USER_ID
|
ADMIN_USER_ID = common.ADMIN_USER_ID
|
||||||
|
|
||||||
|
|
||||||
def get_simple_product_id(self):
|
def get_simple_product_id(self):
|
||||||
return self.registry('product.product').create(self.cr,
|
return self.env['product.product'].create({'name': 'product_test_01',
|
||||||
self.uid,
|
'lst_price': 2000.00,
|
||||||
{'name': 'product_test_01',
|
})
|
||||||
'lst_price': 2000.00,
|
|
||||||
}, context={})
|
|
||||||
|
|
||||||
|
|
||||||
def get_journal_check(self, value):
|
def get_journal_check(self, value):
|
||||||
sale_journal_id = self.ref('account.sales_journal')
|
sale_journal_id = self.ref('account.sales_journal')
|
||||||
journal_id = self.registry('account.journal').copy(self.cr,
|
sale_journal = self.env['account.journal'].browse([sale_journal_id])
|
||||||
self.uid,
|
journal = sale_journal.copy()
|
||||||
sale_journal_id,
|
journal.check_chronology = value
|
||||||
{},
|
return journal
|
||||||
context={})
|
|
||||||
self.registry('account.journal').write(self.cr,
|
|
||||||
self.uid,
|
|
||||||
[journal_id],
|
|
||||||
{'check_chronology': value},
|
|
||||||
context={})
|
|
||||||
return journal_id
|
|
||||||
|
|
||||||
|
|
||||||
def get_simple_account_invoice_line_values(self, product_id):
|
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):
|
def create_simple_invoice(self, journal_id, date):
|
||||||
partner_id = self.ref('base.res_partner_2')
|
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']\
|
return self.env['account.invoice']\
|
||||||
.create({'partner_id': partner_id,
|
.create({'partner_id': partner_id,
|
||||||
'account_id':
|
'account_id':
|
||||||
@ -83,7 +75,7 @@ def create_simple_invoice(self, journal_id, date):
|
|||||||
self.ref('account.a_sale'),
|
self.ref('account.a_sale'),
|
||||||
'price_unit': 2000.00,
|
'price_unit': 2000.00,
|
||||||
'quantity': 1,
|
'quantity': 1,
|
||||||
'product_id': product_id,
|
'product_id': product.id,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
@ -94,40 +86,42 @@ class TestAccountConstraintChronology(common.TransactionCase):
|
|||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestAccountConstraintChronology, self).setUp()
|
super(TestAccountConstraintChronology, self).setUp()
|
||||||
|
self.context = self.registry("res.users").context_get(self.cr,
|
||||||
|
self.uid)
|
||||||
|
|
||||||
def test_invoice_draft(self):
|
def test_invoice_draft(self):
|
||||||
journal_id = get_journal_check(self, True)
|
journal = get_journal_check(self, True)
|
||||||
today = datetime.now()
|
today = datetime.now()
|
||||||
yesterday = today - timedelta(days=1)
|
yesterday = today - timedelta(days=1)
|
||||||
date = yesterday.strftime('%Y-%m-%d')
|
date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
create_simple_invoice(self, journal_id, date)
|
create_simple_invoice(self, journal.id, date)
|
||||||
date = today.strftime('%Y-%m-%d')
|
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
invoice_2 = create_simple_invoice(self, journal_id, date)
|
invoice_2 = create_simple_invoice(self, journal.id, date)
|
||||||
self.assertRaises(orm.except_orm, workflow.trg_validate, self.uid,
|
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||||
'account.invoice', invoice_2.id, 'invoice_open',
|
'account.invoice', invoice_2.id, 'invoice_open',
|
||||||
self.cr)
|
self.cr)
|
||||||
|
|
||||||
def test_invoice_validate(self):
|
def test_invoice_validate(self):
|
||||||
journal_id = get_journal_check(self, True)
|
journal = get_journal_check(self, True)
|
||||||
today = datetime.now()
|
today = datetime.now()
|
||||||
tomorrow = today + timedelta(days=1)
|
tomorrow = today + timedelta(days=1)
|
||||||
date = tomorrow.strftime('%Y-%m-%d')
|
date = tomorrow.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
invoice = create_simple_invoice(self, journal_id, date)
|
invoice = create_simple_invoice(self, journal.id, date)
|
||||||
workflow.trg_validate(self.uid, 'account.invoice', invoice.id,
|
workflow.trg_validate(self.uid, 'account.invoice', invoice.id,
|
||||||
'invoice_open', self.cr)
|
'invoice_open', self.cr)
|
||||||
date = today.strftime('%Y-%m-%d')
|
date = today.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
invoice_2 = create_simple_invoice(self, journal_id, date)
|
invoice_2 = create_simple_invoice(self, journal.id, date)
|
||||||
self.assertRaises(orm.except_orm, workflow.trg_validate, self.uid,
|
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||||
'account.invoice', invoice_2.id, 'invoice_open',
|
'account.invoice', invoice_2.id, 'invoice_open',
|
||||||
self.cr)
|
self.cr)
|
||||||
|
|
||||||
def test_invoice_without_date(self):
|
def test_invoice_without_date(self):
|
||||||
journal_id = get_journal_check(self, True)
|
journal = get_journal_check(self, True)
|
||||||
today = datetime.now()
|
today = datetime.now()
|
||||||
yesterday = today - timedelta(days=1)
|
yesterday = today - timedelta(days=1)
|
||||||
date = yesterday.strftime('%Y-%m-%d')
|
date = yesterday.strftime(DEFAULT_SERVER_DATE_FORMAT)
|
||||||
create_simple_invoice(self, journal_id, date)
|
create_simple_invoice(self, journal.id, date)
|
||||||
invoice_2 = create_simple_invoice(self, journal_id, False)
|
invoice_2 = create_simple_invoice(self, journal.id, False)
|
||||||
self.assertRaises(orm.except_orm, workflow.trg_validate, self.uid,
|
self.assertRaises(exceptions.Warning, workflow.trg_validate, self.uid,
|
||||||
'account.invoice', invoice_2.id, 'invoice_open',
|
'account.invoice', invoice_2.id, 'invoice_open',
|
||||||
self.cr)
|
self.cr)
|
||||||
|
@ -9,10 +9,7 @@
|
|||||||
<field name="entry_posted" position="after">
|
<field name="entry_posted" position="after">
|
||||||
<field name="check_chronology" attrs="{'readonly': [('type', 'not in', ['sale', 'purchase', 'sale_refund', 'purchase_refund'])]}"/>
|
<field name="check_chronology" attrs="{'readonly': [('type', 'not in', ['sale', 'purchase', 'sale_refund', 'purchase_refund'])]}"/>
|
||||||
</field>
|
</field>
|
||||||
<xpath expr="//field[@name='type']" position="attributes">
|
|
||||||
<attribute name="on_change">on_change_type(type)</attribute>
|
|
||||||
</xpath>
|
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
</data>
|
</data>
|
||||||
</openerp>
|
</openerp>
|
||||||
|
Loading…
Reference in New Issue
Block a user