diff options
Diffstat (limited to 'addons')
34 files changed, 260 insertions, 72 deletions
diff --git a/addons/account/models/__init__.py b/addons/account/models/__init__.py index b6b023055b8..5f99c57e04d 100644 --- a/addons/account/models/__init__.py +++ b/addons/account/models/__init__.py @@ -19,3 +19,4 @@ from . import reconciliation_widget from . import account_incoterms from . import digest from . import account_invoice_import_wizard +from . import res_users diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py index 30b92b411c4..2974c2119c9 100644 --- a/addons/account/models/account_invoice.py +++ b/addons/account/models/account_invoice.py @@ -103,6 +103,11 @@ class AccountInvoice(models.Model): if invoice_type == 'out_invoice' and self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms'): return self.env.user.company_id.invoice_terms + 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', @@ -112,14 +117,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 or line.company_id.currency_id - residual += from_currency._convert(line.amount_residual, self.currency_id, line.company_id, line.date or fields.Date.today()) + 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 or line.company_id.currency_id + residual += from_currency._convert(line.amount_residual, self.currency_id, line.company_id, line.date or fields.Date.today()) self.residual_company_signed = abs(residual_company_signed) * sign self.residual_signed = abs(residual) * sign self.residual = abs(residual) @@ -1069,11 +1073,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/res_users.py b/addons/account/models/res_users.py new file mode 100644 index 00000000000..3e6fd163482 --- /dev/null +++ b/addons/account/models/res_users.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models, _ +from odoo.exceptions import ValidationError + + +class Users(models.Model): + _inherit = "res.users" + + @api.multi + @api.constrains('groups_id') + def _check_one_user_type(self): + super(Users, self)._check_one_user_type() + for user in self: + if (user.user_has_groups('account.group_show_line_subtotals_tax_included') and + user.user_has_groups('account.group_show_line_subtotals_tax_excluded')): + raise ValidationError(_('A user cannot have both Tax B2B and Tax B2C')) diff --git a/addons/account/views/account_view.xml b/addons/account/views/account_view.xml index c0abc40d236..234d1c4b53c 100644 --- a/addons/account/views/account_view.xml +++ b/addons/account/views/account_view.xml @@ -1263,6 +1263,7 @@ <field name="invoice_id" attrs="{'invisible': [('invoice_id','=',False)]}"/> </group> <group string="Dates"> + <field name="date"/> <field name="date_maturity"/> </group> @@ -1270,7 +1271,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_payment/views/account_portal_templates.xml b/addons/account_payment/views/account_portal_templates.xml index e9d121e15e0..bdc9c9da488 100644 --- a/addons/account_payment/views/account_portal_templates.xml +++ b/addons/account_payment/views/account_portal_templates.xml @@ -48,7 +48,7 @@ <div t-if="pms or acquirers" id="payment_method" class="text-left col-md-13"> <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="invoice.get_portal_url()"/> <t t-set="error_url" t-value="invoice.get_portal_url()"/> <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/delivery/models/product_template.py b/addons/delivery/models/product_template.py index 79465b50303..eceb08e58e9 100644 --- a/addons/delivery/models/product_template.py +++ b/addons/delivery/models/product_template.py @@ -7,4 +7,7 @@ from odoo import models, fields class ProductTemplate(models.Model): _inherit = 'product.template' - hs_code = fields.Char(string="HS Code", help="Standardized code for international shipping and goods declaration") + hs_code = fields.Char( + string="HS Code", + help="Standardized code for international shipping and goods declaration. At the moment, only used for the FedEx shipping provider.", + ) diff --git a/addons/digest/models/digest.py b/addons/digest/models/digest.py index 7809648e48c..eb4fd1190bb 100644 --- a/addons/digest/models/digest.py +++ b/addons/digest/models/digest.py @@ -133,7 +133,7 @@ class Digest(models.Model): tip = self.env['digest.tip'].search([('user_ids', '!=', user.id), '|', ('group_id', 'in', user.groups_id.ids), ('group_id', '=', False)], limit=1) if not tip: return False - tip.user_ids = [4, user.id] + tip.user_ids += user body = tools.html_sanitize(tip.tip_description) tip_description = self.env['mail.template']._render_template(body, 'digest.tip', self.id) return tip_description diff --git a/addons/hr_holidays/models/hr_leave.py b/addons/hr_holidays/models/hr_leave.py index bf05ec67fb9..70ec1a7ed7c 100644 --- a/addons/hr_holidays/models/hr_leave.py +++ b/addons/hr_holidays/models/hr_leave.py @@ -478,7 +478,7 @@ class HolidaysRequest(models.Model): self.message_subscribe(partner_ids=employee.user_id.partner_id.ids) @api.multi - @api.constrains('holiday_status_id') + @api.constrains('holiday_status_id', 'date_to', 'date_from') def _check_leave_type_validity(self): for leave in self: if leave.holiday_status_id.validity_start and leave.holiday_status_id.validity_stop: diff --git a/addons/hr_timesheet/models/hr_timesheet.py b/addons/hr_timesheet/models/hr_timesheet.py index 0542428f25c..7d1edf4b2b0 100644 --- a/addons/hr_timesheet/models/hr_timesheet.py +++ b/addons/hr_timesheet/models/hr_timesheet.py @@ -42,7 +42,10 @@ class AccountAnalyticLine(models.Model): @api.onchange('employee_id') def _onchange_employee_id(self): - self.user_id = self.employee_id.user_id + if self.employee_id: + self.user_id = self.employee_id.user_id + else: + self.user_id = self._default_user() @api.depends('employee_id') def _compute_department_id(self): diff --git a/addons/http_routing/models/ir_http.py b/addons/http_routing/models/ir_http.py index b8356cf13b5..12c81e9d620 100644 --- a/addons/http_routing/models/ir_http.py +++ b/addons/http_routing/models/ir_http.py @@ -165,7 +165,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('') @@ -174,6 +174,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/mail/models/mail_mail.py b/addons/mail/models/mail_mail.py index f758456c77e..a2ba820656f 100644 --- a/addons/mail/models/mail_mail.py +++ b/addons/mail/models/mail_mail.py @@ -5,6 +5,7 @@ import base64 import datetime import logging import psycopg2 +import smtplib import threading import re @@ -394,11 +395,12 @@ class MailMail(models.Model): mail.id, mail.message_id) # mail status will stay on ongoing since transaction will be rollback raise - except psycopg2.Error: - # If an error with the database occurs, chances are that the cursor is unusable. - # This will lead to an `psycopg2.InternalError` being raised when trying to write - # `state`, shadowing the original exception and forbid a retry on concurrent - # update. Let's bubble it. + except (psycopg2.Error, smtplib.SMTPServerDisconnected): + # If an error with the database or SMTP session occurs, chances are that the cursor + # or SMTP session are unusable, causing further errors when trying to save the state. + _logger.exception( + 'Exception while processing mail with ID %r and Msg-Id %r.', + mail.id, mail.message_id) raise except Exception as e: failure_reason = tools.ustr(e) diff --git a/addons/mail/models/mail_message.py b/addons/mail/models/mail_message.py index e228f7c4062..e2ebb16c69e 100644 --- a/addons/mail/models/mail_message.py +++ b/addons/mail/models/mail_message.py @@ -154,8 +154,8 @@ class Message(models.Model): @api.multi def _search_has_error(self, operator, operand): if operator == '=' and operand: - return ['&', ('notification_ids.email_status', 'in', ('bounce', 'exception')), ('author_id', '=', self.env.user.partner_id.id)] - return ['!', '&', ('notification_ids.email_status', 'in', ('bounce', 'exception')), ('author_id', '=', self.env.user.partner_id.id)] # this wont work and will be equivalent to "not in" beacause of orm restrictions. Dont use "has_error = False" + return [('notification_ids.email_status', 'in', ('bounce', 'exception'))] + return ['!', ('notification_ids.email_status', 'in', ('bounce', 'exception'))] # this wont work and will be equivalent to "not in" beacause of orm restrictions. Dont use "has_error = False" @api.depends('starred_partner_ids') def _get_starred(self): diff --git a/addons/mail/models/mail_thread.py b/addons/mail/models/mail_thread.py index 79cfb230a6b..8e35a8fda18 100644 --- a/addons/mail/models/mail_thread.py +++ b/addons/mail/models/mail_thread.py @@ -237,7 +237,7 @@ class MailThread(models.AbstractModel): @api.model def _search_message_has_error(self, operator, operand): - return [('message_ids.has_error', operator, operand)] + return ['&', ('message_ids.has_error', operator, operand), ('message_ids.author_id', '=', self.env.user.partner_id.id)] @api.multi def _compute_message_attachment_count(self): diff --git a/addons/mass_mailing/models/mass_mailing_stats.py b/addons/mass_mailing/models/mass_mailing_stats.py index 662b6adbaaf..f0d8a763438 100644 --- a/addons/mass_mailing/models/mass_mailing_stats.py +++ b/addons/mass_mailing/models/mass_mailing_stats.py @@ -66,14 +66,14 @@ class MailMailStats(models.Model): stat.state = 'ignored' elif stat.exception: stat.state = 'exception' - elif stat.sent: - stat.state = 'sent' elif stat.opened or stat.clicked: stat.state = 'opened' elif stat.replied: stat.state = 'replied' elif stat.bounced: stat.state = 'bounced' + elif stat.sent: + stat.state = 'sent' else: stat.state = 'outgoing' diff --git a/addons/mass_mailing/wizard/mail_compose_message.py b/addons/mass_mailing/wizard/mail_compose_message.py index d0804977301..3f88e62552b 100644 --- a/addons/mass_mailing/wizard/mail_compose_message.py +++ b/addons/mass_mailing/wizard/mail_compose_message.py @@ -64,7 +64,8 @@ class MailComposeMessage(models.TransientModel): if mail_values.get('email_to'): mail_to = tools.email_normalize(mail_values['email_to']) else: - mail_to = tools.email_normalize(partners_email.get(res_id)) + partner_id = (mail_values.get('recipient_ids') or [(False, '')])[0][1] + mail_to = tools.email_normalize(partners_email.get(partner_id)) if (opt_out_list and mail_to in opt_out_list) or (seen_list and mail_to in seen_list) \ or (not mail_to or not email_re.findall(mail_to)): # prevent sending to blocked addresses that were included by mistake diff --git a/addons/point_of_sale/static/src/js/chrome.js b/addons/point_of_sale/static/src/js/chrome.js index 026682d5135..23ea37d9810 100644 --- a/addons/point_of_sale/static/src/js/chrome.js +++ b/addons/point_of_sale/static/src/js/chrome.js @@ -721,9 +721,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.12 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 4cf483dfcde..eb4c30701fa 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -137,11 +137,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 1c79a5d8f39..1a48f8fa526 100644 --- a/addons/product/models/product.py +++ b/addons/product/models/product.py @@ -15,6 +15,7 @@ from odoo.tools import float_compare _logger = logging.getLogger(__name__) + class ProductCategory(models.Model): _name = "product.category" _description = "Product Category" @@ -521,7 +522,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 a75e6d5ba10..a354b3c5174 100644 --- a/addons/product/views/product_views.xml +++ b/addons/product/views/product_views.xml @@ -297,8 +297,9 @@ <div class="o_row col-5 pl-0"> <field name="lst_price" widget='monetary' options="{'currency_field': 'currency_id', 'field_digits': True}" attrs="{'readonly': [('product_variant_count', '>', 1)]}"/> </div> - <field name="standard_price" widget='monetary' options="{'currency_field': 'currency_id'}"/> + <field name="standard_price" widget='monetary' options="{'currency_field': 'cost_currency_id'}"/> <field name="currency_id" invisible='1'/> + <field name="cost_currency_id" invisible="1"/> </group> </group> <group> diff --git a/addons/purchase/models/account_invoice.py b/addons/purchase/models/account_invoice.py index 9f63039afd7..6c7b1b9293d 100644 --- a/addons/purchase/models/account_invoice.py +++ b/addons/purchase/models/account_invoice.py @@ -25,6 +25,10 @@ class AccountInvoice(models.Model): return {} self.purchase_id = self.vendor_bill_purchase_id.purchase_order_id self.vendor_bill_id = self.vendor_bill_purchase_id.vendor_bill_id + vendor_ref = self.vendor_bill_purchase_id.purchase_order_id.partner_ref + if vendor_ref: + self.reference = ", ".join([self.reference, vendor_ref]) if ( + self.reference and vendor_ref not in self.reference) else vendor_ref self.vendor_bill_purchase_id = False return {} diff --git a/addons/purchase_requisition/models/product.py b/addons/purchase_requisition/models/product.py index ef94ad283b7..48380f1c3dc 100644 --- a/addons/purchase_requisition/models/product.py +++ b/addons/purchase_requisition/models/product.py @@ -16,10 +16,11 @@ class ProductProduct(models.Model): _inherit = 'product.product' def _prepare_sellers(self, params): + sellers = super(ProductProduct, self)._prepare_sellers(params) if params and params.get('order_id'): - return self.seller_ids.filtered(lambda s: not s.purchase_requisition_id or s.purchase_requisition_id == params['order_id'].requisition_id) + return sellers.filtered(lambda s: not s.purchase_requisition_id or s.purchase_requisition_id == params['order_id'].requisition_id) else: - return self.seller_ids + return sellers class ProductTemplate(models.Model): diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 5059aa2cf24..797ce794067 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -174,7 +174,7 @@ class StockRule(models.Model): def _update_purchase_order_line(self, product_id, product_qty, product_uom, company_id, values, line): partner = values['supplier'].name 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=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.date(), @@ -197,7 +197,7 @@ class StockRule(models.Model): procurement_uom_po_qty = product_uom._compute_quantity(product_qty, product_id.uom_po_id) # _select_seller is used if the supplier have different price depending # the quantities ordered. - seller = product_id._select_seller( + seller = product_id.with_context(force_company=company_id.id)._select_seller( partner_id=partner, quantity=procurement_uom_po_qty, date=po.date_order and po.date_order.date(), diff --git a/addons/sale/models/res_company.py b/addons/sale/models/res_company.py index 6d6cfccc87c..439061adafa 100644 --- a/addons/sale/models/res_company.py +++ b/addons/sale/models/res_company.py @@ -61,6 +61,7 @@ class ResCompany(models.Model): 'product_uom_qty': 10, 'price_unit': 123, 'order_id': sample_sales_order.id, + 'company_id': sample_sales_order.company_id.id, }) return sample_sales_order diff --git a/addons/sale/models/sale.py b/addons/sale/models/sale.py index 875b48646c2..79456e26d28 100644 --- a/addons/sale/models/sale.py +++ b/addons/sale/models/sale.py @@ -1031,20 +1031,23 @@ class SaleOrderLine(models.Model): res[field] = line._fields[field].convert_to_write(line[field], line) return res - @api.model - def create(self, values): - if values.get('display_type', self.default_get(['display_type'])['display_type']): - values.update(product_id=False, price_unit=0, product_uom_qty=0, product_uom=False, customer_lead=0) - - values.update(self._prepare_add_missing_fields(values)) - line = super(SaleOrderLine, self).create(values) - if line.product_id and line.order_id.state == 'sale': - msg = _("Extra line with %s ") % (line.product_id.display_name,) - line.order_id.message_post(body=msg) - # create an analytic account if at least an expense product - if line.product_id.expense_policy not in [False, 'no'] and not self.order_id.analytic_account_id: - self.order_id._create_analytic_account() - return line + @api.model_create_multi + def create(self, vals_list): + for values in vals_list: + if values.get('display_type', self.default_get(['display_type'])['display_type']): + values.update(product_id=False, price_unit=0, product_uom_qty=0, product_uom=False, customer_lead=0) + + values.update(self._prepare_add_missing_fields(values)) + + lines = super().create(vals_list) + for line in lines: + if line.product_id and line.order_id.state == 'sale': + msg = _("Extra line with %s ") % (line.product_id.display_name,) + line.order_id.message_post(body=msg) + # create an analytic account if at least an expense product + if line.product_id.expense_policy not in [False, 'no'] and not line.order_id.analytic_account_id: + line.order_id._create_analytic_account() + return lines _sql_constraints = [ ('accountable_required_fields', diff --git a/addons/stock/models/stock_inventory.py b/addons/stock/models/stock_inventory.py index d3111d2564f..4710ff88851 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, float_compare @@ -151,13 +151,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 product doesn\'t belong to that owner..')) + raise ValidationError(_('The selected product doesn\'t belong to that owner..')) if self.filter != 'lot' and self.lot_id: - raise UserError(_('The selected lot number doesn\'t exist.')) + raise ValidationError(_('The selected lot number doesn\'t exist.')) if self.filter not in ('owner', 'product_owner') and self.partner_id: - raise UserError(_('The selected owner doesn\'t have the proprietary of that product.')) + raise ValidationError(_('The selected owner doesn\'t have the proprietary of that product.')) if self.filter != 'pack' and self.package_id: - raise UserError(_('The selected inventory options are not coherent, the package doesn\'t exist.')) + raise ValidationError(_('The selected inventory options are not coherent, the package doesn\'t exist.')) def action_reset_product_qty(self): self.mapped('line_ids').write({'product_qty': 0}) @@ -425,7 +425,7 @@ class InventoryLine(models.Model): """ for line in self: if line.product_id.type != 'product': - raise UserError(_("You can only adjust storable products.") + '\n\n%s -> %s' % (line.product_id.display_name, line.product_id.type)) + raise ValidationError(_("You can only adjust storable products.") + '\n\n%s -> %s' % (line.product_id.display_name, line.product_id.type)) def _get_move_values(self, qty, location_id, location_dest_id, out): self.ensure_one() diff --git a/addons/stock/models/stock_quant.py b/addons/stock/models/stock_quant.py index 03c1890c51a..66a7aa90b8c 100644 --- a/addons/stock/models/stock_quant.py +++ b/addons/stock/models/stock_quant.py @@ -365,7 +365,7 @@ class QuantPackage(models.Model): 'res.partner', 'Owner', compute='_compute_package_info', search='_search_owner', index=True, readonly=True) - @api.depends('quant_ids.package_id', 'quant_ids.location_id', 'quant_ids.company_id', 'quant_ids.owner_id') + @api.depends('quant_ids.package_id', 'quant_ids.location_id', 'quant_ids.company_id', 'quant_ids.owner_id', 'quant_ids.quantity', 'quant_ids.reserved_quantity') def _compute_package_info(self): for package in self: values = {'location_id': False, 'company_id': self.env.user.company_id.id, 'owner_id': False} 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 35742c6de79..a708f57e256 100644 --- a/addons/stock_account/models/stock.py +++ b/addons/stock_account/models/stock.py @@ -304,7 +304,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 727bef148fd..b4b47cb3d2f 100644 --- a/addons/survey/static/src/js/survey.js +++ b/addons/survey/static/src/js/survey.js @@ -98,7 +98,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/wysiwyg/widgets/media.js b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js index e8a93e7c5f3..7f73cb8269b 100644 --- a/addons/web_editor/static/src/js/wysiwyg/widgets/media.js +++ b/addons/web_editor/static/src/js/wysiwyg/widgets/media.js @@ -905,7 +905,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]*)/; @@ -932,8 +932,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 0a36e8fa8ee..ea33aa114b2 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 from odoo.addons.base.models.assetsbundle import AssetsBundle from odoo.tools import html_escape as escape @@ -50,10 +51,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 5e078d89dd6..8cba2d150c0 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'}) + ) |
