diff options
| author | Christophe Simonis <chs@odoo.com> | 2018-03-06 14:19:32 +0100 |
|---|---|---|
| committer | Christophe Simonis <chs@odoo.com> | 2018-03-06 14:19:32 +0100 |
| commit | cc86634b81627fdb06d4942baaee1dbba718eb58 (patch) | |
| tree | bdcfe5aba79587a600532bd555c3209b73d28e72 | |
| parent | b771dd8a5cb9fdc37b9ed3e071c00ac9404d9074 (diff) | |
| parent | 5ddb3fdb0e9375607bf07b134c3cf61d6a5cda93 (diff) | |
[MERGE] forward port branch saas-14 up to 5ddb3fdb0e9
21 files changed, 141 insertions, 39 deletions
diff --git a/addons/account/i18n/account.pot b/addons/account/i18n/account.pot index 31df6e8a650..40674ffdd65 100644 --- a/addons/account/i18n/account.pot +++ b/addons/account/i18n/account.pot @@ -9613,6 +9613,12 @@ msgid "You cannot cancel an invoice which is partially paid. You need to unrecon msgstr "" #. module: account +#: code:addons/account/models/company.py:118 +#, python-format +msgid "You cannot change the currency of the company since some journal items already exist" +msgstr "" + +#. module: account #: code:addons/account/models/account.py:138 #, python-format msgid "You cannot change the owner company of an account that already contains journal items." diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 3211571755b..8c6a21b4614 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- from odoo import fields, models, api, _ -from odoo.exceptions import ValidationError +from odoo.exceptions import ValidationError, UserError from datetime import timedelta @@ -110,4 +110,10 @@ Best Regards,''') company.reflect_code_prefix_change(company.cash_account_code_prefix, new_cash_code, digits) if values.get('accounts_code_digits'): company.reflect_code_digits_change(digits) + + #forbid the change of currency_id if there are already some accounting entries existing + if 'currency_id' in values and values['currency_id'] != company.currency_id.id: + if self.env['account.move.line'].search([('company_id', '=', company.id)]): + raise UserError(_('You cannot change the currency of the company since some journal items already exist')) + return super(ResCompany, self).write(values) diff --git a/addons/account/tests/test_payment.py b/addons/account/tests/test_payment.py index 4fb9da15f8d..e048fbb7930 100644 --- a/addons/account/tests/test_payment.py +++ b/addons/account/tests/test_payment.py @@ -17,7 +17,9 @@ class TestPayment(AccountingTestCase): self.currency_chf_id = self.env.ref("base.CHF").id self.currency_usd_id = self.env.ref("base.USD").id self.currency_eur_id = self.env.ref("base.EUR").id - self.env.ref('base.main_company').write({'currency_id': self.currency_eur_id}) + + company = self.env.ref('base.main_company') + self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.currency_eur_id, company.id]) self.product = self.env.ref("product.product_product_4") self.payment_method_manual_in = self.env.ref("account.account_payment_method_manual_in") self.payment_method_manual_out = self.env.ref("account.account_payment_method_manual_out") diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py index 3b0198b3f09..7d202628fba 100644 --- a/addons/account/tests/test_reconciliation.py +++ b/addons/account/tests/test_reconciliation.py @@ -24,7 +24,8 @@ class TestReconciliation(AccountingTestCase): self.currency_swiss_id = self.env.ref("base.CHF").id self.currency_usd_id = self.env.ref("base.USD").id self.currency_euro_id = self.env.ref("base.EUR").id - self.env.ref('base.main_company').write({'currency_id': self.currency_euro_id}) + company = self.env.ref('base.main_company') + self.cr.execute("UPDATE res_company SET currency_id = %s WHERE id = %s", [self.currency_euro_id, company.id]) self.account_rcv = partner_agrolait.property_account_receivable_id or self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_receivable').id)], limit=1) self.account_rsa = partner_agrolait.property_account_payable_id or self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_payable').id)], limit=1) self.product = self.env.ref("product.product_product_4") diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 9827da60063..cf657f6691d 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -921,6 +921,8 @@ class Lead(models.Model): 'nb_opportunities': 0, } + today = fields.Date.from_string(fields.Date.context_today(self)) + opportunities = self.search([('type', '=', 'opportunity'), ('user_id', '=', self._uid)]) for opp in opportunities: @@ -928,28 +930,28 @@ class Lead(models.Model): if opp.activity_date_deadline: if opp.date_deadline: date_deadline = fields.Date.from_string(opp.date_deadline) - if date_deadline == date.today(): + if date_deadline == today: result['closing']['today'] += 1 - if date.today() <= date_deadline <= date.today() + timedelta(days=7): + if today <= date_deadline <= today + timedelta(days=7): result['closing']['next_7_days'] += 1 - if date_deadline < date.today() and not opp.date_closed: + if date_deadline < today and not opp.date_closed: result['closing']['overdue'] += 1 # Next activities for activity in opp.activity_ids: date_deadline = fields.Date.from_string(activity.date_deadline) - if date_deadline == date.today(): + if date_deadline == today: result['activity']['today'] += 1 - if date.today() <= date_deadline <= date.today() + timedelta(days=7): + if today <= date_deadline <= today + timedelta(days=7): result['activity']['next_7_days'] += 1 - if date_deadline < date.today() and not opp.date_closed: + if date_deadline < today and not opp.date_closed: result['activity']['overdue'] += 1 # Won in Opportunities if opp.date_closed and opp.stage_id.probability == 100: date_closed = fields.Date.from_string(opp.date_closed) - if date.today().replace(day=1) <= date_closed <= date.today(): + if today.replace(day=1) <= date_closed <= today: if opp.planned_revenue: result['won']['this_month'] += opp.planned_revenue - elif date.today() + relativedelta(months=-1, day=1) <= date_closed < date.today().replace(day=1): + elif today + relativedelta(months=-1, day=1) <= date_closed < today.replace(day=1): if opp.planned_revenue: result['won']['last_month'] += opp.planned_revenue @@ -974,9 +976,9 @@ class Lead(models.Model): for activity in activites_done: if activity['date']: date_act = fields.Date.from_string(activity['date']) - if date.today().replace(day=1) <= date_act <= date.today(): + if today.replace(day=1) <= date_act <= today: result['done']['this_month'] += 1 - elif date.today() + relativedelta(months=-1, day=1) <= date_act < date.today().replace(day=1): + elif today + relativedelta(months=-1, day=1) <= date_act < today.replace(day=1): result['done']['last_month'] += 1 # Meetings @@ -991,9 +993,9 @@ class Lead(models.Model): for meeting in meetings: if meeting['start']: start = datetime.strptime(meeting['start'], tools.DEFAULT_SERVER_DATETIME_FORMAT).date() - if start == date.today(): + if start == today: result['meeting']['today'] += 1 - if date.today() <= start <= date.today() + timedelta(days=7): + if today <= start <= today + timedelta(days=7): result['meeting']['next_7_days'] += 1 result['done']['target'] = self.env.user.target_sales_done diff --git a/addons/crm/static/src/js/sales_team_dashboard.js b/addons/crm/static/src/js/sales_team_dashboard.js index b2bec86a753..2f1df97bbb1 100644 --- a/addons/crm/static/src/js/sales_team_dashboard.js +++ b/addons/crm/static/src/js/sales_team_dashboard.js @@ -8,7 +8,7 @@ SalesTeamDashboardView.include({ fetch_data: function() { return new Model('crm.lead') - .call('retrieve_sales_dashboard', []); + .call('retrieve_sales_dashboard', [], {context: this.session.user_context || {}}); } }); diff --git a/addons/delivery/__manifest__.py b/addons/delivery/__manifest__.py index 4a3d32e9a1d..93363b5d092 100644 --- a/addons/delivery/__manifest__.py +++ b/addons/delivery/__manifest__.py @@ -16,6 +16,7 @@ invoices from picking, the system is able to add and compute the shipping line. 'depends': ['sale_stock'], 'data': [ 'security/ir.model.access.csv', + 'security/delivery_security.xml', 'views/delivery_view.xml', 'views/partner_view.xml', 'views/product_template_view.xml', diff --git a/addons/delivery/models/__init__.py b/addons/delivery/models/__init__.py index 33fb6434d71..140f3e93204 100644 --- a/addons/delivery/models/__init__.py +++ b/addons/delivery/models/__init__.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +from . import base_config_settings import delivery_carrier import delivery_price_rule import product_template diff --git a/addons/delivery/models/base_config_settings.py b/addons/delivery/models/base_config_settings.py new file mode 100644 index 00000000000..2ab67cbebdd --- /dev/null +++ b/addons/delivery/models/base_config_settings.py @@ -0,0 +1,17 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, models + + +class BaseConfigSettings(models.TransientModel): + _inherit = 'base.config.settings' + + @api.multi + def set_auth_company_share_product(self): + self.ensure_one() + res = super(BaseConfigSettings, self).set_auth_company_share_product() + delivery_rule = self.env.ref('delivery.delivery_comp_rule', False) + if delivery_rule: + delivery_rule.write({'active': not bool(self.company_share_product)}) + return res diff --git a/addons/delivery/security/delivery_security.xml b/addons/delivery/security/delivery_security.xml new file mode 100644 index 00000000000..ae588bc245c --- /dev/null +++ b/addons/delivery/security/delivery_security.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> +<data noupdate="1"> + <record id="delivery_comp_rule" model="ir.rule"> + <field name="name">Delivery multi-company</field> + <field name="model_id" ref="model_delivery_carrier"/> + <field name="global" eval="True"/> + <field name="domain_force"> ['|',('product_id.company_id','=',user.company_id.id),('product_id.company_id','=',False)]</field> + <field name="active" eval="False"/> + </record> +</data> +</odoo> diff --git a/addons/sale_crm/models/crm_lead.py b/addons/sale_crm/models/crm_lead.py index 3d986566a72..55accdf7983 100644 --- a/addons/sale_crm/models/crm_lead.py +++ b/addons/sale_crm/models/crm_lead.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from datetime import date from dateutil.relativedelta import relativedelta from odoo import api, fields, models @@ -31,7 +30,7 @@ class CrmLead(models.Model): @api.model def retrieve_sales_dashboard(self): res = super(CrmLead, self).retrieve_sales_dashboard() - date_today = date.today() + date_today = fields.Date.from_string(fields.Date.context_today(self)) res['invoiced'] = { 'this_month': 0, diff --git a/addons/survey/models/survey.py b/addons/survey/models/survey.py index 3d367b0364b..8f5ad20c2c5 100644 --- a/addons/survey/models/survey.py +++ b/addons/survey/models/survey.py @@ -683,6 +683,7 @@ class SurveyLabel(models.Model): value = fields.Char('Suggested value', translate=True, required=True) quizz_mark = fields.Float('Score for this choice', help="A positive score indicates a correct choice; a negative or null score indicates a wrong answer") + @api.one @api.constrains('question_id', 'question_id_2') def _check_question_not_empty(self): """Ensure that field question_id XOR field question_id_2 is not null""" diff --git a/addons/web/static/src/js/view_manager.js b/addons/web/static/src/js/view_manager.js index a351a813263..490b2d5cfba 100644 --- a/addons/web/static/src/js/view_manager.js +++ b/addons/web/static/src/js/view_manager.js @@ -15,6 +15,9 @@ var _t = core._t; var ViewManager = Widget.extend(ControlPanelMixin, { className: "o_view_manager_content", + custom_events: { + get_controller_context: '_onGetControllerContext', + }, /** * Called each time the view manager is attached into the DOM */ @@ -474,6 +477,25 @@ var ViewManager = Widget.extend(ControlPanelMixin, { } return this._super.apply(this, arguments); }, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + // ONLY FORWARDPORT THIS COMMIT UP TO SAAS-15 + /** + * Handles a context request: provides to the caller the context of the + * active view. + * + * @private + * @param {OdooEvent} ev + * @param {function} ev.data.callback used to send the requested context + */ + _onGetControllerContext: function (ev) { + var controller = this.active_view && this.active_view.controller; + var context = controller && controller.get_context(); + ev.data.callback(context); + }, }); return ViewManager; diff --git a/addons/web/static/src/js/views/form_common.js b/addons/web/static/src/js/views/form_common.js index c562bebd83e..43a061aee74 100644 --- a/addons/web/static/src/js/views/form_common.js +++ b/addons/web/static/src/js/views/form_common.js @@ -976,6 +976,9 @@ var SelectCreateListView = ListView.extend({ * Search dialog (displays a list of records and permits to create a new one by switching to a form view) */ var SelectCreateDialog = ViewDialog.extend({ + custom_events: { + get_controller_context: '_onGetControllerContext', + }, /** * options: * - initial_ids @@ -1106,6 +1109,23 @@ var SelectCreateDialog = ViewDialog.extend({ return new FormViewDialog(this.__parentedParent, this.options).open(); }, on_view_list_loaded: function() {}, + + //-------------------------------------------------------------------------- + // Handlers + //-------------------------------------------------------------------------- + + /** + * Handles a context request: provides to the caller the context of the + * list view. + * + * @private + * @param {OdooEvent} ev + * @param {function} ev.data.callback used to send the requested context + */ + _onGetControllerContext: function (ev) { + var context = this.view_list.get_context(); + ev.data.callback(context); + }, }); return { diff --git a/addons/web/static/src/js/views/pivot_view.js b/addons/web/static/src/js/views/pivot_view.js index c40d17b41e2..395a07a1016 100644 --- a/addons/web/static/src/js/views/pivot_view.js +++ b/addons/web/static/src/js/views/pivot_view.js @@ -819,7 +819,7 @@ var PivotView = View.extend({ framework.blockUI(); var nbr_measures = this.active_measures.length, headers = this.compute_headers(), - measure_row = nbr_measures > 1 ? _.last(headers) : [], + measure_row = nbr_measures >= 1 ? _.last(headers) : [], rows = this.compute_rows(), i, j, value; headers[0].splice(0,1); @@ -845,7 +845,8 @@ var PivotView = View.extend({ title: this.title, }; if(table.measure_row.length + 1 > 256) { - c.show_message(_t("For Excel compatibility, data cannot be exported if there are more than 256 columns.\n\nTip: try to flip axis, filter further or reduce the number of measures.")); + crash_manager.show_message(_t("For Excel compatibility, data cannot be exported if there are more than 256 columns.\n\nTip: try to flip axis, filter further or reduce the number of measures.")); + framework.unblockUI(); return; } session.get_file({ diff --git a/addons/web/static/src/js/views/search_menus.js b/addons/web/static/src/js/views/search_menus.js index b5f17648256..7d02ec32342 100644 --- a/addons/web/static/src/js/views/search_menus.js +++ b/addons/web/static/src/js/views/search_menus.js @@ -94,13 +94,15 @@ return Widget.extend({ this.$inputs.first().focus(); return; } - var search = this.searchview.build_search_data(), - view_manager = this.findAncestor(function (a) { - // HORRIBLE HACK. PLEASE SAVE ME FROM MYSELF (BUT IN A PAINLESS WAY IF POSSIBLE) - return 'active_view' in a; - }), - view_context = view_manager ? view_manager.active_view.controller.get_context() : {}, - results = pyeval.sync_eval_domains_and_contexts({ + var search = this.searchview.build_search_data(); + // ONLY FORWARDPORT THIS COMMIT UP TO SAAS-15 + var view_context; + this.trigger_up('get_controller_context', { + callback: function (ctx) { + view_context = ctx; + }, + }); + var results = pyeval.sync_eval_domains_and_contexts({ domains: search.domains, contexts: search.contexts.concat(view_context || []), group_by_seq: search.groupbys || [], diff --git a/addons/website_form/controllers/main.py b/addons/website_form/controllers/main.py index 960fd7a5d7e..e7e48ba372f 100644 --- a/addons/website_form/controllers/main.py +++ b/addons/website_form/controllers/main.py @@ -170,7 +170,8 @@ class WebsiteForm(http.Controller): return data def insert_record(self, request, model, values, custom, meta=None): - record = request.env[model.model].sudo().with_context(mail_create_nosubscribe=True).create(values) + model_name = model.sudo().model + record = request.env[model_name].sudo().with_context(mail_create_nosubscribe=True).create(values) if custom or meta: default_field = model.website_form_default_field_id @@ -182,13 +183,13 @@ class WebsiteForm(http.Controller): # If there is a default field configured for this model, use it. # If there isn't, put the custom data in a message instead if default_field.name: - if default_field.ttype == 'html' or model.model == 'mail.mail': + if default_field.ttype == 'html' or model_name == 'mail.mail': custom_content = nl2br(custom_content) record.update({default_field.name: custom_content}) else: values = { 'body': nl2br(custom_content), - 'model': model.model, + 'model': model_name, 'message_type': 'comment', 'no_auto_thread': False, 'res_id': record.id, @@ -200,7 +201,8 @@ class WebsiteForm(http.Controller): # Link all files attached on the form def insert_attachment(self, model, id_record, files): orphan_attachment_ids = [] - record = model.env[model.model].browse(id_record) + model_name = model.sudo().model + record = model.env[model_name].browse(id_record) authorized_fields = model.sudo()._get_form_writable_fields() for file in files: custom_field = file.field_name not in authorized_fields @@ -208,7 +210,7 @@ class WebsiteForm(http.Controller): 'name': file.field_name if custom_field else file.filename, 'datas': base64.encodestring(file.read()), 'datas_fname': file.filename, - 'res_model': model.model, + 'res_model': model_name, 'res_id': record.id, } attachment_id = request.env['ir.attachment'].sudo().create(attachment_value) @@ -220,10 +222,10 @@ class WebsiteForm(http.Controller): # If some attachments didn't match a field on the model, # we create a mail.message to link them to the record if orphan_attachment_ids: - if model.model != 'mail.mail': + if model_name != 'mail.mail': values = { 'body': _('<p>Attached files : </p>'), - 'model': model.model, + 'model': model_name, 'message_type': 'comment', 'no_auto_thread': False, 'res_id': id_record, diff --git a/addons/website_sale_delivery/models/res_country.py b/addons/website_sale_delivery/models/res_country.py index 8b4648a7105..601ac731787 100644 --- a/addons/website_sale_delivery/models/res_country.py +++ b/addons/website_sale_delivery/models/res_country.py @@ -35,5 +35,7 @@ class ResCountry(models.Model): states = res break states |= carrier.state_ids + if not states: + states = states.search([('country_id', '=', self.id)]) res = res & states return res diff --git a/addons/website_slides/models/slides.py b/addons/website_slides/models/slides.py index ad58b7af56a..d155f3855f1 100644 --- a/addons/website_slides/models/slides.py +++ b/addons/website_slides/models/slides.py @@ -351,7 +351,7 @@ class Slide(models.Model): base_url = self.env['ir.config_parameter'].sudo().get_param('web.base.url') for record in self: if record.datas and (not record.document_id or record.slide_type in ['document', 'presentation']): - record.embed_code = '<iframe src="%s/slides/embed/%s?page=1" allowFullScreen="true" height="%s" width="%s" frameborder="0"></iframe>' % (base_url, record.id, 315, 420) + record.embed_code = '<iframe src="%s/slides/embed/%s?page=1" class="o_wslides_iframe_viewer" allowFullScreen="true" height="%s" width="%s" frameborder="0"></iframe>' % (base_url, record.id, 315, 420) elif record.slide_type == 'video' and record.document_id: if not record.mime_type: # embed youtube video diff --git a/addons/website_slides/static/src/js/slides.js b/addons/website_slides/static/src/js/slides.js index 93ff942ab83..8f3ab9ea6c8 100644 --- a/addons/website_slides/static/src/js/slides.js +++ b/addons/website_slides/static/src/js/slides.js @@ -111,11 +111,12 @@ $(document).ready(function () { }, }); - $('iframe').ready(function() { + $('iframe.o_wslides_iframe_viewer').ready(function() { // TODO : make it work. For now, once the iframe is loaded, the value of #page_count is // still now set (the pdf is still loading) - var max_page = $('iframe').contents().find('#page_count').val(); - new SlideSocialEmbed($(this), max_page).setElement($('.oe_slide_js_embed_code_widget')); + var $iframe = $(this); + var max_page = $iframe.contents().find('#page_count').val(); + new SlideSocialEmbed($iframe, max_page).setElement($('.oe_slide_js_embed_code_widget')); }); diff --git a/odoo/addons/base/ir/ir_autovacuum.py b/odoo/addons/base/ir/ir_autovacuum.py index 774a6613592..1bbbd4ee096 100644 --- a/odoo/addons/base/ir/ir_autovacuum.py +++ b/odoo/addons/base/ir/ir_autovacuum.py @@ -17,7 +17,11 @@ class AutoVacuum(models.AbstractModel): for mname in self.env: model = self.env[mname] if model.is_transient(): - model._transient_vacuum(force=True) + try: + with cr.savepoint(): + model._transient_vacuum(force=True) + except Exception as e: + _logger.warning("Failed to clean transient model %s\n%s", model, str(e)) @api.model def _gc_user_logs(self): |
