summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-04-08 17:45:00 +0200
committerChristophe Simonis <chs@odoo.com>2019-04-08 17:45:00 +0200
commit4c61621efbb079a4298db99d5c0b30b90e072bb9 (patch)
treef6734b44a1ea45826be4f7a14191f7aaa3b75846
parentb3d4c2d178bb3dbb9875271082bc36a80076e649 (diff)
parent9a7e3c8b4986fcfecf3699a194e45f5ec94bde6c (diff)
[MERGE] forward port branch 11.0 up to 9a7e3c8b498
-rw-r--r--addons/account/models/account_invoice.py28
-rw-r--r--addons/account/models/reconciliation_widget.py2
-rw-r--r--addons/account/views/account_view.xml3
-rw-r--r--addons/account_asset/views/account_asset_views.xml2
-rw-r--r--addons/account_payment/views/account_portal_templates.xml2
-rw-r--r--addons/base_address_city/models/res_partner.py4
-rw-r--r--addons/http_routing/models/ir_http.py6
-rw-r--r--addons/l10n_pl/data/account_tax_data.xml2
-rw-r--r--addons/mass_mailing/wizard/mail_compose_message.py3
-rw-r--r--addons/point_of_sale/models/pos_order.py8
-rw-r--r--addons/point_of_sale/static/src/js/chrome.js3
-rw-r--r--addons/point_of_sale/static/src/js/models.js15
-rw-r--r--addons/product/models/product.py6
-rw-r--r--addons/product/views/product_views.xml3
-rw-r--r--addons/purchase/models/purchase.py4
-rw-r--r--addons/stock/models/stock_inventory.py12
-rw-r--r--addons/stock/wizard/stock_immediate_transfer.py2
-rw-r--r--addons/stock_account/models/stock.py2
-rw-r--r--addons/survey/static/src/js/survey.js2
-rw-r--r--addons/web_editor/static/src/js/editor/rte.summernote.js5
-rw-r--r--addons/web_editor/static/src/js/widgets/widgets.js6
-rw-r--r--addons/website/models/ir_qweb.py9
-rw-r--r--addons/website/tests/test_qweb.py122
-rw-r--r--doc/cla/individual/bletourmy.md11
-rw-r--r--doc/cla/individual/matthewdwatkins.md11
-rw-r--r--odoo/addons/base/models/ir_module.py9
-rw-r--r--odoo/fields.py6
27 files changed, 242 insertions, 46 deletions
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index b7c1985719f..25bc91f7e8f 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -99,6 +99,11 @@ class AccountInvoice(models.Model):
def _get_reference_type(self):
return [('none', _('Free Reference'))]
+ def _get_aml_for_amount_residual(self):
+ """ Get the aml to consider to compute the amount residual of invoices """
+ self.ensure_one()
+ return self.sudo().move_id.line_ids.filtered(lambda l: l.account_id == self.account_id)
+
@api.one
@api.depends(
'state', 'currency_id', 'invoice_line_ids.price_subtotal',
@@ -108,14 +113,13 @@ class AccountInvoice(models.Model):
residual = 0.0
residual_company_signed = 0.0
sign = self.type in ['in_refund', 'out_refund'] and -1 or 1
- for line in self.sudo().move_id.line_ids:
- if line.account_id == self.account_id:
- residual_company_signed += line.amount_residual
- if line.currency_id == self.currency_id:
- residual += line.amount_residual_currency if line.currency_id else line.amount_residual
- else:
- from_currency = (line.currency_id and line.currency_id.with_context(date=line.date)) or line.company_id.currency_id.with_context(date=line.date)
- residual += from_currency.compute(line.amount_residual, self.currency_id)
+ for line in self._get_aml_for_amount_residual():
+ residual_company_signed += line.amount_residual
+ if line.currency_id == self.currency_id:
+ residual += line.amount_residual_currency if line.currency_id else line.amount_residual
+ else:
+ from_currency = (line.currency_id and line.currency_id.with_context(date=line.date)) or line.company_id.currency_id.with_context(date=line.date)
+ residual += from_currency.compute(line.amount_residual, self.currency_id)
self.residual_company_signed = abs(residual_company_signed) * sign
self.residual_signed = abs(residual) * sign
self.residual = abs(residual)
@@ -930,11 +934,17 @@ class AccountInvoice(models.Model):
return tax_grouped
@api.multi
+ def _get_aml_for_register_payment(self):
+ """ Get the aml to consider to reconcile in register payment """
+ self.ensure_one()
+ return self.move_id.line_ids.filtered(lambda r: not r.reconciled and r.account_id.internal_type in ('payable', 'receivable'))
+
+ @api.multi
def register_payment(self, payment_line, writeoff_acc_id=False, writeoff_journal_id=False):
""" Reconcile payable/receivable lines from the invoice with payment_line """
line_to_reconcile = self.env['account.move.line']
for inv in self:
- line_to_reconcile += inv.move_id.line_ids.filtered(lambda r: not r.reconciled and r.account_id.internal_type in ('payable', 'receivable'))
+ line_to_reconcile += inv._get_aml_for_register_payment()
return (line_to_reconcile + payment_line).reconcile(writeoff_acc_id, writeoff_journal_id)
@api.multi
diff --git a/addons/account/models/reconciliation_widget.py b/addons/account/models/reconciliation_widget.py
index 246f7268478..a65e6bc5872 100644
--- a/addons/account/models/reconciliation_widget.py
+++ b/addons/account/models/reconciliation_widget.py
@@ -682,7 +682,7 @@ class AccountReconciliation(models.AbstractModel):
liquidity_amt_clause = currency and '%(amount)s::numeric' or 'abs(%(amount)s::numeric)'
sql_query = st_line._get_common_sql_query(excluded_ids=excluded_ids) + \
" AND (" + field + " = %(amount)s::numeric OR (acc.internal_type = 'liquidity' AND " + liquidity_field + " = " + liquidity_amt_clause + ")) \
- ORDER BY date_maturity desc, aml.id desc LIMIT 1"
+ ORDER BY date_maturity asc, aml.id desc LIMIT 1"
self.env.cr.execute(sql_query, params)
results = self.env.cr.fetchone()
if results:
diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml
index 5f6644a892a..00cac13bdb4 100644
--- a/addons/account/views/account_view.xml
+++ b/addons/account/views/account_view.xml
@@ -1199,6 +1199,7 @@
<field name="invoice_id" attrs="{'invisible': [('invoice_id','=',False)]}"/>
</group>
<group string="Dates">
+ <field name="date"/>
<field name="date_maturity"/>
</group>
@@ -1206,7 +1207,7 @@
<field name="tax_line_id" readonly="1" attrs="{'invisible': [('tax_line_id','=',False)]}"/>
<field name="tax_ids" widget="many2many_tags" readonly="1" attrs="{'invisible': [('tax_ids','=',[])]}"/>
</group>
- <group string="Matching" attrs="{'invisible':[('full_reconcile_id','=',False)]}">
+ <group string="Matching" attrs="{'invisible':[('full_reconcile_id','=',False), ('matched_debit_ids', '=', []),('matched_credit_ids', '=', [])]}">
<label for="full_reconcile_id"/>
<div>
<field name="full_reconcile_id"/>
diff --git a/addons/account_asset/views/account_asset_views.xml b/addons/account_asset/views/account_asset_views.xml
index 595912687d1..3d00d2dd0d6 100644
--- a/addons/account_asset/views/account_asset_views.xml
+++ b/addons/account_asset/views/account_asset_views.xml
@@ -178,7 +178,7 @@
<field name="salvage_value" widget="monetary" options="{'currency_field': 'currency_id'}" attrs="{'invisible': [('type','=','sale')]}"/>
<field name="value_residual" widget="monetary" options="{'currency_field': 'currency_id'}"/>
<field name="partner_id" string="Vendor" domain="[('supplier', '=', True)]"/>
- <field name="invoice_id" string="Invoice" options="{'no_create': True}"/>
+ <field name="invoice_id" string="Invoice" attrs="{'readonly': [('state', '!=', 'draft')]}" options="{'no_create': True}"/>
</group>
</group>
<notebook colspan="4">
diff --git a/addons/account_payment/views/account_portal_templates.xml b/addons/account_payment/views/account_portal_templates.xml
index 7383a5cf303..ec7de0936d7 100644
--- a/addons/account_payment/views/account_portal_templates.xml
+++ b/addons/account_payment/views/account_portal_templates.xml
@@ -71,7 +71,7 @@
<h4 class="mb24">Pay with</h4>
<t t-call="payment.payment_tokens_list">
<t t-set="mode" t-value="'payment'"/>
- <t t-set="partner_id" t-value="invoice.partner_id.id"/>
+ <t t-set="partner_id" t-value="request.env.user.partner_id.id"/>
<t t-set="success_url" t-value="'/my/invoices/%s%s' % (invoice.id, ('?access_token=%s' % (access_token)) if access_token else '')"/>
<t t-set="error_url" t-value="'/my/invoices/%s%s' % (invoice.id, ('?access_token=%s' % (access_token)) if access_token else '')"/>
<t t-set="access_token" t-value="access_token or ''"/>
diff --git a/addons/base_address_city/models/res_partner.py b/addons/base_address_city/models/res_partner.py
index f8f01119e7d..c9ee67f2c7b 100644
--- a/addons/base_address_city/models/res_partner.py
+++ b/addons/base_address_city/models/res_partner.py
@@ -31,13 +31,13 @@ class Partner(models.Model):
replacement_xml = """
<div>
<field name="country_enforce_cities" invisible="1"/>
- <field name='city' placeholder="%(placeholder)s"
+ <field name='city' placeholder="%(placeholder)s" class="o_address_city"
attrs="{
'invisible': [('country_enforce_cities', '=', True), ('city_id', '!=', False)],
'readonly': [('type', '=', 'contact')%(parent_condition)s]
}"
/>
- <field name='city_id' placeholder="%(placeholder)s" string="%(placeholder)s"
+ <field name='city_id' placeholder="%(placeholder)s" string="%(placeholder)s" class="o_address_city"
context="{'default_country_id': country_id,
'default_name': city,
'default_zipcode': zip,
diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py
index 5a9343e03ff..c68eb681cca 100644
--- a/addons/http_routing/models/ir_http.py
+++ b/addons/http_routing/models/ir_http.py
@@ -164,7 +164,7 @@ def is_multilang_url(local_url, langs=None):
local_url = '/'.join(spath)
try:
# Try to match an endpoint in werkzeug's routing table
- url = local_url.split('?')
+ url = local_url.partition('#')[0].split('?')
path = url[0]
query_string = url[1] if len(url) > 1 else None
router = request.httprequest.app.get_db_router(request.db).bind('')
@@ -173,6 +173,10 @@ def is_multilang_url(local_url, langs=None):
return (func.routing.get('website', False) and
func.routing.get('multilang', func.routing['type'] == 'http'))
except werkzeug.exceptions.NotFound:
+ # Consider /static/ files as non-multilang
+ static_index = path.find('/static/', 1)
+ if static_index != -1 and static_index == path.find('/', 1):
+ return False
return True
except Exception as e:
return False
diff --git a/addons/l10n_pl/data/account_tax_data.xml b/addons/l10n_pl/data/account_tax_data.xml
index f29294b36aa..973d05ff7b6 100644
--- a/addons/l10n_pl/data/account_tax_data.xml
+++ b/addons/l10n_pl/data/account_tax_data.xml
@@ -256,7 +256,7 @@
<field name="type_tax_use">sale</field>
<field name="refund_account_id" ref="chart22030200"/>
<field name="account_id" ref="chart22030200"/>
- <field name="tag_ids" eval="[ref('l10n_pl.tag_pl_08'), ref('l10n_pl.tag_pl_29')]"/>
+ <field name="tag_ids" eval="[(6,0,[ref('l10n_pl.tag_pl_08'), ref('l10n_pl.tag_pl_29')])]"/>
<field name="tax_group_id" ref="tax_group_vat_7"/>
</record>
diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py
index 8f28f6b5244..6545a239bdb 100644
--- a/addons/mass_mailing/wizard/mail_compose_message.py
+++ b/addons/mass_mailing/wizard/mail_compose_message.py
@@ -62,7 +62,8 @@ class MailComposeMessage(models.TransientModel):
if mail_values.get('email_to'):
recips = tools.email_split(mail_values['email_to'])
else:
- recips = tools.email_split(partners_email.get(res_id))
+ partner_id = (mail_values.get('recipient_ids') or [(False, '')])[0][1]
+ recips = tools.email_split(partners_email.get(partner_id))
mail_to = recips[0].lower() if recips else False
if (blacklist and mail_to in blacklist) or (seen_list and mail_to in seen_list):
# prevent sending to blocked addresses that were included by mistake
diff --git a/addons/point_of_sale/models/pos_order.py b/addons/point_of_sale/models/pos_order.py
index a30f33228f7..becca5a266a 100644
--- a/addons/point_of_sale/models/pos_order.py
+++ b/addons/point_of_sale/models/pos_order.py
@@ -506,7 +506,13 @@ class PosOrder(models.Model):
'|',
('credit_move_id.move_id', '=', move.id),
('debit_move_id.move_id', '=', move.id)], limit=1)
- partial_reconcile.create_tax_cash_basis_entry(cash_basis_percentage_before_rec[move])
+ if partial_reconcile:
+ # In case none of the order debit move lines have been reconciled
+ # there is no need to create the tax cash basis entries as nothing has been reconciled
+ # a known case is when the the bank journal credit account is set to a receivable account,
+ # which has as effect to fully reconcile the payment line with its counterpart,
+ # leaving no payment lines to reconcile with the order debit lines.
+ partial_reconcile.create_tax_cash_basis_entry(cash_basis_percentage_before_rec[move])
def _filtered_for_reconciliation(self):
filter_states = ['invoiced', 'done']
diff --git a/addons/point_of_sale/static/src/js/chrome.js b/addons/point_of_sale/static/src/js/chrome.js
index 5099e40989b..a049417d98d 100644
--- a/addons/point_of_sale/static/src/js/chrome.js
+++ b/addons/point_of_sale/static/src/js/chrome.js
@@ -742,9 +742,6 @@ var Chrome = PosBaseWidget.extend(AbstractAction.prototype, {
if(err.message === 'XmlHttpRequestError '){
title = 'Network Failure (XmlHttpRequestError)';
body = 'The Point of Sale could not be loaded due to a network problem.\n Please check your internet connection.';
- }else if(err.message === 'TLSError'){
- title = 'Https connection to IoT Box failed';
- body = 'Make sure you are using IoT Box v18.10 or higher.\n\n Navigate to ' + err.url + ' to accept the certificate of your IoT Box.';
}else if(err.code === 200){
title = err.data.message;
body = err.data.debug;
diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js
index 27950760e5b..1b4ba84437c 100644
--- a/addons/point_of_sale/static/src/js/models.js
+++ b/addons/point_of_sale/static/src/js/models.js
@@ -135,11 +135,16 @@ exports.PosModel = Backbone.Model.extend({
done.resolve();
},
function(statusText, url){
- if (statusText == 'error' && window.location.protocol == 'https:') {
- var error = {message: 'TLSError', url: url};
- self.chrome.loading_error(error);
- } else {
- done.resolve();
+ var show_loading_error = (self.gui.current_screen === null);
+ done.resolve();
+ if (show_loading_error && statusText == 'error' && window.location.protocol == 'https:') {
+ self.gui.show_popup('alert', {
+ title: _t('HTTPS connection to IoT Box failed'),
+ body: _.str.sprintf(
+ _t('Make sure you are using IoT Box v18.12 or higher. Navigate to %s to accept the certificate of your IoT Box.'),
+ url
+ ),
+ });
}
});
return done;
diff --git a/addons/product/models/product.py b/addons/product/models/product.py
index 68adb54aaf4..551e8705ce3 100644
--- a/addons/product/models/product.py
+++ b/addons/product/models/product.py
@@ -12,6 +12,7 @@ from odoo.addons import decimal_precision as dp
from odoo.tools import float_compare, pycompat
+
class ProductCategory(models.Model):
_name = "product.category"
_description = "Product Category"
@@ -508,7 +509,10 @@ class ProductProduct(models.Model):
precision = self.env['decimal.precision'].precision_get('Product Unit of Measure')
res = self.env['product.supplierinfo']
- for seller in self._prepare_sellers(params):
+ sellers = self._prepare_sellers(params)
+ if self.env.context.get('force_company'):
+ sellers = sellers.filtered(lambda s: not s.company_id or s.company_id.id == self.env.context['force_company'])
+ for seller in sellers:
# Set quantity in UoM of seller
quantity_uom_seller = quantity
if quantity_uom_seller and uom_id and uom_id != seller.product_uom:
diff --git a/addons/product/views/product_views.xml b/addons/product/views/product_views.xml
index 1da4cdcc99e..465c84dddcc 100644
--- a/addons/product/views/product_views.xml
+++ b/addons/product/views/product_views.xml
@@ -237,8 +237,9 @@
<group name="pricing" string="Pricing">
<field name="product_variant_count" invisible="1"/>
<field name="lst_price" widget='monetary' options="{'currency_field': 'currency_id', 'field_digits': True}" attrs="{'readonly': [('product_variant_count', '&gt;', 1)]}"/>
- <field name="standard_price" widget='monetary' options="{'currency_field': 'currency_id', 'field_digits': True}"/>
+ <field name="standard_price" widget='monetary' options="{'currency_field': 'cost_currency_id', 'field_digits': True}"/>
<field name="currency_id" invisible='1'/>
+ <field name="cost_currency_id" invisible="1"/>
</group>
<group name="weight">
<group name="weight" string="Weights" attrs="{'invisible':[('type', 'not in', ['product', 'consu'])]}">
diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py
index e039995505a..7840665bb64 100644
--- a/addons/purchase/models/purchase.py
+++ b/addons/purchase/models/purchase.py
@@ -999,7 +999,7 @@ class ProcurementRule(models.Model):
def _get_purchase_order_date(self, product_id, product_qty, product_uom, values, partner, schedule_date):
"""Return the datetime value to use as Order Date (``date_order``) for the
Purchase Order created to satisfy the given procurement. """
- seller = product_id._select_seller(
+ seller = product_id.with_context(force_company=values['company_id'].id)._select_seller(
partner_id=partner,
quantity=product_qty,
date=fields.Date.to_string(schedule_date),
@@ -1009,7 +1009,7 @@ class ProcurementRule(models.Model):
def _update_purchase_order_line(self, product_id, product_qty, product_uom, values, line, partner):
procurement_uom_po_qty = product_uom._compute_quantity(product_qty, product_id.uom_po_id)
- seller = product_id._select_seller(
+ seller = product_id.with_context(force_company=values['company_id'].id)._select_seller(
partner_id=partner,
quantity=line.product_qty + procurement_uom_po_qty,
date=line.order_id.date_order and line.order_id.date_order[:10],
diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py
index 15118b17096..cffed9290f6 100644
--- a/addons/stock/models/stock_inventory.py
+++ b/addons/stock/models/stock_inventory.py
@@ -3,7 +3,7 @@
from odoo import api, fields, models, _
from odoo.addons import decimal_precision as dp
-from odoo.exceptions import UserError
+from odoo.exceptions import UserError, ValidationError
from odoo.tools import float_utils
@@ -148,13 +148,13 @@ class Inventory(models.Model):
if self.filter == 'none' and self.product_id and self.location_id and self.lot_id:
return
if self.filter not in ('product', 'product_owner') and self.product_id:
- raise UserError(_('The selected inventory options are not coherent.'))
+ raise ValidationError(_('The selected inventory options are not coherent.'))
if self.filter != 'lot' and self.lot_id:
- raise UserError(_('The selected inventory options are not coherent.'))
+ raise ValidationError(_('The selected inventory options are not coherent.'))
if self.filter not in ('owner', 'product_owner') and self.partner_id:
- raise UserError(_('The selected inventory options are not coherent.'))
+ raise ValidationError(_('The selected inventory options are not coherent.'))
if self.filter != 'pack' and self.package_id:
- raise UserError(_('The selected inventory options are not coherent.'))
+ raise ValidationError(_('The selected inventory options are not coherent.'))
def action_reset_product_qty(self):
self.mapped('line_ids').write({'product_qty': 0})
@@ -387,7 +387,7 @@ class InventoryLine(models.Model):
"""
for line in self:
if line.product_id.type != 'product':
- raise UserError(_("You can only adjust stockable products.") + '\n\n%s -> %s' % (line.product_id.display_name, line.product_id.type))
+ raise ValidationError(_("You can only adjust stockable products.") + '\n\n%s -> %s' % (line.product_id.display_name, line.product_id.type))
def _get_quants(self):
return self.env['stock.quant'].search([
diff --git a/addons/stock/wizard/stock_immediate_transfer.py b/addons/stock/wizard/stock_immediate_transfer.py
index 66a652ac795..9b46a91c585 100644
--- a/addons/stock/wizard/stock_immediate_transfer.py
+++ b/addons/stock/wizard/stock_immediate_transfer.py
@@ -22,7 +22,7 @@ class StockImmediateTransfer(models.TransientModel):
picking.action_assign()
if picking.state != 'assigned':
raise UserError(_("Could not reserve all requested products. Please use the \'Mark as Todo\' button to handle the reservation manually."))
- for move in picking.move_lines:
+ for move in picking.move_lines.filtered(lambda m: m.state not in ['done', 'cancel']):
for move_line in move.move_line_ids:
move_line.qty_done = move_line.product_uom_qty
if picking._check_backorder():
diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py
index 770fb443fe1..d8fa7d0aea1 100644
--- a/addons/stock_account/models/stock.py
+++ b/addons/stock_account/models/stock.py
@@ -303,7 +303,7 @@ class StockMove(models.Model):
if qty_to_take_on_candidates == 0:
move.write({
'value': -tmp_value if not quantity else move.value or -tmp_value, # outgoing move are valued negatively
- 'price_unit': -tmp_value / move.product_qty,
+ 'price_unit': -tmp_value / (move.product_qty or quantity),
})
elif qty_to_take_on_candidates > 0:
last_fifo_price = new_standard_price or move.product_id.standard_price
diff --git a/addons/survey/static/src/js/survey.js b/addons/survey/static/src/js/survey.js
index f2d5e50fbbe..e8d4972abcd 100644
--- a/addons/survey/static/src/js/survey.js
+++ b/addons/survey/static/src/js/survey.js
@@ -97,7 +97,7 @@ if(!the_form.length) {
}
// checkboxes and radios
- the_form.find("input[name^=" + key + "][type!='text']").each(function(){
+ the_form.find("input[name=" + key + "][type!='text']").each(function(){
$(this).val(value);
});
});
diff --git a/addons/web_editor/static/src/js/editor/rte.summernote.js b/addons/web_editor/static/src/js/editor/rte.summernote.js
index 614ab4bfcf0..fc4241689e7 100644
--- a/addons/web_editor/static/src/js/editor/rte.summernote.js
+++ b/addons/web_editor/static/src/js/editor/rte.summernote.js
@@ -883,7 +883,10 @@ eventHandler.attach = function (oLayoutInfo, options) {
show_tooltip = true;
setTimeout(function () {
- if (!show_tooltip) return;
+ // Do not show tooltip on double-click and if there is already one
+ if (!show_tooltip || $target.attr('title') !== undefined) {
+ return;
+ }
$target.tooltip({title: _t('Double-click to edit'), trigger: 'manuel', container: 'body'}).tooltip('show');
setTimeout(function () {
$target.tooltip('destroy');
diff --git a/addons/web_editor/static/src/js/widgets/widgets.js b/addons/web_editor/static/src/js/widgets/widgets.js
index b9e2a3289a0..27a5e41d06a 100644
--- a/addons/web_editor/static/src/js/widgets/widgets.js
+++ b/addons/web_editor/static/src/js/widgets/widgets.js
@@ -900,7 +900,7 @@ var VideoWidget = MediaWidget.extend({
options = options || {};
// Video url patterns(youtube, instagram, vimeo, dailymotion, youku, ...)
- var ytRegExp = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtu\.be\/|youtube\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((\w|-){11})(?:\S+)?$/;
+ var ytRegExp = /^(?:(?:https?:)?\/\/)?(?:www\.)?(?:youtu\.be\/|youtube(-nocookie)?\.com\/(?:embed\/|v\/|watch\?v=|watch\?.+&v=))((?:\w|-){11})(?:\S+)?$/;
var ytMatch = url.match(ytRegExp);
var insRegExp = /(.*)instagram.com\/p\/(.[a-zA-Z0-9]*)/;
@@ -927,8 +927,8 @@ var VideoWidget = MediaWidget.extend({
var autoplay = options.autoplay ? '?autoplay=1' : '?autoplay=0';
- if (ytMatch && ytMatch[1].length === 11) {
- $video.attr('src', '//www.youtube.com/embed/' + ytMatch[1] + autoplay);
+ if (ytMatch && ytMatch[2].length === 11) {
+ $video.attr('src', '//www.youtube' + (ytMatch[1] || '') + '.com/embed/' + ytMatch[2] + autoplay);
} else if (insMatch && insMatch[2].length) {
$video.attr('src', '//www.instagram.com/p/' + insMatch[2] + '/embed/');
videoType = 'ins';
diff --git a/addons/website/models/ir_qweb.py b/addons/website/models/ir_qweb.py
index 0f73bc469f5..0c7900e9a47 100644
--- a/addons/website/models/ir_qweb.py
+++ b/addons/website/models/ir_qweb.py
@@ -4,6 +4,7 @@ import re
from collections import OrderedDict
from odoo import models
+from odoo.addons.http_routing.models.ir_http import url_for
from odoo.http import request
@@ -37,10 +38,16 @@ class QWeb(models.AbstractModel):
if not website and options.get('website_id'):
website = self.env['website'].browse(options['website_id'])
- if not website or not website.cdn_activated:
+ if not website:
return atts
name = self.URL_ATTRS.get(tagName)
+ if request and name and name in atts:
+ atts[name] = url_for(atts[name])
+
+ if not website.cdn_activated:
+ return atts
+
if name and name in atts:
atts = OrderedDict(atts)
atts[name] = website.get_cdn_url(atts[name])
diff --git a/addons/website/tests/test_qweb.py b/addons/website/tests/test_qweb.py
index e73083a66b2..5df4898487e 100644
--- a/addons/website/tests/test_qweb.py
+++ b/addons/website/tests/test_qweb.py
@@ -2,7 +2,9 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import re
+import werkzeug
+import odoo
from odoo import tools
from odoo.modules.module import get_module_resource
from odoo.tests.common import TransactionCase
@@ -63,3 +65,123 @@ class TestQweb(TransactionCase):
"css": attachments[1].url,
"user_id": demo.id,
}).encode('utf8'))
+
+class MockObject(object):
+ _log_call = []
+ def __init__(self, *args, **kwargs):
+ self.__dict__ = kwargs
+ def __call__(self, *args, **kwargs):
+ self._log_call.append((args, kwargs))
+ return self
+ def __getitem__(self, index):
+ return self
+
+def werkzeugRaiseNotFound(*args, **kwargs):
+ raise werkzeug.exceptions.NotFound()
+
+class MockRequest(object):
+ """ Class with context manager mocking odoo.http.request for tests """
+ def __init__(self, env, website=None, context=None, multilang=True, routing=True):
+ app = MockObject(routing={
+ 'type': 'http',
+ 'website': True,
+ 'multilang': multilang,
+ })
+ app.get_db_router = app.bind = app.match = app
+ if not routing:
+ app.match = werkzeugRaiseNotFound
+ self.request = MockObject(
+ env=env, context=context or {}, db=None, debug=False,
+ website=website, httprequest=MockObject(
+ path='/hello/',
+ app=app
+ )
+ )
+ odoo.http._request_stack.push(self.request)
+ def __enter__(self):
+ return self.request
+ def __exit__(self, exc_type, exc_value, traceback):
+ odoo.http._request_stack.pop()
+
+class TestQwebProcessAtt(TransactionCase):
+ def setUp(self):
+ super(TestQwebProcessAtt, self).setUp()
+ self.website = self.env['website'].browse(1)
+ self.website.language_ids = self.env.ref('base.lang_en') + self.env.ref('base.lang_fr')
+ self.website.default_lang_id = self.env.ref('base.lang_en')
+ self.website.cdn_activated = True
+ self.website.cdn_url = "http://test.cdn"
+ self.website.cdn_filters = "\n".join(["^(/[a-z]{2}_[A-Z]{2})?/a$", "^/b$"])
+
+ def _test_att(self, url, expect, tag='a', attribute='href'):
+ self.assertEqual(
+ self.env['ir.qweb']._post_processing_att(tag, {attribute: url}, {}),
+ expect
+ )
+
+ def test_process_att_no_request(self):
+ # no request so no URL rewriting
+ self._test_att('/', {'href': '/'})
+ self._test_att('/en_US/', {'href': '/en_US/'})
+ self._test_att('/fr_FR/', {'href': '/fr_FR/'})
+ # no URL rewritting for CDN
+ self._test_att('/a', {'href': '/a'})
+
+ def test_process_att_no_website(self):
+ with MockRequest(self.env) as request:
+ # no website so URL rewriting
+ self._test_att('/', {'href': '/'})
+ self._test_att('/en_US/', {'href': '/en_US/'})
+ self._test_att('/fr_FR/', {'href': '/fr_FR/'})
+ # no URL rewritting for CDN
+ self._test_att('/a', {'href': '/a'})
+
+ def test_process_att_monolang_route(self):
+ with MockRequest(self.env, website=self.website, multilang=False) as request:
+ # lang not changed in URL but CDN enabled
+ self._test_att('/a', {'href': 'http://test.cdn/a'})
+ self._test_att('/en_US/a', {'href': 'http://test.cdn/en_US/a'})
+ self._test_att('/b', {'href': 'http://test.cdn/b'})
+ self._test_att('/en_US/b', {'href': '/en_US/b'})
+
+ def test_process_att_no_request_lang(self):
+ with MockRequest(self.env, self.website) as request:
+ self._test_att('/', {'href': '/'})
+ self._test_att('/en_US/', {'href': '/'})
+ self._test_att('/fr_FR/', {'href': '/fr_FR/'})
+
+ def test_process_att_with_request_lang(self):
+ with MockRequest(self.env, self.website, context={'lang': 'fr_FR'}) as request:
+ self._test_att('/', {'href': '/fr_FR/'})
+ self._test_att('/en_US/', {'href': '/'})
+ self._test_att('/fr_FR/', {'href': '/fr_FR/'})
+
+ def test_process_att_matching_cdn_and_lang(self):
+ with MockRequest(self.env, self.website) as request:
+ # lang prefix is added before CDN
+ self._test_att('/a', {'href': 'http://test.cdn/a'})
+ self._test_att('/en_US/a', {'href': 'http://test.cdn/a'})
+ self._test_att('/fr_FR/a', {'href': 'http://test.cdn/fr_FR/a'})
+ self._test_att('/b', {'href': 'http://test.cdn/b'})
+ self._test_att('/en_US/b', {'href': 'http://test.cdn/b'})
+ self._test_att('/fr_FR/b', {'href': '/fr_FR/b'})
+
+ def test_process_att_no_route(self):
+ with MockRequest(self.env, self.website, context={'lang': 'fr_FR'}, routing=False) as request:
+ # default on multilang=True if route is not /{module}/static/
+ self._test_att('/web/static/hi', {'href': '/web/static/hi'})
+ self._test_att('/my-page', {'href': '/fr_FR/my-page'})
+
+ def test_process_att_url_crap(self):
+ with MockRequest(self.env, self.website) as request:
+ # #{fragment} is stripped from URL when testing route
+ self._test_att('/x#y?z', {'href': '/x#y?z'})
+ self.assertEqual(
+ request.httprequest.app._log_call[-1],
+ (('/x',), {'method': 'POST', 'query_args': None})
+ )
+ self._test_att('/x?y#z', {'href': '/x?y#z'})
+ self.assertEqual(
+ request.httprequest.app._log_call[-1],
+ (('/x',), {'method': 'POST', 'query_args': 'y'})
+ )
diff --git a/doc/cla/individual/bletourmy.md b/doc/cla/individual/bletourmy.md
new file mode 100644
index 00000000000..1d51fcaf71d
--- /dev/null
+++ b/doc/cla/individual/bletourmy.md
@@ -0,0 +1,11 @@
+Switzerland, 2019-03-25
+
+I hereby agree to the terms of the Odoo Individual Contributor License
+Agreement v1.0.
+
+I declare that I am authorized and able to make this agreement and sign this
+declaration.
+
+Signed,
+
+Bernard Letourmy bernard.letourmy@gmail.com https://github.com/bletourmy
diff --git a/doc/cla/individual/matthewdwatkins.md b/doc/cla/individual/matthewdwatkins.md
new file mode 100644
index 00000000000..75f773aa5a4
--- /dev/null
+++ b/doc/cla/individual/matthewdwatkins.md
@@ -0,0 +1,11 @@
+USA, 2019-04-04
+
+I hereby agree to the terms of the Odoo Individual Contributor License
+Agreement v1.0.
+
+I declare that I am authorized and able to make this agreement and sign this
+declaration.
+
+Signed,
+
+Matthew Watkins mwatkins.bulk@gmail.com https://github.com/matthewdwatkins
diff --git a/odoo/addons/base/models/ir_module.py b/odoo/addons/base/models/ir_module.py
index 33ecb666d40..12887a1d5c7 100644
--- a/odoo/addons/base/models/ir_module.py
+++ b/odoo/addons/base/models/ir_module.py
@@ -21,6 +21,7 @@ from docutils.core import publish_string
from docutils.transforms import Transform, writer_aux
from docutils.writers.html4css1 import Writer
import lxml.html
+import psycopg2
import odoo
from odoo import api, fields, models, modules, tools, _
@@ -528,6 +529,14 @@ class Module(models.Model):
@api.multi
def _button_immediate_function(self, function):
+ try:
+ # This is done because the installation/uninstallation/upgrade can modify a currently
+ # running cron job and prevent it from finishing, and since the ir_cron table is locked
+ # during execution, the lock won't be released until timeout.
+ self._cr.execute("SELECT * FROM ir_cron FOR UPDATE NOWAIT")
+ except psycopg2.OperationalError:
+ raise UserError(_("The server is busy right now, module operations are not possible at"
+ " this time, please try again later."))
function(self)
self._cr.commit()
diff --git a/odoo/fields.py b/odoo/fields.py
index be097509072..0acacc0a6d3 100644
--- a/odoo/fields.py
+++ b/odoo/fields.py
@@ -922,7 +922,11 @@ class Field(MetaField('DummyField', (object,), {})):
"""
indexname = '%s_%s_index' % (model._table, self.name)
if self.index:
- sql.create_index(model._cr, indexname, model._table, ['"%s"' % self.name])
+ try:
+ with model._cr.savepoint():
+ sql.create_index(model._cr, indexname, model._table, ['"%s"' % self.name])
+ except psycopg2.OperationalError:
+ _schema.error("Unable to add index for %s", self)
else:
sql.drop_index(model._cr, indexname, model._table)