Skip to content

Commit

Permalink
[MERGE] forward port branch saas-16 up to 11ff01a
Browse files Browse the repository at this point in the history
  • Loading branch information
KangOl committed Nov 17, 2017
2 parents 49c3f64 + 11ff01a commit 179abc3
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 11 deletions.
10 changes: 6 additions & 4 deletions addons/l10n_be_hr_payroll/data/l10n_be_hr_payroll_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@
<field name="condition_select">none</field>
<field name="amount_select">code</field>
<field name="amount_python_compute">
result = contract.wage + contract.mobile + contract.mobile_plus + contract.internet
if contract.transport_mode == 'company_car':
result += contract.car_atn
result = contract.wage
if contract.internet:
result += 5.0
if contract.mobile:
result += 12.0
</field>
<field name="sequence">20</field>
<field name="appears_on_payslip" eval="False"/>
Expand Down Expand Up @@ -399,7 +401,7 @@ elif salary &lt;= 2461.27:
<field name="category_id" ref="hr_payroll_head_div_impos"/>
<field name="name">ATN Company Car</field>
<field name="code">ATN.CAR</field>
<field name="sequence">15</field>
<field name="sequence">99</field>
<field name="condition_select">python</field>
<field name="condition_python">
result = bool(contract.transport_mode == 'company_car' and contract.car_atn)
Expand Down
7 changes: 3 additions & 4 deletions addons/l10n_be_hr_payroll/models/l10n_be_hr_payroll.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class HrContract(models.Model):
def _compute_wage_with_holidays(self):
for contract in self:
if contract.holidays > 20.0:
yearly_cost = contract.final_yearly_costs * (1.0 - (contract.holidays - 20.0) / 220.0)
yearly_cost = contract.final_yearly_costs * (1.0 - (contract.holidays - 20.0) / 231.0)
contract.wage_with_holidays = contract._get_gross_from_employer_costs(yearly_cost)
else:
contract.wage_with_holidays = contract.wage
Expand Down Expand Up @@ -116,13 +116,12 @@ def _compute_yearly_cost_before_charges(self):
contract.transport_employer_cost
)

@api.depends('yearly_cost_before_charges', 'ucm_insurance', 'social_security_contributions',
@api.depends('yearly_cost_before_charges', 'social_security_contributions',
'social_security_contributions', 'double_holidays', 'warrants_cost', 'meal_voucher_paid_by_employer')
def _compute_final_yearly_costs(self):
for contract in self:
contract.final_yearly_costs = (
contract.yearly_cost_before_charges +
contract.ucm_insurance +
contract.social_security_contributions +
contract.double_holidays +
contract.warrants_cost +
Expand All @@ -133,7 +132,7 @@ def _compute_final_yearly_costs(self):
def _compute_holidays_compensation(self):
for contract in self:
if contract.holidays < 20:
decrease_amount = contract.final_yearly_costs * (20.0 - contract.holidays) / 220.0
decrease_amount = contract.final_yearly_costs * (20.0 - contract.holidays) / 231.0
contract.holidays_compensation = decrease_amount
else:
contract.holidays_compensation = 0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
<span>/ month</span>
</div>
</group>
<group string="Yearly Advantages">
<group string="Yearly Advantages" name="yearly_advantages">
<label for="eco_checks"/>
<div class="o_row">
<field name="eco_checks" nolabel="1"/>
Expand Down
2 changes: 1 addition & 1 deletion addons/l10n_be_hr_payroll_fleet/models/hr_contract.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def _compute_available_cars_amount(self):
@api.depends('name')
def _compute_max_unused_cars(self):
params = self.env['ir.config_parameter'].sudo()
max_unused_cars = params.get_param('l10n_be_hr_payroll_fleet.max_unused_cars', default=3)
max_unused_cars = params.get_param('l10n_be_hr_payroll_fleet.max_unused_cars', default=1000)
for contract in self:
contract.max_unused_cars = int(max_unused_cars)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ def set_values(self):
def get_values(self):
res = super(ResConfigSettings, self).get_values()
params = self.env['ir.config_parameter'].sudo()
res.update(max_unused_cars=int(params.get_param('l10n_be_hr_payroll_fleet.max_unused_cars', default=3)))
res.update(max_unused_cars=int(params.get_param('l10n_be_hr_payroll_fleet.max_unused_cars', default=1000)))
return res
49 changes: 49 additions & 0 deletions addons/mail/static/src/js/form_renderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
odoo.define('mail.form_renderer', function (require) {
"use strict";

var BasicModel = require('web.BasicModel');
var Chatter = require('mail.Chatter');
var FormController = require('web.FormController');
var FormRenderer = require('web.FormRenderer');

/**
Expand Down Expand Up @@ -90,4 +92,51 @@ FormRenderer.include({
},
});

/**
* Include the FormController and BasicModel to update the datapoint on the
* model when a message is posted.
*/
FormController.include({
custom_events: _.extend({}, FormController.prototype.custom_events, {
new_message: '_onNewMessage',
}),

//--------------------------------------------------------------------------
// Handlers
//--------------------------------------------------------------------------

/**
* @private
* @param {OdooEvent} event
* @param {string} event.data.id datapointID
* @param {integer[]} event.data.msgIDs list of message ids
*/
_onNewMessage: function (event) {
this.model.updateMessageIDs(event.data.id, event.data.msgIDs);
},
});

BasicModel.include({

//--------------------------------------------------------------------------
// Public
//--------------------------------------------------------------------------

/**
* Update the message ids on a datapoint.
*
* Note that we directly update the res_ids on the datapoint as the message
* has already been posted ; this change can't be handled 'normally' with
* x2m commands because the change won't be saved as a normal field.
*
* @param {string} id
* @param {integer[]} msgIDs
*/
updateMessageIDs: function (id, msgIDs) {
var element = this.localData[id];
element.res_ids = msgIDs;
element.count = msgIDs.length;
},
});

});
4 changes: 4 additions & 0 deletions addons/mail/static/src/js/thread_field.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ var ThreadField = AbstractField.extend(chat_mixin, {
_onNewMessage: function (message) {
if (message.model === this.model && message.res_id === this.res_id) {
this.msgIDs.unshift(message.id);
this.trigger_up('new_message', {
id: this.value.id,
msgIDs: this.msgIDs,
});
this._fetchAndRenderThread(this.msgIDs);
}
},
Expand Down
80 changes: 80 additions & 0 deletions addons/mail/static/tests/chatter_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,86 @@ QUnit.test('chatter: post, receive and star messages', function (assert) {
});
});


QUnit.test('chatter: post a message and switch in edit mode', function (assert) {
assert.expect(5);

var messages = [];
var bus = new Bus();
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<sheet>' +
'<field name="foo"/>' +
'</sheet>' +
'<div class="oe_chatter">' +
'<field name="message_ids" widget="mail_thread" options="{\'display_log_button\': True}"/>' +
'</div>' +
'</form>',
res_id: 2,
session: {},
mockRPC: function (route, args) {
if (route === "/web/dataset/call_kw/partner/message_get_suggested_recipients") {
return $.when({2: []});
}
return this._super(route, args);
},
intercepts: {
get_messages: function (event) {
event.stopPropagation();
var requested_msgs = _.filter(messages, function (msg) {
return _.contains(event.data.options.ids, msg.id);
});
event.data.callback($.when(requested_msgs));
},
post_message: function (event) {
event.stopPropagation();
messages.push({
attachment_ids: [],
author_id: ["42", "Me"],
body: event.data.message.content,
date: moment(), // now
displayed_author: "Me",
id: 42,
is_note: event.data.message.subtype === 'mail.mt_note',
is_starred: false,
model: 'partner',
res_id: 2,
});
bus.trigger('new_message', {
id: 42,
model: event.data.options.model,
res_id: event.data.options.res_id,
});
},
get_bus: function (event) {
event.stopPropagation();
event.data.callback(bus);
},
},
});

assert.strictEqual(form.$('.o_thread_message').length, 0, "thread should not contain messages");

// send a message
form.$('.o_chatter_button_new_message').click();
form.$('.oe_chatter .o_composer_text_field:first()').val("My first message");
form.$('.oe_chatter .o_composer_button_send').click();
assert.strictEqual(form.$('.o_thread_message').length, 1, "thread should contain a message");
assert.ok(form.$('.o_thread_message:first() .o_thread_message_core').text().indexOf('My first message') >= 0,
"the message's body should be correct");

// switch in edit mode
form.$buttons.find('.o_form_button_edit').click();
assert.strictEqual(form.$('.o_thread_message').length, 1, "thread should contain a message");
assert.ok(form.$('.o_thread_message:first() .o_thread_message_core').text().indexOf('My first message') >= 0,
"the message's body should be correct");

form.destroy();
});

QUnit.test('chatter: Attachment viewer', function (assert) {
assert.expect(6);
this.data.partner.records[0].message_ids = [1];
Expand Down

0 comments on commit 179abc3

Please sign in to comment.