update common

This commit is contained in:
ivan deng
2020-09-05 20:36:01 +08:00
parent 386dc82b55
commit 0c9d68ceab
4 changed files with 18 additions and 27 deletions

16
app_common/models/base.py Normal file
View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api, _
class Base(models.AbstractModel):
_inherit = 'base'
@api.model
def _app_get_m2o_default(self, fieldname, domain=[]):
if hasattr(self, fieldname) and self._fields[fieldname].type == 'many2one':
if self._context.get(fieldname) or self._context.get('default_%s' % fieldname):
return self._context.get(fieldname) or self._context.get('default_%s' % fieldname)
else:
rec = self.env[self._fields[fieldname].comodel_name].search(domain, limit=1)
return rec.id if rec else False
return False