0
votes

I am setting up default value of analytics_id in account.move.line by below code

class account_move_line(models.Model):
    _inherit = 'account.move.line'
    _name = "account.move.line"

    def _get_default_account(self, cr, uid, context=None):
        obj = self.pool.get('account.move')
        value = obj.browse(cr, uid, uid)
        if  value.move_id.debit>0 or value.move_id.credit<0:
            res = self.pool.get('account.analytic.plan.instance').search(cr, uid, [('code','=','LAL')], context=context)
            return res and res[0] or False

    _defaults = {
        'analytics_id': _get_default_account,
    }

it is working well for me but now i want to set this default value if debit field value is greater then zero OR credit field value less then zero otherwise analytics_id field remain empty.

1
hello tahir you asking but you don't vote when some help you mmmmmmmm not good manCharif DZ
Sorry sir, I'll remember for next time...Tahir Noor
Thank you did you fix this problem!Charif DZ
In account move line two fields debit and credit are there with analytics_id field. I want to set default value something in analytics_id when debit >0 or credit <0Tahir Noor
can you edit you question and post the code of the model and a simple exemple of what you wantCharif DZ

1 Answers

0
votes

Try to use this type of code

res = self.pool.get('account.analytic.plan.instance').search(cr, uid, [('code','=','LAL')], context=context)
if res:    
   br_analytic_plan=self.pool.get('account.analytic.plan.instance').browse(cr,uid,res[0],context=context)
   if ---your Condition---- # You can access For example. br_analytic_plan.amount > 0
       return res[0]

This same logic you can apply to both groups condition (it means under if and else on your current code).

Hope this helps.