diff --git a/addons/account/models/account_journal_dashboard.py b/addons/account/models/account_journal_dashboard.py index b753323ac43..7fc9aa17cf8 100644 --- a/addons/account/models/account_journal_dashboard.py +++ b/addons/account/models/account_journal_dashboard.py @@ -138,7 +138,8 @@ class account_journal(models.Model): number_to_reconcile = last_balance = account_sum = 0 ac_bnk_stmt = [] title = '' - number_draft = number_waiting = number_late = sum_draft = sum_waiting = sum_late = 0 + number_draft = number_waiting = number_late = 0 + sum_draft = sum_waiting = sum_late = 0.0 if self.type in ['bank', 'cash']: last_bank_stmt = self.env['account.bank.statement'].search([('journal_id', 'in', self.ids)], order="date desc, id desc", limit=1) last_balance = last_bank_stmt and last_bank_stmt[0].balance_end or 0 @@ -171,30 +172,33 @@ class account_journal(models.Model): elif self.type in ['sale', 'purchase']: title = _('Bills to pay') if self.type == 'purchase' else _('Invoices owed to you') # optimization to find total and sum of invoice that are in draft, open state - query = """SELECT state, amount_total, currency_id AS currency FROM account_invoice WHERE journal_id = %s AND state NOT IN ('paid', 'cancel');""" + query = """SELECT state, amount_total, currency_id AS currency, type FROM account_invoice WHERE journal_id = %s AND state NOT IN ('paid', 'cancel');""" self.env.cr.execute(query, (self.id,)) query_results = self.env.cr.dictfetchall() today = datetime.today() - query = """SELECT amount_total, currency_id AS currency FROM account_invoice WHERE journal_id = %s AND date < %s AND state = 'open';""" + query = """SELECT amount_total, currency_id AS currency, type FROM account_invoice WHERE journal_id = %s AND date < %s AND state = 'open';""" self.env.cr.execute(query, (self.id, today)) late_query_results = self.env.cr.dictfetchall() - sum_draft = 0.0 - number_draft = 0 - number_waiting = 0 for result in query_results: + if result['type'] in ['in_refund', 'out_refund']: + factor = -1 + else: + factor = 1 cur = self.env['res.currency'].browse(result.get('currency')) if result.get('state') in ['draft', 'proforma', 'proforma2']: number_draft += 1 - sum_draft += cur.compute(result.get('amount_total'), currency) + sum_draft += cur.compute(result.get('amount_total'), currency) * factor elif result.get('state') == 'open': number_waiting += 1 - sum_waiting += cur.compute(result.get('amount_total'), currency) - sum_late = 0.0 - number_late = 0 + sum_waiting += cur.compute(result.get('amount_total'), currency) * factor for result in late_query_results: + if result['type'] in ['in_refund', 'out_refund']: + factor = -1 + else: + factor = 1 cur = self.env['res.currency'].browse(result.get('currency')) number_late += 1 - sum_late += cur.compute(result.get('amount_total'), currency) + sum_late += cur.compute(result.get('amount_total'), currency) * factor return { 'number_to_reconcile': number_to_reconcile, diff --git a/addons/account/models/partner.py b/addons/account/models/partner.py index 665fc780369..0e381d20ef8 100644 --- a/addons/account/models/partner.py +++ b/addons/account/models/partner.py @@ -321,12 +321,9 @@ class ResPartner(models.Model): def _compute_issued_total(self): """ Returns the issued total as will be displayed on partner view """ today = fields.Date.context_today(self) - for partner in self: - domain = partner.get_followup_lines_domain(today, overdue_only=True) - issued_total = 0 - for aml in self.env['account.move.line'].search(domain): - issued_total += aml.amount_residual - partner.issued_total = issued_total + domain = self.get_followup_lines_domain(today, overdue_only=True) + for aml in self.env['account.move.line'].search(domain): + aml.partner_id.issued_total += aml.amount_residual @api.one def _compute_has_unreconciled_entries(self): diff --git a/addons/mass_mailing/views/mass_mailing_views.xml b/addons/mass_mailing/views/mass_mailing_views.xml index ddd5e153696..adcd0599afa 100644 --- a/addons/mass_mailing/views/mass_mailing_views.xml +++ b/addons/mass_mailing/views/mass_mailing_views.xml @@ -312,7 +312,7 @@ - + diff --git a/addons/pad/static/src/js/pad.js b/addons/pad/static/src/js/pad.js index dffd5c12967..d39b570d047 100644 --- a/addons/pad/static/src/js/pad.js +++ b/addons/pad/static/src/js/pad.js @@ -17,7 +17,9 @@ var FieldPad = form_common.AbstractField.extend(form_common.ReinitializeWidgetMi event.preventDefault(); self.set("configured", true); }); - this.pad_loading_request = null; + // CHANGES ONLY NEEDED UNTIL SAAS-15 + // deferred for request getting pad content (readonly) or new pad url (edit) + this._pad_loading_deferred = null; }, initialize_content: function() { var self = this; @@ -36,14 +38,25 @@ var FieldPad = form_common.AbstractField.extend(form_common.ReinitializeWidgetMi }, render_value: function() { var self = this; - $.when(this._configured_deferred, this.pad_loading_request).always(function() { + $.when(this._configured_deferred).always(function() { if (!self.get('configured')){ return; } + + // reject previously ongoing _pad_loading_deferred + if (self._pad_loading_deferred !== null) { + self._pad_loading_deferred.reject(); + self.$('.oe_pad_content').removeClass('oe_pad_loading').html(''); + } + self._pad_loading_deferred = $.Deferred(); + // keep reference to current _pad_loading_deferred + var loading_def = self._pad_loading_deferred; + var value = self.get('value'); if (self.get('effective_readonly')) { if (_.str.startsWith(value, 'http')) { - self.pad_loading_request = self.view.dataset.call('pad_get_content', {url: value}).done(function(data) { + self.view.dataset.call('pad_get_content', {url: value}).then(loading_def.resolve, loading_def.reject); + loading_def.done(function(data) { self.$('.oe_pad_content').removeClass('oe_pad_loading').html('
'); self.$('.oe_pad_readonly').html(data); }).fail(function() { @@ -54,21 +67,37 @@ var FieldPad = form_common.AbstractField.extend(form_common.ReinitializeWidgetMi } } else { - var def = $.when(); + var def = $.Deferred(); if (! value || !_.str.startsWith(value, 'http')) { - def = self.view.dataset.call('pad_generate_url', { - context: { - model: self.view.model, - field_name: self.name, - object_id: self.view.datarecord.id - }, - }).then(function(data) { - if (! data.url) { - self.set("configured", false); - } else { - self.internal_set_value(data.url); - } + var deferreds = [ + self.view.dataset.call('pad_generate_url', { + context: { + model: self.view.model, + field_name: self.name, + object_id: self.view.datarecord.id + } + }), + // change record only after record_loaded and its call stack is finished + self.view.record_loaded.then(function() { + var call_stack_ended = $.Deferred(); + _.defer(call_stack_ended.resolve); + return call_stack_ended; + }) + ]; + // delay onchange after x2many views are loaded + deferreds = deferreds.concat(_.compact(_.pluck(self.view.fields, 'is_loaded'))); + $.when.apply($, deferreds).then(function(data) { + // update value only if loading_def has not been previously rejected + loading_def.resolve().done(function(){ + if (! data.url) { + self.set("configured", false); + } else { + self.internal_set_value(data.url); + } + }).then(def.resolve, def.reject); }); + } else { + def.resolve(); } def.then(function() { value = self.get('value'); diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 4cb1cc08296..9566d195c33 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1413,7 +1413,7 @@ exports.Orderline = Backbone.Model.extend({ } return false; }, - compute_all: function(taxes, price_unit, quantity, currency_rounding) { + compute_all: function(taxes, price_unit, quantity, currency_rounding, no_map_tax) { var self = this; var list_taxes = []; var currency_rounding_bak = currency_rounding; @@ -1424,7 +1424,9 @@ exports.Orderline = Backbone.Model.extend({ var total_included = total_excluded; var base = total_excluded; _(taxes).each(function(tax) { - tax = self._map_tax_fiscal_position(tax); + if (!no_map_tax){ + tax = self._map_tax_fiscal_position(tax); + } if (tax.amount_type === 'group'){ var ret = self.compute_all(tax.children_tax_ids, price_unit, quantity, currency_rounding); total_excluded = ret.total_excluded; @@ -1955,6 +1957,27 @@ exports.Order = Backbone.Model.extend({ this.orderlines.remove(line); this.select_orderline(this.get_last_orderline()); }, + + fix_tax_included_price: function(line){ + if(this.fiscal_position){ + var unit_price = line.price; + var taxes = line.get_taxes(); + var mapped_included_taxes = []; + _(taxes).each(function(tax) { + var line_tax = line._map_tax_fiscal_position(tax); + if(tax.price_include && tax.id != line_tax.id){ + + mapped_included_taxes.push(tax); + } + }) + + unit_price = line.compute_all(mapped_included_taxes, unit_price, 1, this.pos.currency.rounding, true).total_excluded; + + line.set_unit_price(unit_price); + } + + }, + add_product: function(product, options){ if(this._printed){ this.destroy(); @@ -1970,9 +1993,14 @@ exports.Order = Backbone.Model.extend({ if(options.quantity !== undefined){ line.set_quantity(options.quantity); } + if(options.price !== undefined){ line.set_unit_price(options.price); } + + //To substract from the unit price the included taxes mapped by the fiscal position + this.fix_tax_included_price(line); + if(options.discount !== undefined){ line.set_discount(options.discount); } diff --git a/odoo/addons/base/tests/test_views.py b/odoo/addons/base/tests/test_views.py index 5d6608457f2..de7d2e060e6 100644 --- a/odoo/addons/base/tests/test_views.py +++ b/odoo/addons/base/tests/test_views.py @@ -8,6 +8,7 @@ from lxml import etree from lxml.builder import E from psycopg2 import IntegrityError +from odoo.osv.orm import modifiers_tests from odoo.exceptions import ValidationError from odoo.tests import common from odoo.tools import mute_logger @@ -816,6 +817,10 @@ class TestViews(ViewCase): string="Replacement title", version="7.0" )) + def test_modifiers(self): + # implemeted elsewhere... + modifiers_tests() + class ViewModeField(ViewCase): """