diff --git a/addons/account_voucher/account_voucher.py b/addons/account_voucher/account_voucher.py index fc5d5aa1188..c9516b6135f 100644 --- a/addons/account_voucher/account_voucher.py +++ b/addons/account_voucher/account_voucher.py @@ -217,7 +217,7 @@ class account_voucher(osv.osv): if context.get('type', 'sale') in ('purchase', 'payment'): nodes = doc.xpath("//field[@name='partner_id']") for node in nodes: - node.set('context', "{'search_default_supplier': 1}") + node.set('context', "{'default_customer': 0, 'search_default_supplier': 1, 'default_supplier': 1}") if context.get('invoice_type','') in ('in_invoice', 'in_refund'): node.set('string', _("Supplier")) res['arch'] = etree.tostring(doc) diff --git a/addons/base_calendar/base_calendar.py b/addons/base_calendar/base_calendar.py index 6194324e183..7c5c880f8aa 100644 --- a/addons/base_calendar/base_calendar.py +++ b/addons/base_calendar/base_calendar.py @@ -28,7 +28,7 @@ from openerp.tools.translate import _ import pytz import re import time - +from operator import itemgetter from openerp import tools, SUPERUSER_ID import openerp.service.report @@ -1169,28 +1169,44 @@ rule or repeating pattern of time to exclude from the recurring rule."), (_check_closing_date, 'Error ! End date cannot be set before start date.', ['date_deadline']), ] + # TODO for trunk: remove get_recurrent_ids def get_recurrent_ids(self, cr, uid, select, domain, limit=100, context=None): + """Wrapper for _get_recurrent_ids to get the 'order' parameter from the context""" + if not context: + context = {} + order = context.get('order', self._order) + return self._get_recurrent_ids(cr, uid, select, domain, limit=limit, order=order, context=context) + + def _get_recurrent_ids(self, cr, uid, select, domain, limit=100, order=None, context=None): """Gives virtual event ids for recurring events based on value of Recurrence Rule This method gives ids of dates that comes between start date and end date of calendar views @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user's ID for security checks, - @param limit: The Number of Results to Return """ + @param limit: The Number of Results to Return + @param order: The fields (comma separated, format "FIELD {DESC|ASC}") on which the events should be sorted""" if not context: context = {} result = [] - for data in super(calendar_event, self).read(cr, uid, select, ['rrule', 'recurrency', 'exdate', 'exrule', 'date'], context=context): + result_data = [] + fields = ['rrule', 'recurrency', 'exdate', 'exrule', 'date'] + if order: + order_fields = [field.split()[0] for field in order.split(',')] + else: + # fallback on self._order defined on the model + order_fields = [field.split()[0] for field in self._order.split(',')] + fields = list(set(fields + order_fields)) + + for data in super(calendar_event, self).read(cr, uid, select, fields, context=context): if not data['recurrency'] or not data['rrule']: + result_data.append(data) result.append(data['id']) continue event_date = datetime.strptime(data['date'], "%Y-%m-%d %H:%M:%S") # TOCHECK: the start date should be replaced by event date; the event date will be changed by that of calendar code - if not data['rrule']: - continue - exdate = data['exdate'] and data['exdate'].split(',') or [] rrule_str = data['rrule'] new_rrule_str = [] @@ -1248,12 +1264,24 @@ rule or repeating pattern of time to exclude from the recurring rule."), if [True for item in new_pile if not item]: continue idval = real_id2base_calendar_id(data['id'], r_date.strftime("%Y-%m-%d %H:%M:%S")) + r_data = dict(data, id=idval, date=r_date.strftime("%Y-%m-%d %H:%M:%S")) result.append(idval) + result_data.append(r_data) + ids = list(set(result)) - if isinstance(select, (str, int, long)): - return ids and ids[0] or False - else: - ids = list(set(result)) + if order_fields: + + def comparer(left, right): + for fn, mult in comparers: + result = cmp(fn(left), fn(right)) + if result: + return mult * result + return 0 + + sort_params = [key.split()[0] if key[-4:].lower() != 'desc' else '-%s' % key.split()[0] for key in (order or self._order).split(',')] + comparers = [ ((itemgetter(col[1:]), -1) if col[0] == '-' else (itemgetter(col), 1)) for col in sort_params] + ids = [r['id'] for r in sorted(result_data, cmp=comparer)] + return ids def compute_rule_string(self, data): @@ -1377,10 +1405,13 @@ rule or repeating pattern of time to exclude from the recurring rule."), new_id = get_real_ids(arg[2]) new_arg = (arg[0], arg[1], new_id) new_args.append(new_arg) - #offset, limit and count must be treated separately as we may need to deal with virtual ids - res = super(calendar_event, self).search(cr, uid, new_args, offset=0, limit=0, order=order, context=context, count=False) if context.get('virtual_id', True): - res = self.get_recurrent_ids(cr, uid, res, args, limit, context=context) + #offset, limit, order and count must be treated separately as we may need to deal with virtual ids + res = super(calendar_event, self).search(cr, uid, new_args, offset=0, limit=0, order=None, context=context, count=False) + res = self._get_recurrent_ids(cr, uid, res, args, limit, order=order, context=context) + else: + res = super(calendar_event, self).search(cr, uid, new_args, offset=offset, limit=limit, order=order, context=context, count=count) + if count: return len(res) elif limit: diff --git a/addons/base_calendar/crm_meeting.py b/addons/base_calendar/crm_meeting.py index 66823e0b8f4..af87db1e21e 100644 --- a/addons/base_calendar/crm_meeting.py +++ b/addons/base_calendar/crm_meeting.py @@ -139,7 +139,7 @@ class mail_message(osv.osv): def _find_allowed_model_wise(self, cr, uid, doc_model, doc_dict, context=None): if doc_model == 'crm.meeting': - for virtual_id in self.pool[doc_model].get_recurrent_ids(cr, uid, doc_dict.keys(), [], context=context): + for virtual_id in self.pool[doc_model]._get_recurrent_ids(cr, uid, doc_dict.keys(), [], context=context): doc_dict.setdefault(virtual_id, doc_dict[get_real_ids(virtual_id)]) return super(mail_message, self)._find_allowed_model_wise(cr, uid, doc_model, doc_dict, context=context) diff --git a/addons/decimal_precision/decimal_precision.py b/addons/decimal_precision/decimal_precision.py index b237f053ebb..6c6453322c0 100644 --- a/addons/decimal_precision/decimal_precision.py +++ b/addons/decimal_precision/decimal_precision.py @@ -23,6 +23,7 @@ import openerp from openerp import SUPERUSER_ID from openerp import tools from openerp.osv import osv, fields +from openerp.modules.registry import RegistryManager class decimal_precision(osv.osv): _name = 'decimal.precision' @@ -44,23 +45,28 @@ class decimal_precision(osv.osv): res = cr.fetchone() return res[0] if res else 2 + def clear_cache(self, cr): + """clear cache and update models. Notify other workers to restart their registry.""" + self.precision_get.clear_cache(self) + for obj in self.pool.obj_list(): + for colname, col in self.pool.get(obj)._columns.items(): + if isinstance(col, (fields.float, fields.function)): + col.digits_change(cr) + RegistryManager.signal_registry_change(cr.dbname) + def create(self, cr, uid, data, context=None): res = super(decimal_precision, self).create(cr, uid, data, context=context) - self.precision_get.clear_cache(self) + self.clear_cache(cr) return res def unlink(self, cr, uid, ids, context=None): res = super(decimal_precision, self).unlink(cr, uid, ids, context=context) - self.precision_get.clear_cache(self) + self.clear_cache(cr) return res def write(self, cr, uid, ids, data, *args, **argv): res = super(decimal_precision, self).write(cr, uid, ids, data, *args, **argv) - self.precision_get.clear_cache(self) - for obj in self.pool.obj_list(): - for colname, col in self.pool[obj]._columns.items(): - if isinstance(col, (fields.float, fields.function)): - col.digits_change(cr) + self.clear_cache(cr) return res diff --git a/addons/mail/static/src/js/mail.js b/addons/mail/static/src/js/mail.js index 748d3d19f2d..261ab6f3b4d 100644 --- a/addons/mail/static/src/js/mail.js +++ b/addons/mail/static/src/js/mail.js @@ -1438,7 +1438,7 @@ openerp.mail = function (session) { message_fetch: function (replace_domain, replace_context, ids, callback) { return this.ds_message.call('message_read', [ // ids force to read - ids == false ? undefined : ids, + ids === false ? undefined : ids, // domain + additional (replace_domain ? replace_domain : this.domain), // ids allready loaded @@ -1812,7 +1812,7 @@ openerp.mail = function (session) { this.node.params.readonly = this.node.attrs.readonly; } - this.domain = this.node.params && this.node.params.domain || []; + this.domain = (this.node.params && this.node.params.domain) || (this.field && this.field.domain) || []; if (!this.ParentViewManager.is_action_enabled('edit')) { this.node.params.show_link = false; diff --git a/addons/mrp/procurement.py b/addons/mrp/procurement.py index c7b4b369b17..5266147fef0 100644 --- a/addons/mrp/procurement.py +++ b/addons/mrp/procurement.py @@ -121,12 +121,3 @@ class procurement_order(osv.osv): for procurement in self.browse(cr, uid, ids, context=context): body = _("Manufacturing Order %s created.") % ( procurement.production_id.name,) self.message_post(cr, uid, [procurement.id], body=body, context=context) - - -class sale_order(osv.Model): - _inherit ='sale.order' - - def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None): - result = super(sale_order, self)._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, context) - result['property_ids'] = [(6, 0, [x.id for x in line.property_ids])] - return result diff --git a/addons/sale_mrp/sale_mrp.py b/addons/sale_mrp/sale_mrp.py index f043791d0d9..ffdf0384913 100644 --- a/addons/sale_mrp/sale_mrp.py +++ b/addons/sale_mrp/sale_mrp.py @@ -88,4 +88,10 @@ class mrp_production(osv.osv): } -# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: +class sale_order(osv.Model): + _inherit ='sale.order' + + def _prepare_order_line_procurement(self, cr, uid, order, line, move_id, date_planned, context=None): + result = super(sale_order, self)._prepare_order_line_procurement(cr, uid, order, line, move_id, date_planned, context) + result['property_ids'] = [(6, 0, [x.id for x in line.property_ids])] + return result diff --git a/addons/stock/wizard/stock_partial_picking.py b/addons/stock/wizard/stock_partial_picking.py index 50ddc2b88ed..ceedb682ed8 100644 --- a/addons/stock/wizard/stock_partial_picking.py +++ b/addons/stock/wizard/stock_partial_picking.py @@ -144,7 +144,7 @@ class stock_partial_picking(osv.osv_memory): def _partial_move_for(self, cr, uid, move): partial_move = { 'product_id' : move.product_id.id, - 'quantity' : move.product_qty if move.state == 'assigned' else 0, + 'quantity' : move.product_qty if move.state == 'assigned' or move.picking_id.type == 'in' else 0, 'product_uom' : move.product_uom.id, 'prodlot_id' : move.prodlot_id.id, 'move_id' : move.id,