Odoo Help


Warning Msg to be shown when Validation?

on 6/27/14, 7:31 AM 1,039 views

Hi I need some series help.In Supplier Paymnets screen i added one more field to show account balance through default on_change function.It works Fine But Now i want to throw an warning msg..when i select Payment Method if balance is negative means it should throw an warning msg but it wont stop the validation..Do help..I tried to do this and taken lots of time to do This but i cant.Here is my code

_.py file

'balance': fields.float('Balance',  readonly=True),

.xml file:

<xpath expr="/form/sheet/group/group/field[@name='date']" position="before">
       <field name="balance" string="Account Balance"/>

on_change function:

def onchange_journal(self, cr, uid, ids, journal_id, line_ids, tax_id, partner_id, date, amount, ttype, company_id, context=None):
        if context is None:
            context = {}
        if not journal_id:
            return False
        journal_pool = self.pool.get('account.journal')
        journal = journal_pool.browse(cr, uid, journal_id, context=context)
        account_id = journal.default_credit_account_id or journal.default_debit_account_id
        tax_id = False
        if account_id and account_id.tax_ids:
            tax_id = account_id.tax_ids[0].id

        vals = {'value':{} }
        if ttype in ('sale', 'purchase'):
            vals = self.onchange_price(cr, uid, ids, line_ids, tax_id, partner_id, context)
            vals['value'].update({'tax_id':tax_id,'amount': amount})
        currency_id = False
        if journal_id:
            print "----->",vals['value']
        if journal.type == 'Cash': <!--this is code for showing balance for account-->
            vals['value'].update({'balance':journal.default_debit_account_id.balance })
            vals['value'].update({'balance':journal.default_debit_account_id.balance })

        if journal.currency:
            currency_id = journal.currency.id
            currency_id = journal.company_id.currency_id.id
        vals['value'].update({'currency_id': currency_id})
        #in case we want to register the payment directly from an invoice, it's confusing to allow to switch the journal
        #without seeing that the amount is expressed in the journal currency, and not in the invoice currency. So to avoid
        #this common mistake, we simply reset the amount to 0 if the currency is not the invoice currency.
        if context.get('payment_expected_currency') and currency_id != context.get('payment_expected_currency'):
            vals['value']['amount'] = 0
            amount = 0
        if partner_id:
            res = self.onchange_partner_id(cr, uid, ids, partner_id, journal_id, amount, currency_id, ttype, date, context)
            for key in res.keys():
        return vals

On 6/27/14, 8:23 AM

Hi vadivel,

just check the balance if it is negative raise the exception.

if journal.default_debit_account_id.balance < 0:

       raise osv.except_osv('Warning', 'msg msg')

       vals['value'].update({'balance':journal.default_debit_account_id.balance })

it may help you

thank you

Thank you so much brother I know you

on 6/27/14, 8:57 AM

Also have to hide cheque_no and cheque_date(customized fields) must be hided when type is in cash

on 6/30/14, 7:05 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 6/27/14, 7:31 AM
Seen: 1039 times
Last updated: 3/16/15, 8:10 AM