Browse Source

🚑 mail_move_message quick create button fix

pull/158/head
KolushovAlexandr 6 years ago
committed by Ivan Yelizariev
parent
commit
3d38f9e343
  1. 2
      mail_move_message/__manifest__.py
  2. 5
      mail_move_message/doc/changelog.rst
  3. 48
      mail_move_message/mail_move_message_models.py
  4. 2
      mail_move_message/mail_move_message_views.xml
  5. 41
      mail_move_message/static/src/js/mail_move_message.js

2
mail_move_message/__manifest__.py

@ -7,7 +7,7 @@
{
'name': 'Mail Relocation',
'version': '11.0.1.0.5',
'version': '11.0.1.0.6',
'author': 'IT-Projects LLC, Ivan Yelizariev, Pavel Romanchenko',
'license': 'LGPL-3',
'category': 'Discuss',

5
mail_move_message/doc/changelog.rst

@ -1,3 +1,8 @@
`1.0.6`
-------
- FIX: Error related to *Create Partner* button on the mail move wizard form.
`1.0.5`
-------

48
mail_move_message/mail_move_message_models.py

@ -202,7 +202,6 @@ class Wizard(models.TransientModel):
for r in self:
if not r.model:
raise exceptions.except_orm(_('Record field is empty!'), _('Select a record for relocation first'))
for r in self:
r.check_access()
if not r.parent_id or not (r.parent_id.model == r.model and
@ -210,7 +209,7 @@ class Wizard(models.TransientModel):
# link with the first message of record
parent = self.env['mail.message'].search([('model', '=', r.model), ('res_id', '=', r.res_id)], order='id', limit=1)
r.parent_id = parent.id or None
r.message_id.move(r.parent_id.id, r.res_id, r.model, r.move_back, r.move_followers, r.message_to_read)
r.message_id.move(r.parent_id.id, r.res_id, r.model, r.move_back, r.move_followers, r.message_to_read, r.partner_id)
if r.model in ['mail.message', 'mail.channel', False]:
return {
@ -246,30 +245,6 @@ class Wizard(models.TransientModel):
self.message_id.unlink()
return {}
@api.model
def create_partner(self, message_id, relation, partner_id, message_name_from, message_email_from):
model = self.env[relation]
message = self.env['mail.message'].browse(message_id)
if not partner_id and message_name_from:
partner_id = self.env['res.partner'].with_context({'update_message_author': True}).create({
'name': message_name_from,
'email': message_email_from
}).id
context = {'partner_id': partner_id}
if model._rec_name:
context.update({'default_%s' % model._rec_name: message.subject})
fields = model.fields_get()
contact_field = False
for n, f in fields.items():
if f['type'] == 'many2one' and f['relation'] == 'res.partner':
contact_field = n
break
if contact_field:
context.update({'default_%s' % contact_field: partner_id})
return context
@api.multi
def read_close(self):
for r in self:
@ -325,18 +300,23 @@ class MailMessage(models.Model):
self.env[model].browse(ids).message_subscribe([f.partner_id.id], [s.id for s in f.subtype_ids])
@api.multi
def move(self, parent_id, res_id, model, move_back, move_followers=False, message_to_read=False):
def move(self, parent_id, res_id, model, move_back, move_followers=False, message_to_read=False, author=False):
for r in self:
r.move_one(parent_id, res_id, model, move_back, move_followers=move_followers, message_to_read=message_to_read)
r.move_one(parent_id, res_id, model, move_back, move_followers=move_followers, message_to_read=message_to_read, author=author)
@api.multi
def move_one(self, parent_id, res_id, model, move_back, move_followers=False, message_to_read=False):
def move_one(self, parent_id, res_id, model, move_back, move_followers=False, message_to_read=False, author=False):
self.ensure_one()
if parent_id == self.id:
# if for any reason method is called to move message with parent
# equal to oneself, we need stop to prevent infinitive loop in
# building message tree
return
if not self.author_id:
self.write({
'author_id': author.id,
})
vals = {}
if move_back:
# clear variables if we move everything back
@ -476,3 +456,13 @@ class ResPartner(models.Model):
if messages:
messages.sudo().write({'author_id': res.id})
return res
@api.model
def default_get(self, default_fields):
contextual_self = self
if 'mail_move_message' in self.env.context and self.env.context['mail_move_message']:
contextual_self = self.with_context(
default_name=self.env.context['message_name_from'] or '',
default_email=self.env.context['message_email_from'] or '',
)
return super(ResPartner, contextual_self).default_get(default_fields)

2
mail_move_message/mail_move_message_views.xml

@ -46,7 +46,7 @@
<field name="partner_id" class="oe_inline"/>
<button string="Create Partner" attrs="{'invisible':[('partner_id','!=',False)]}"
class="oe_highlight oe_inline ml32"
special="quick_create" field="partner_id" context="{'force_email':True,'default_email':message_email_from,'default_name':message_name_from, 'update_message_author':True}" />
special="quick_create" model="res.partner" field="partner_id" context="{'force_email':True,'default_email':message_email_from,'default_name':message_name_from, 'update_message_author':True}" />
</div>
<label for="move_back" attrs="{'invisible':[('message_is_moved','=',False)]}"/>
<div attrs="{'invisible':[('message_is_moved','=',False)]}">

41
mail_move_message/static/src/js/mail_move_message.js

@ -21,7 +21,11 @@ odoo.define('mail_move_message.relocate', function (require) {
var session = require('web.Session');
var FormController = require('web.FormController');
var FormView = require('web.FormView');
var registry = require('web.field_registry');
var FormRenderer = require('web.FormRenderer');
var dialogs = require('web.view_dialogs');
var Dialog = require('web.Dialog');
var relational_fields = require('web.relational_fields');
var Widget = require('web.Widget');
var _t = core._t;
@ -114,4 +118,39 @@ odoo.define('mail_move_message.relocate', function (require) {
return this._super(recordID, values, options)
}
});
FormController.include({
_onButtonClicked: function(event){
if(event.data.attrs.special === 'quick_create' && event.data.attrs.field === 'partner_id'){
var self = this;
var field_data = event.data.record.data;
this.on_saved = function(record, bool) {
var values = [{
id: record.res_id,
display_name: record.data.display_name,
}];
};
var wid = self.initialState.fieldsInfo.form.partner_id.Widget;
var relField = new relational_fields.FieldMany2One(wid,
'partner_id',
self.initialState,
{
mode: 'edit',
viewType: 'form',
});
relField.getParent = function() {
// necessary for correct _trigger_up implementation in mixins.js
return self;
};
var wizard_popup = relField._searchCreatePopup("form", false, {
'message_name_from': field_data.message_name_from && field_data.message_name_from.split('@')[0],
'message_email_from': field_data.message_email_from,
'message_id': field_data.res_id,
'mail_move_message': 1,
});
} else {
this._super.apply(this, arguments);
}
},
});
});
Loading…
Cancel
Save