[IMP] For manual entries when multicurrency :

a - Validation on the use of the 'Currency' and 'Currency Amount' fields as it is possible to enter one without the other
b - Validation to prevent a Credit amount with a positive 'Currency Amount', or a Debit with a negative 'Currency Amount'

bzr revid: joel.grandguillaume@camptocamp.com-20121026105132-6x0zh3gc823h3b68
This commit is contained in:
Joël Grand-Guillaume 2012-10-26 12:51:32 +02:00
parent eaf53213da
commit 87be45dcd6
1 changed files with 15 additions and 0 deletions

View File

@ -613,12 +613,27 @@ class account_move_line(osv.osv):
return False
return True
def _check_currency_and_amount(self, cr, uid, ids, context=None):
for l in self.browse(cr, uid, ids, context=context):
if (l.currency_id and not l.amount_currency) or (not l.currency_id and l.amount_currency):
return False
return True
def _check_currency_amount(self, cr, uid, ids, context=None):
for l in self.browse(cr, uid, ids, context=context):
if l.amount_currency:
if (l.amount_currency > 0.0 and l.credit > 0.0) or (l.amount_currency < 0.0 and l.debit > 0.0):
return False
return True
_constraints = [
(_check_no_view, 'You cannot create journal items on an account of type view.', ['account_id']),
(_check_no_closed, 'You cannot create journal items on closed account.', ['account_id']),
(_check_company_id, 'Account and Period must belong to the same company.', ['company_id']),
(_check_date, 'The date of your Journal Entry is not in the defined period! You should change the date or remove this constraint from the journal.', ['date']),
(_check_currency, 'The selected account of your Journal Entry forces to provide a secondary currency. You should remove the secondary currency on the account or select a multi-currency view on the journal.', ['currency_id']),
(_check_currency_and_amount, "You cannot create journal items with a secondary currency without recording both 'currency' and 'amount currency' field.", ['currency_id','amount_currency']),
(_check_currency_amount, 'The amount expressed in the secondary currency must be positif when journal item are debit and negatif when journal item are credit.', ['amount_currency']),
]
#TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id