设置字段的默认值取决于odoo中的其他字段 [英] Set default value of field depends on other field in odoo
本文介绍了设置字段的默认值取决于odoo中的其他字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在通过以下代码在account.move.line
中设置analytics_id
的默认值
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,
}
它对我来说运作良好,但是如果debit field value is greater then zero
OR credit field value less then zero
,否则我现在想设置此默认值.否则analytics_id
字段保留为空.
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.
推荐答案
尝试使用这种类型的代码
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]
您可以将这两种逻辑应用于两组条件(这意味着在当前代码的if和else下).
This same logic you can apply to both groups condition (it means under if and else on your current code).
希望这会有所帮助.
这篇关于设置字段的默认值取决于odoo中的其他字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文