Odoo Help

Welcome!

This community 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.

0

Warning Msg to be shown when Validation?

By
vadivel
on 6/27/14, 7:31 AM 705 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"/>
 </xpath>

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:
            vals['value'].update({'journal_type':journal.type})
            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 })
        else:
            vals['value'].update({'balance':journal.default_debit_account_id.balance })

        if journal.currency:
            currency_id = journal.currency.id
        else:
            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():
                vals[key].update(res[key])
        return vals

1
Rajkumar
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')

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

it may help you

thank you

Thank you so much brother I know you

vadivel
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

vadivel
on 6/30/14, 7:05 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

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