diff --git a/addons/sale/sale.py b/addons/sale/sale.py index ed7a2835425..9ba6c43a588 100644 --- a/addons/sale/sale.py +++ b/addons/sale/sale.py @@ -201,6 +201,7 @@ class sale_order(osv.osv): help="""This field controls how invoice and delivery operations are synchronized. - With 'Before Delivery', a draft invoice is created, and it must be paid before delivery."""), 'pricelist_id': fields.many2one('product.pricelist', 'Pricelist', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Pricelist for current sales order."), + 'currency_id': fields.related('pricelist_id', 'currency_id', type="many2one", relation="res.currency", readonly=True, required=True), 'project_id': fields.many2one('account.analytic.account', 'Contract/Analytic Account', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="The analytic account related to a sales order."), 'order_line': fields.one2many('sale.order.line', 'order_id', 'Order Lines', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}), @@ -264,13 +265,18 @@ class sale_order(osv.osv): return osv.osv.unlink(self, cr, uid, unlink_ids, context=context) def onchange_pricelist_id(self, cr, uid, ids, pricelist_id, order_lines, context=None): - if (not pricelist_id) or (not order_lines): + if not pricelist_id: return {} + value = { + 'currency_id': self.pool.get('product.pricelist').browse(cr, uid, pricelist_id, context=context).currency_id.id + } + if not order_lines: + return {'value': value} warning = { 'title': _('Pricelist Warning!'), 'message' : _('If you change the pricelist of this order (and eventually the currency), prices of existing order lines will not be updated.') } - return {'warning': warning} + return {'warning': warning, 'value': value} def onchange_partner_id(self, cr, uid, ids, part): if not part: diff --git a/addons/sale/sale_view.xml b/addons/sale/sale_view.xml index a9ebca876a9..8b89e8047cb 100644 --- a/addons/sale/sale_view.xml +++ b/addons/sale/sale_view.xml @@ -184,6 +184,7 @@ + @@ -261,14 +262,14 @@ - - + + - + diff --git a/addons/sale_margin/sale_margin_view.xml b/addons/sale_margin/sale_margin_view.xml index 69f49bd48ea..6aa34bae26c 100644 --- a/addons/sale_margin/sale_margin_view.xml +++ b/addons/sale_margin/sale_margin_view.xml @@ -11,7 +11,7 @@