summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2018-11-05 17:51:04 +0100
committerChristophe Simonis <chs@odoo.com>2018-11-05 17:51:04 +0100
commitf66a9cdbcf3a9e9cd4afb8abc249ddd23e1b7085 (patch)
treeab6a1f6d6b5a3b97719e528568f84edcdd65138d /addons
parentba239e4cacf468705b012c68fb3b96ba400a0030 (diff)
parentbab5ccfdd7bd2138eb41db325981dc47641678f9 (diff)
[MERGE] forward port branch 11.0 up to bab5ccfdd7b
Diffstat (limited to 'addons')
-rw-r--r--addons/account/models/account_move.py4
-rw-r--r--addons/hr_attendance/models/hr_employee.py1
-rw-r--r--addons/hr_attendance/static/src/js/greeting_message.js35
-rw-r--r--addons/hr_attendance/static/src/js/kiosk_mode.js4
-rw-r--r--addons/hr_attendance/static/tests/hr_attendance_tests.js127
-rw-r--r--addons/product/models/product_attribute.py6
-rw-r--r--addons/purchase_requisition/models/purchase_requisition.py2
-rw-r--r--addons/website_sale/controllers/main.py5
-rw-r--r--addons/website_sale_delivery/controllers/main.py7
-rw-r--r--addons/website_sale_options/controllers/main.py5
10 files changed, 175 insertions, 21 deletions
diff --git a/addons/account/models/account_move.py b/addons/account/models/account_move.py
index e0015b63ad1..cfe33be10ce 100644
--- a/addons/account/models/account_move.py
+++ b/addons/account/models/account_move.py
@@ -267,7 +267,7 @@ class AccountMove(models.Model):
aml = ac_move.line_ids.filtered(lambda x: x.account_id.reconcile or x.account_id.internal_type == 'liquidity')
aml.remove_move_reconcile()
#reconcile together the reconcilable (or the liquidity aml) and their newly created counterpart
- for account in list(set([x.account_id for x in aml])):
+ for account in set([x.account_id for x in aml]):
to_rec = aml.filtered(lambda y: y.account_id == account)
to_rec |= reversed_move.line_ids.filtered(lambda y: y.account_id == account)
#reconciliation will be full, so speed up the computation by using skip_full_reconcile_check in the context
@@ -952,6 +952,8 @@ class AccountMoveLine(models.Model):
ctx = {}
if 'date' in vals:
ctx['date'] = vals['date']
+ elif 'date_maturity' in vals:
+ ctx['date'] = vals['date_maturity']
temp['currency_id'] = bank.currency_id.id
temp['amount_currency'] = bank.company_id.currency_id.with_context(ctx).compute(tax_vals['amount'], bank.currency_id, round=True)
if vals.get('tax_exigible'):
diff --git a/addons/hr_attendance/models/hr_employee.py b/addons/hr_attendance/models/hr_employee.py
index e0cec9681bc..83e44105c00 100644
--- a/addons/hr_attendance/models/hr_employee.py
+++ b/addons/hr_attendance/models/hr_employee.py
@@ -90,6 +90,7 @@ class HrEmployee(models.Model):
action_message = self.env.ref('hr_attendance.hr_attendance_action_greeting_message').read()[0]
action_message['previous_attendance_change_date'] = self.last_attendance_id and (self.last_attendance_id.check_out or self.last_attendance_id.check_in) or False
action_message['employee_name'] = self.name
+ action_message['barcode'] = self.barcode
action_message['next_action'] = next_action
if self.user_id:
diff --git a/addons/hr_attendance/static/src/js/greeting_message.js b/addons/hr_attendance/static/src/js/greeting_message.js
index 8399ae0b14a..edd263dff05 100644
--- a/addons/hr_attendance/static/src/js/greeting_message.js
+++ b/addons/hr_attendance/static/src/js/greeting_message.js
@@ -51,6 +51,7 @@ var GreetingMessage = AbstractAction.extend({
this.attendance.check_in_time = this.attendance.check_in && this.attendance.check_in.format(this.format_time);
this.attendance.check_out_time = this.attendance.check_out && this.attendance.check_out.format(this.format_time);
this.employee_name = action.employee_name;
+ this.attendanceBarcode = action.barcode;
},
start: function() {
@@ -136,21 +137,27 @@ var GreetingMessage = AbstractAction.extend({
_onBarcodeScanned: function(barcode) {
var self = this;
- if (this.return_to_main_menu) { // in case of multiple scans in the greeting message view, delete the timer, a new one will be created.
- clearTimeout(this.return_to_main_menu);
+ if (this.attendanceBarcode !== barcode){
+ if (this.return_to_main_menu) { // in case of multiple scans in the greeting message view, delete the timer, a new one will be created.
+ clearTimeout(this.return_to_main_menu);
+ }
+ core.bus.off('barcode_scanned', this, this._onBarcodeScanned);
+ this._rpc({
+ model: 'hr.employee',
+ method: 'attendance_scan',
+ args: [barcode, ],
+ })
+ .then(function (result) {
+ if (result.action) {
+ self.do_action(result.action);
+ } else if (result.warning) {
+ self.do_warn(result.warning);
+ setTimeout( function() { self.do_action(self.next_action, {clear_breadcrumbs: true}); }, 5000);
+ }
+ }, function () {
+ setTimeout( function() { self.do_action(self.next_action, {clear_breadcrumbs: true}); }, 5000);
+ });
}
- this._rpc({
- model: 'hr.employee',
- method: 'attendance_scan',
- args: [barcode, ],
- })
- .then(function (result) {
- if (result.action) {
- self.do_action(result.action);
- } else if (result.warning) {
- self.do_warn(result.warning);
- }
- });
},
destroy: function () {
diff --git a/addons/hr_attendance/static/src/js/kiosk_mode.js b/addons/hr_attendance/static/src/js/kiosk_mode.js
index 6046b9bdbb2..b457dc64e97 100644
--- a/addons/hr_attendance/static/src/js/kiosk_mode.js
+++ b/addons/hr_attendance/static/src/js/kiosk_mode.js
@@ -36,6 +36,7 @@ var KioskMode = AbstractAction.extend({
_onBarcodeScanned: function(barcode) {
var self = this;
+ core.bus.off('barcode_scanned', this, this._onBarcodeScanned);
this._rpc({
model: 'hr.employee',
method: 'attendance_scan',
@@ -46,7 +47,10 @@ var KioskMode = AbstractAction.extend({
self.do_action(result.action);
} else if (result.warning) {
self.do_warn(result.warning);
+ core.bus.on('barcode_scanned', self, self._onBarcodeScanned);
}
+ }, function () {
+ core.bus.on('barcode_scanned', self, self._onBarcodeScanned);
});
},
diff --git a/addons/hr_attendance/static/tests/hr_attendance_tests.js b/addons/hr_attendance/static/tests/hr_attendance_tests.js
index 0f09069048c..750fc6318d2 100644
--- a/addons/hr_attendance/static/tests/hr_attendance_tests.js
+++ b/addons/hr_attendance/static/tests/hr_attendance_tests.js
@@ -2,8 +2,11 @@ odoo.define('hr_attendance.tests', function (require) {
"use strict";
var testUtils = require('web.test_utils');
+var core = require('web.core');
var MyAttendances = require('hr_attendance.my_attendances');
+var KioskMode = require('hr_attendance.kiosk_mode');
+var GreetingMessage = require('hr_attendance.greeting_message');
QUnit.module('HR Attendance', {
@@ -19,12 +22,30 @@ QUnit.module('HR Attendance', {
default: 1,
},
user_id: {string: 'user ID', type: 'integer'},
+ barcode: {string:'barcode', type: 'integer'},
},
records: [{
id: 1,
name: "Employee A",
attendance_state: 1,
user_id: 1,
+ barcode: 1,
+ },
+ {
+ id: 2,
+ name: "Employee B",
+ attendance_state: 'checked_out',
+ user_id: 2,
+ barcode: 2,
+ }],
+ },
+ 'res.company': {
+ fields: {
+ name: {string: 'Name', type: 'char'},
+ },
+ records: [{
+ id: 1,
+ name: "Company A",
}],
},
};
@@ -51,6 +72,112 @@ QUnit.module('HR Attendance', {
clientAction.destroy();
});
+ QUnit.test('Attendance Kiosk Mode Test', function (assert) {
+ assert.expect(2);
+
+ var $target = $('#qunit-fixture');
+ var self = this;
+ var rpcCount = 0;
+ var clientAction = new KioskMode(null);
+ testUtils.addMockEnvironment(clientAction, {
+ data: this.data,
+ session: {
+ uid: 1,
+ company_id: 1,
+ },
+ mockRPC: function(route, args) {
+ if (args.method === 'attendance_scan' && args.model === 'hr.employee') {
+
+ rpcCount++;
+ return $.when(self.data['hr.employee'].records[0]);
+ }
+ return this._super(route, args);
+ },
+ });
+ clientAction.appendTo($target);
+ core.bus.trigger('barcode_scanned', 1);
+ core.bus.trigger('barcode_scanned', 1);
+ assert.strictEqual(rpcCount, 1, 'RPC call should have been done only once.');
+
+ core.bus.trigger('barcode_scanned', 2);
+ assert.strictEqual(rpcCount, 1, 'RPC call should have been done only once.');
+
+ clientAction.destroy();
+ });
+
+ QUnit.test('Attendance Greeting Message Test', function (assert) {
+ assert.expect(10);
+
+ var $target = $('#qunit-fixture');
+ var self = this;
+ var rpcCount = 0;
+
+ var clientActions = [];
+ function createGreetingMessage (target, barcode){
+ var action = {
+ attendance: {
+ check_in: "2018-09-20 13:41:13",
+ employee_id: [barcode],
+ },
+ next_action: "hr_attendance.hr_attendance_action_kiosk_mode",
+ barcode: barcode,
+ }
+ var clientAction = new GreetingMessage(null, action);
+ testUtils.addMockEnvironment(clientAction, {
+ data: self.data,
+ session: {
+ uid: 1,
+ company_id: 1,
+ },
+ mockRPC: function(route, args) {
+ if (args.method === 'attendance_scan' && args.model === 'hr.employee') {
+ rpcCount++;
+ action.attendance.employee_id = [args.args[0], 'Employee'];
+ /*
+ if rpc have been made, a new instance is created to simulate the same behaviour
+ as functional flow.
+ */
+ createGreetingMessage (target, args.args[0]);
+ return $.when({action: action});
+ }
+ return this._super(route, args);
+ },
+ });
+ clientAction.appendTo(target);
+
+ clientActions.push(clientAction);
+ };
+
+ // init - mock coming from kiosk
+ createGreetingMessage ($target, 1);
+ assert.strictEqual(clientActions.length, 1, 'Number of clientAction must = 1.');
+
+ core.bus.trigger('barcode_scanned', 1);
+ /*
+ As action is given when instantiate GreetingMessage, we simulate that we come from the KioskMode
+ So rescanning the same barcode won't lead to another RPC.
+ */
+ assert.strictEqual(clientActions.length, 1, 'Number of clientActions must = 1.');
+ assert.strictEqual(rpcCount, 0, 'RPC call should not have been done.');
+
+ core.bus.trigger('barcode_scanned', 2);
+ assert.strictEqual(clientActions.length, 2, 'Number of clientActions must = 2.');
+ assert.strictEqual(rpcCount, 1, 'RPC call should have been done only once.');
+ core.bus.trigger('barcode_scanned', 2);
+ assert.strictEqual(clientActions.length, 2, 'Number of clientActions must = 2.');
+ assert.strictEqual(rpcCount, 1, 'RPC call should have been done only once.');
+
+ core.bus.trigger('barcode_scanned', 1);
+ assert.strictEqual(clientActions.length, 3, 'Number of clientActions must = 3.');
+ core.bus.trigger('barcode_scanned', 1);
+ assert.strictEqual(clientActions.length, 3, 'Number of clientActions must = 3.');
+ assert.strictEqual(rpcCount, 2, 'RPC call should have been done only twice.');
+
+ _.each(clientActions, function(clientAction) {
+ clientAction.destroy();
+ });
+ });
+
});
});
diff --git a/addons/product/models/product_attribute.py b/addons/product/models/product_attribute.py
index 0b319b6d8ce..ee9c7d4a95d 100644
--- a/addons/product/models/product_attribute.py
+++ b/addons/product/models/product_attribute.py
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo.osv import expression
from odoo import api, fields, models, _
from odoo.addons import decimal_precision as dp
from odoo.exceptions import UserError, ValidationError
@@ -108,6 +109,7 @@ class ProductAttributeLine(models.Model):
# search on a m2o and one on a m2m, probably this will quickly become
# difficult to compute - check if performance optimization is required
if name and operator in ('=', 'ilike', '=ilike', 'like', '=like'):
- args = expression.AND([['|', ('attribute_id', operator, name), ('value_ids', operator, name)], args])
- return self.search(args, limit=limit).name_get()
+ args = args or []
+ domain = ['|', ('attribute_id', operator, name), ('value_ids', operator, name)]
+ return self.search(expression.AND([domain, args]), limit=limit).name_get()
return super(ProductAttributeLine, self).name_search(name=name, args=args, operator=operator, limit=limit)
diff --git a/addons/purchase_requisition/models/purchase_requisition.py b/addons/purchase_requisition/models/purchase_requisition.py
index af375ba011b..ce0cb5e2d2a 100644
--- a/addons/purchase_requisition/models/purchase_requisition.py
+++ b/addons/purchase_requisition/models/purchase_requisition.py
@@ -310,7 +310,7 @@ class PurchaseOrder(models.Model):
self.partner_id = partner.id
self.fiscal_position_id = fpos.id
- self.payment_term_id = payment_term.id,
+ self.payment_term_id = payment_term.id
self.company_id = requisition.company_id.id
self.currency_id = requisition.currency_id.id
if not self.origin or requisition.name not in self.origin.split(', '):
diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py
index b7a4421b865..749a7956767 100644
--- a/addons/website_sale/controllers/main.py
+++ b/addons/website_sale/controllers/main.py
@@ -356,6 +356,9 @@ class WebsiteSale(http.Controller):
revive: Revival method when abandoned cart. Can be 'merge' or 'squash'
"""
order = request.website.sale_get_order()
+ if order and order.state != 'draft':
+ request.session['sale_order_id'] = None
+ order = request.website.sale_get_order()
values = {}
if access_token:
abandoned_order = request.env['sale.order'].sudo().search([('access_token', '=', access_token)], limit=1)
@@ -398,7 +401,7 @@ class WebsiteSale(http.Controller):
@http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True, csrf=False)
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
- sale_order = request.website.sale_get_order(force_create=1)
+ sale_order = request.website.sale_get_order(force_create=True)
if sale_order.state != 'draft':
request.session['sale_order_id'] = None
sale_order = request.website.sale_get_order(force_create=True)
diff --git a/addons/website_sale_delivery/controllers/main.py b/addons/website_sale_delivery/controllers/main.py
index a7b7d41998b..5eae72e2bbb 100644
--- a/addons/website_sale_delivery/controllers/main.py
+++ b/addons/website_sale_delivery/controllers/main.py
@@ -58,9 +58,14 @@ class WebsiteSaleDelivery(WebsiteSale):
def _update_website_sale_delivery(self, **post):
order = request.website.sale_get_order()
carrier_id = int(post['carrier_id'])
- currency = order.currency_id
if order:
order._check_carrier_quotation(force_carrier_id=carrier_id)
+ return self._update_website_sale_delivery_return(order, **post)
+
+ def _update_website_sale_delivery_return(self, order, **post):
+ carrier_id = int(post['carrier_id'])
+ currency = order.currency_id
+ if order:
return {'status': order.delivery_rating_success,
'error_message': order.delivery_message,
'carrier_id': carrier_id,
diff --git a/addons/website_sale_options/controllers/main.py b/addons/website_sale_options/controllers/main.py
index 1f151f0dcf7..9f677bbcfbb 100644
--- a/addons/website_sale_options/controllers/main.py
+++ b/addons/website_sale_options/controllers/main.py
@@ -19,7 +19,10 @@ class WebsiteSaleOptions(WebsiteSale):
if lang:
request.website = request.website.with_context(lang=lang)
- order = request.website.sale_get_order(force_create=1)
+ order = request.website.sale_get_order(force_create=True)
+ if order.state != 'draft':
+ request.session['sale_order_id'] = None
+ order = request.website.sale_get_order(force_create=True)
product = request.env['product.product'].browse(int(product_id))
option_ids = product.optional_product_ids.mapped('product_variant_ids').ids