-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Mass edit migration #293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Mass edit migration #293
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,10 +21,11 @@ | |
| ############################################################################## | ||
| { | ||
| "name": "Mass Editing", | ||
| "version": "8.0.1.3.0", | ||
| "version": "9.0.1.1.0", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not 9.0.1.0.0? |
||
| "author": "Serpent Consulting Services,Odoo Community Association (OCA)", | ||
| "contributors": [ | ||
| "Oihane Crucelaegui <oihanecrucelaegi@gmail.com>", | ||
| "Florent Thomas <contact@mind-and-go.com>" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create a proper README file following https://github.com/OCA/maintainer-tools/blob/master/CONTRIBUTING.md and https://github.com/OCA/maintainer-tools/blob/master/template/module/README.rst |
||
| ], | ||
| "category": "Tools", | ||
| "website": "http://www.serpentcs.com", | ||
|
|
@@ -45,7 +46,7 @@ | |
| "security/ir.model.access.csv", | ||
| 'views/mass_editing_view.xml', | ||
| ], | ||
| 'installable': False, | ||
| 'installable': True, | ||
| 'application': True, | ||
| 'auto_install': False, | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,15 +20,16 @@ | |
| # | ||
| ############################################################################## | ||
|
|
||
| from openerp.osv import orm | ||
| import logging | ||
| from openerp import models, fields, api, _ | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. most of those imports are unused |
||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
| class IrModelFields(orm.Model): | ||
| class IrModelFields(models.Model): | ||
| _inherit = 'ir.model.fields' | ||
|
|
||
| def search( | ||
| self, cr, uid, args, offset=0, limit=0, order=None, context=None, | ||
| count=False): | ||
| @api.model | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
| def search(self, args, offset=0, limit=0, order=None, count=False): | ||
| model_domain = [] | ||
| for domain in args: | ||
| if (len(domain) > 2 and | ||
|
|
@@ -39,7 +40,6 @@ def search( | |
| ] | ||
| else: | ||
| model_domain.append(domain) | ||
| return super(IrModelFields, self).search( | ||
| cr, uid, model_domain, offset=offset, limit=limit, order=order, | ||
| context=context, count=count | ||
| ) | ||
|
|
||
| return super(IrModelFields, self).search(model_domain, offset=offset, | ||
| limit=limit, order=order, count=count ) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,60 +20,66 @@ | |
| # | ||
| ############################################################################## | ||
|
|
||
| import logging | ||
| from openerp import SUPERUSER_ID | ||
| from openerp.osv import orm, fields | ||
| from openerp.tools.translate import _ | ||
| from openerp import models, fields, api | ||
|
|
||
| _logger = logging.getLogger(__name__) | ||
|
|
||
| class MassObject(orm.Model): | ||
| class MassObject(models.Model): | ||
| _name = "mass.object" | ||
|
|
||
| _columns = { | ||
| 'name': fields.char("Name", size=64, required=True, select=1), | ||
| 'model_id': fields.many2one( | ||
| 'ir.model', 'Model', required=True, select=1), | ||
| 'field_ids': fields.many2many( | ||
| 'ir.model.fields', 'mass_field_rel', 'mass_id', 'field_id', | ||
| 'Fields'), | ||
| 'ref_ir_act_window': fields.many2one( | ||
| 'ir.actions.act_window', 'Sidebar Action', readonly=True, | ||
|
|
||
|
|
||
| name = fields.Char("Name", size=64, required=True, select=1) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. size is not mandatory any more, so remove it where not functionally sensible |
||
| model_id = fields.Many2one(comodel_name='ir.model', string='Model', | ||
| required=True, index=True) | ||
| field_ids = fields.Many2many(comodel_name='ir.model.fields', | ||
| relation='mass_field_rel', column1='mass_id', | ||
| column2='field_id', string='Fields') | ||
| ref_ir_act_window = fields.Many2one(comodel_name='ir.actions.act_window', | ||
| string='Sidebar Action', readonly=True, | ||
| help="Sidebar action to make this template available on records \ | ||
| of the related document model"), | ||
| 'ref_ir_value': fields.many2one( | ||
| 'ir.values', 'Sidebar Button', readonly=True, | ||
| help="Sidebar button to open the sidebar action"), | ||
| 'model_ids': fields.many2many('ir.model', string='Model List') | ||
| } | ||
| of the related document model") | ||
| ref_ir_value = fields.Many2one(comodel_name='ir.values', | ||
| string='Sidebar Button', readonly=True, | ||
| help="Sidebar button to open the sidebar action") | ||
| model_ids = fields.Many2many(comodel_name='ir.model', string='Model List') | ||
|
|
||
|
|
||
| _sql_constraints = [ | ||
| ('name_uniq', 'unique (name)', _('Name must be unique!')), | ||
| ] | ||
|
|
||
| def onchange_model_id(self, cr, uid, ids, model_id, context=None): | ||
| if context is None: | ||
| context = {} | ||
| if not model_id: | ||
| return {'value': {'model_ids': [(6, 0, [])]}} | ||
| model_ids = [model_id] | ||
| model_obj = self.pool['ir.model'] | ||
| active_model_obj = self.pool.get(model_obj.browse( | ||
| cr, uid, model_id).model) | ||
| @api.onchange('model_id') | ||
| def onchange_model_id(self): | ||
| if not self.model_id: | ||
| self.model_ids = [(6, 0, [])] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you don't need this line |
||
| return self | ||
| model_ids = [self.model_id.id] | ||
| model_obj = self.env['ir.model'] | ||
| _logger.debug("MODEL") | ||
| _logger.debug(model_obj.browse(self.model_id.id).model) | ||
| active_model_obj = self.env[model_obj.browse(self.model_id.id).model] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| if active_model_obj._inherits: | ||
| for key, val in active_model_obj._inherits.items(): | ||
| found_model_ids = model_obj.search( | ||
| cr, uid, [('model', '=', key)], context=context) | ||
| model_ids += found_model_ids | ||
| return {'value': {'model_ids': [(6, 0, model_ids)]}} | ||
| found_model_ids = model_obj.search([('model', '=', key)]) | ||
| _logger.debug("found_model_ids" ) | ||
| _logger.debug(found_model_ids) | ||
| model_ids += [m.id for m in found_model_ids] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| self.model_ids = [(6, 0, model_ids)] | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can simply assign a browse record |
||
|
|
||
| def create_action(self, cr, uid, ids, context=None): | ||
| @api.multi | ||
| def create_action(self): | ||
| vals = {} | ||
| action_obj = self.pool['ir.actions.act_window'] | ||
| ir_values_obj = self.pool['ir.values'] | ||
| for data in self.browse(cr, uid, ids, context=context): | ||
| action_obj = self.env['ir.actions.act_window'] | ||
| ir_values_obj = self.env['ir.values'] | ||
| for data in self : | ||
| src_obj = data.model_id.model | ||
| button_name = _('Mass Editing (%s)') % data.name | ||
| vals['ref_ir_act_window'] = action_obj.create( | ||
| cr, SUPERUSER_ID, | ||
| vals['ref_ir_act_window'] = action_obj.sudo().create( | ||
| { | ||
| 'name': button_name, | ||
| 'type': 'ir.actions.act_window', | ||
|
|
@@ -84,10 +90,8 @@ def create_action(self, cr, uid, ids, context=None): | |
| 'view_mode': 'form,tree', | ||
| 'target': 'new', | ||
| 'auto_refresh': 1, | ||
| }, | ||
| context) | ||
| vals['ref_ir_value'] = ir_values_obj.create( | ||
| cr, SUPERUSER_ID, | ||
| }).id | ||
| vals['ref_ir_value'] = ir_values_obj.sudo().create( | ||
| { | ||
| 'name': button_name, | ||
| 'model': src_obj, | ||
|
|
@@ -96,43 +100,41 @@ def create_action(self, cr, uid, ids, context=None): | |
| "ir.actions.act_window," + | ||
| str(vals['ref_ir_act_window'])), | ||
| 'object': True, | ||
| }, | ||
| context) | ||
| }).id | ||
| _logger.debug("VALS") | ||
| _logger.debug(vals) | ||
| self.write( | ||
| cr, uid, ids, | ||
| { | ||
| 'ref_ir_act_window': vals.get('ref_ir_act_window', False), | ||
| 'ref_ir_value': vals.get('ref_ir_value', False), | ||
| }, | ||
| context) | ||
| }) | ||
| return True | ||
|
|
||
| def unlink_action(self, cr, uid, ids, context=None): | ||
| for template in self.browse(cr, uid, ids, context=context): | ||
| @api.multi | ||
| def unlink_action(self): | ||
| for template in self: | ||
| template = self | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line assigns the original browse record again, which fails below for len(self) > 1. remove |
||
| try: | ||
| if template.ref_ir_act_window: | ||
| act_window_obj = self.pool['ir.actions.act_window'] | ||
| act_window_obj.unlink( | ||
| cr, SUPERUSER_ID, [template.ref_ir_act_window.id], | ||
| context=context) | ||
| act_window_obj.sudo().unlink([template.ref_ir_act_window.id]) | ||
| if template.ref_ir_value: | ||
| ir_values_obj = self.pool['ir.values'] | ||
| ir_values_obj.unlink( | ||
| cr, SUPERUSER_ID, template.ref_ir_value.id, | ||
| context=context) | ||
| ir_values_obj.sudo().unlink(template.ref_ir_value.id) | ||
| except: | ||
| raise orm.except_orm( | ||
| _("Warning"), | ||
| _("Deletion of the action record failed.")) | ||
| return True | ||
|
|
||
| @api.multi | ||
| def unlink(self): | ||
| self.unlink_action() | ||
| return super(MassObject, self).unlink() | ||
|
|
||
| def unlink(self, cr, uid, ids, context=None): | ||
| self.unlink_action(cr, uid, ids, context=context) | ||
| return super(MassObject, self).unlink(cr, uid, ids, context=context) | ||
|
|
||
| def copy(self, cr, uid, record_id, default=None, context=None): | ||
| @api.one | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add |
||
| def copy(self, default=None): | ||
| if default is None: | ||
| default = {} | ||
| default.update({'name': '', 'field_ids': []}) | ||
| return super(MassObject, self).copy( | ||
| cr, uid, record_id, default, context=context) | ||
| return super(MassObject, self).copy(record_id, default) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contribution!
Please use simple headers following OCA templates
https://github.com/OCA/maintainer-tools/blob/master/template/module/__openerp__.py#L3