[IMP] base: onchange cleanup

This commit is contained in:
Victor Feyens
2020-02-11 14:48:52 +00:00
parent c1a1e47b52
commit 27650db8bb
2 changed files with 7 additions and 27 deletions
+1 -6
View File
@@ -391,7 +391,7 @@ class IrActionsServer(models.Model):
crud_model_name = fields.Char(related='crud_model_id.model', string='Target Model', readonly=True)
link_field_id = fields.Many2one('ir.model.fields', string='Link using field',
help="Provide the field used to link the newly created record "
"on the record on used by the server action.")
"on the record used by the server action.")
fields_lines = fields.One2many('ir.server.object.lines', 'server_id', string='Value Mapping', copy=True)
groups_id = fields.Many2many('res.groups', 'ir_act_server_group_rel',
'act_id', 'gid', string='Groups')
@@ -411,11 +411,6 @@ class IrActionsServer(models.Model):
@api.onchange('crud_model_id')
def _onchange_crud_model_id(self):
self.link_field_id = False
self.crud_model_name = self.crud_model_id.model
@api.onchange('model_id')
def _onchange_model_id(self):
self.model_name = self.model_id.model
def create_action(self):
""" Create a contextual action for each server action. """
+6 -21
View File
@@ -28,14 +28,8 @@ class Company(models.Model):
def _get_logo(self):
return base64.b64encode(open(os.path.join(tools.config['root_path'], 'addons', 'base', 'static', 'img', 'res_company_logo.png'), 'rb') .read())
@api.model
def _get_euro(self):
return self.env['res.currency.rate'].search([('rate', '=', 1)], limit=1).currency_id
@api.model
def _get_user_currency(self):
currency_id = self.env['res.users'].browse(self._uid).company_id.currency_id
return currency_id or self._get_euro()
def _default_currency_id(self):
return self.env.user.company_id.currency_id
def _get_default_favicon(self, original=False):
img_path = get_resource_path('web', 'static/src/img/favicon.ico')
@@ -74,7 +68,7 @@ class Company(models.Model):
# logo_web: do not store in attachments, since the image is retrieved in SQL for
# performance reasons (see addons/web/controllers/main.py, Binary.company_logo)
logo_web = fields.Binary(compute='_compute_logo_web', store=True, attachment=False)
currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self._get_user_currency())
currency_id = fields.Many2one('res.currency', string='Currency', required=True, default=lambda self: self._default_currency_id())
user_ids = fields.Many2many('res.users', 'res_company_users_rel', 'cid', 'user_id', string='Accepted Users')
street = fields.Char(compute='_compute_address', inverse='_inverse_street')
street2 = fields.Char(compute='_compute_address', inverse='_inverse_street2')
@@ -164,19 +158,10 @@ class Company(models.Model):
if self.state_id.country_id:
self.country_id = self.state_id.country_id
def on_change_country(self, country_id):
# This function is called from account/models/chart_template.py, hence decorated with `multi`.
self.ensure_one()
currency_id = self._get_user_currency()
if country_id:
currency_id = self.env['res.country'].browse(country_id).currency_id
return {'value': {'currency_id': currency_id.id}}
@api.onchange('country_id')
def _onchange_country_id_wrapper(self):
values = self.on_change_country(self.country_id.id)['value']
for fname, value in values.items():
setattr(self, fname, value)
def _onchange_country_id(self):
if self.country_id:
self.currency_id = self.country_id.currency_id
@api.model
def _name_search(self, name, args=None, operator='ilike', limit=100, name_get_uid=None):