Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions mass_editing/__openerp__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
##############################################################################
{

Copy link
Copy Markdown

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

"name": "Mass Editing",
"version": "8.0.1.3.0",
"version": "9.0.1.1.0",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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>"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

],
"category": "Tools",
"website": "http://www.serpentcs.com",
Expand All @@ -45,7 +46,7 @@
"security/ir.model.access.csv",
'views/mass_editing_view.xml',
],
'installable': False,
'installable': True,
'application': True,
'auto_install': False,
}
18 changes: 9 additions & 9 deletions mass_editing/models/ir_model_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@
#
##############################################################################

from openerp.osv import orm
import logging
from openerp import models, fields, api, _

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add @api.returns

def search(self, args, offset=0, limit=0, order=None, count=False):
model_domain = []
for domain in args:
if (len(domain) > 2 and
Expand All @@ -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 )
122 changes: 62 additions & 60 deletions mass_editing/models/mass_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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, [])]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.model_id already is your browse record, no need to rebrowse


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]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

found_model_ids.ids

self.model_ids = [(6, 0, model_ids)]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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',
Expand All @@ -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,
Expand All @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add @api.returns

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove record_id

4 changes: 2 additions & 2 deletions mass_editing/views/mass_editing_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
<field name="name" required="1" />
</h1>
<group>
<field name="model_id" required="1"
on_change="onchange_model_id(model_id)" />
<field name="model_id" required="1" />
<field name="model_ids" invisible="1" />
</group>
</div>
Expand Down Expand Up @@ -43,6 +42,7 @@
<field name="field_ids" colspan="4"
nolabel="1"
domain="[('ttype', 'not in', ['reference', 'function']), ('model_id', 'in', model_ids[0][2])]" />

</page>
<page string="Advanced" attrs="{'invisible':[('ref_ir_act_window','=',False)]}">
<group colspan="2" col="2">
Expand Down