How can we check in method if field is empty. How this code should look correctly.
i hope try to made my point clear.
def method(self, vals):
if vals.get("field" == empty)
use my logic
if not empty use data that was already there.
and if that field is in other model , how can i reach it.
Try this:
def method(self):
if vals.get("field_name", False):
# Code if is not empty
else:
# Code if is empty
You can try following code, in which first check if key is in vals or not. if key is available then check value is set or not.
def method(self, vals):
if vals.has_key('field') and not vals.get('field',False):
print "if logic"
else:
print "else logic"
If field is not empty and field is in other model then you should try with active_model.
You can pass active_model in context from calling method, based on that you can browse record or do other operation.
Ex:
def method(self, vals):
if vals.has_key('field') and not vals.get('field',False):
print "if logic"
else:
model=self._context.get('active_model')
self.env[model].browse(model)
print "else logic"
self.with_context({'active_model':'model'}).method(vals)
Using with_context user can pass context & based on context value you can easily get active model dynamically.
This may help you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With