summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-02-05 12:36:15 +0100
committerChristophe Simonis <chs@odoo.com>2019-02-05 12:36:15 +0100
commit66efbf2b5bf352fd913e30b6db95bdb3c646582f (patch)
tree52ea9465115c372ce827ff75032382105e6d01bd /addons
parent788684a5ddcff074e239b524e043cbf900dc54a9 (diff)
parent53ba83579beeb330312d9e4066ae05145dd40caa (diff)
[MERGE] forward port branch saas-14 up to 53ba83579be
Diffstat (limited to 'addons')
-rw-r--r--addons/account/models/account_invoice.py7
-rw-r--r--addons/product/models/product_pricelist.py59
-rw-r--r--addons/product/models/res_partner.py7
-rw-r--r--addons/sale/models/res_partner.py7
-rw-r--r--addons/stock_account/models/stock.py2
-rw-r--r--addons/website_event/static/src/js/website_geolocation.js5
6 files changed, 49 insertions, 38 deletions
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index 894adf3e278..ea07610662e 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -111,7 +111,12 @@ class AccountInvoice(models.Model):
def _get_outstanding_info_JSON(self):
self.outstanding_credits_debits_widget = json.dumps(False)
if self.state == 'open':
- domain = [('account_id', '=', self.account_id.id), ('partner_id', '=', self.env['res.partner']._find_accounting_partner(self.partner_id).id), ('reconciled', '=', False), '|', ('amount_residual', '!=', 0.0), ('amount_residual_currency', '!=', 0.0)]
+ domain = [('account_id', '=', self.account_id.id),
+ ('partner_id', '=', self.env['res.partner']._find_accounting_partner(self.partner_id).id),
+ ('reconciled', '=', False),
+ '|',
+ '&', ('amount_residual_currency', '!=', 0.0), ('currency_id','!=', None),
+ '&', ('amount_residual_currency', '=', 0.0), '&', ('currency_id','=', None), ('amount_residual', '!=', 0.0)]
if self.type in ('out_invoice', 'in_refund'):
domain.extend([('credit', '>', 0), ('debit', '=', 0)])
type_payment = _('Outstanding credits')
diff --git a/addons/product/models/product_pricelist.py b/addons/product/models/product_pricelist.py
index b7652b5a226..bca9dcc4f1e 100644
--- a/addons/product/models/product_pricelist.py
+++ b/addons/product/models/product_pricelist.py
@@ -291,37 +291,44 @@ class Pricelist(models.Model):
def _get_partner_pricelist(self, partner_id, company_id=None):
""" Retrieve the applicable pricelist for a given partner in a given company.
-
:param company_id: if passed, used for looking up properties,
instead of current user's company
"""
+ res = self._get_partner_pricelist_multi([partner_id], company_id)
+ return res[partner_id].id
+
+ def _get_partner_pricelist_multi(self, partner_ids, company_id=None):
+ """ Retrieve the applicable pricelist for given partners in a given company.
+ :param company_id: if passed, used for looking up properties,
+ instead of current user's company
+ :return: a dict {partner_id: pricelist}
+ """
Partner = self.env['res.partner']
Property = self.env['ir.property'].with_context(force_company=company_id or self.env.user.company_id.id)
-
- p = Partner.browse(partner_id)
- pl = Property.get('property_product_pricelist', Partner._name, '%s,%s' % (Partner._name, p.id))
- if pl:
- pl = pl[0].id
-
- if not pl:
- if p.country_id.code:
- pls = self.env['product.pricelist'].search([('country_group_ids.country_ids.code', '=', p.country_id.code)], limit=1)
- pl = pls and pls[0].id
-
- if not pl:
- # search pl where no country
- pls = self.env['product.pricelist'].search([('country_group_ids', '=', False)], limit=1)
- pl = pls and pls[0].id
-
- if not pl:
- prop = Property.get('property_product_pricelist', 'res.partner')
- pl = prop and prop[0].id
-
- if not pl:
- pls = self.env['product.pricelist'].search([], limit=1)
- pl = pls and pls[0].id
-
- return pl
+ Pricelist = self.env['product.pricelist']
+
+ # retrieve values of property
+ result = Property.get_multi('property_product_pricelist', Partner._name, partner_ids)
+
+ remaining_partner_ids = [pid for pid, val in result.items() if not val]
+ if remaining_partner_ids:
+ # get fallback pricelist when no pricelist for a given country
+ pl_fallback = (
+ Pricelist.search([('country_group_ids', '=', False)], limit=1) or
+ Property.get('property_product_pricelist', 'res.partner') or
+ Pricelist.search([], limit=1)
+ )
+ # group partners by country, and find a pricelist for each country
+ domain = [('id', 'in', remaining_partner_ids)]
+ groups = Partner.read_group(domain, ['country_id'], ['country_id'])
+ for group in groups:
+ country_id = group['country_id'] and group['country_id'][0]
+ pl = Pricelist.search([('country_group_ids.country_ids', '=', country_id)], limit=1)
+ pl = pl or pl_fallback
+ for pid in Partner.search(group['__domain']).ids:
+ result[pid] = pl
+
+ return result
class ResCountryGroup(models.Model):
diff --git a/addons/product/models/res_partner.py b/addons/product/models/res_partner.py
index d307bd6ab09..96ec08ffa75 100644
--- a/addons/product/models/res_partner.py
+++ b/addons/product/models/res_partner.py
@@ -8,17 +8,18 @@ class Partner(models.Model):
_name = 'res.partner'
_inherit = 'res.partner'
+ # NOT A REAL PROPERTY
property_product_pricelist = fields.Many2one(
'product.pricelist', 'Sale Pricelist', compute='_compute_product_pricelist',
- inverse="_inverse_product_pricelist", company_dependent=False, # NOT A REAL PROPERTY
+ inverse="_inverse_product_pricelist", company_dependent=False,
help="This pricelist will be used, instead of the default one, for sales to the current partner")
@api.multi
@api.depends('country_id')
def _compute_product_pricelist(self):
+ res = self.env['product.pricelist']._get_partner_pricelist_multi(self.ids)
for p in self:
- if not isinstance(p.id, models.NewId): # if not onchange
- p.property_product_pricelist = self.env['product.pricelist']._get_partner_pricelist(p.id)
+ p.property_product_pricelist = res.get(p.id)
@api.one
def _inverse_product_pricelist(self):
diff --git a/addons/sale/models/res_partner.py b/addons/sale/models/res_partner.py
index 27a70360d45..0ac1409cd00 100644
--- a/addons/sale/models/res_partner.py
+++ b/addons/sale/models/res_partner.py
@@ -16,12 +16,9 @@ class ResPartner(models.Model):
def _compute_sale_order_count(self):
sale_data = self.env['sale.order'].read_group(domain=[('partner_id', 'child_of', self.ids)],
fields=['partner_id'], groupby=['partner_id'])
- # read to keep the child/parent relation while aggregating the read_group result in the loop
- partner_child_ids = self.read(['child_ids'])
mapped_data = dict([(m['partner_id'][0], m['partner_id_count']) for m in sale_data])
for partner in self:
- # let's obtain the partner id and all its child ids from the read up there
- partner_ids = filter(lambda r: r['id'] == partner.id, partner_child_ids)[0]
- partner_ids = [partner_ids.get('id')] + partner_ids.get('child_ids')
+ # let's obtain the partner id and all its child ids
+ partner_ids = [partner.id] + partner.child_ids.ids
# then we can sum for all the partner's child
partner.sale_order_count = sum(mapped_data.get(child, 0) for child in partner_ids)
diff --git a/addons/stock_account/models/stock.py b/addons/stock_account/models/stock.py
index d2a853f2253..ca40bd9aebc 100644
--- a/addons/stock_account/models/stock.py
+++ b/addons/stock_account/models/stock.py
@@ -288,7 +288,7 @@ class StockMove(models.Model):
valuation_amount = self._context.get('force_valuation_amount')
else:
if self.product_id.cost_method == 'average':
- valuation_amount = cost if self.location_id.usage == 'supplier' and self.location_dest_id.usage == 'internal' else self.product_id.standard_price
+ valuation_amount = cost if self.location_id.usage in ['supplier', 'production'] and self.location_dest_id.usage == 'internal' else self.product_id.standard_price
else:
valuation_amount = cost if self.product_id.cost_method == 'real' else self.product_id.standard_price
# the standard_price of the product may be in another decimal precision, or not compatible with the coinage of
diff --git a/addons/website_event/static/src/js/website_geolocation.js b/addons/website_event/static/src/js/website_geolocation.js
index 43fb2209aef..040a436363c 100644
--- a/addons/website_event/static/src/js/website_geolocation.js
+++ b/addons/website_event/static/src/js/website_geolocation.js
@@ -4,11 +4,12 @@ odoo.define('website_event.geolocation', function (require) {
var animation = require('web_editor.snippets.animation');
animation.registry.visitor = animation.Class.extend({
- selector: ".oe_country_events",
+ selector: ".oe_country_events, .country_events",
start: function () {
+ var self = this;
$.get("/event/get_country_event_list").then(function( data ) {
if(data){
- $( ".country_events_list" ).replaceWith( data );
+ self.$(".country_events_list").replaceWith( data );
}
});
}