[MERGE] forward port of branch saas-3 up to e1e7dc0
authorChristophe Simonis <chs@odoo.com>
Mon, 1 Dec 2014 14:42:51 +0000 (15:42 +0100)
committerChristophe Simonis <chs@odoo.com>
Mon, 1 Dec 2014 14:42:51 +0000 (15:42 +0100)
1  2 
addons/account/account_invoice.py
addons/marketing_campaign/__openerp__.py
addons/product/product.py
addons/product/product_view.xml
addons/web/static/src/js/view_list.js
openerp/addons/base/res/res_bank.py
openerp/addons/base/res/res_partner.py

@@@ -1615,12 -1816,12 +1615,12 @@@ class account_invoice_tax(models.Model)
          return res
  
  
 -class res_partner(osv.osv):
 -    """ Inherits partner and adds invoice information in the partner form """
 +class res_partner(models.Model):
 +    # Inherits partner and adds invoice information in the partner form
      _inherit = 'res.partner'
 -    _columns = {
 -        'invoice_ids': fields.one2many('account.invoice.line', 'partner_id', 'Invoices', readonly=True),
 -    }
 +
 +    invoice_ids = fields.One2many('account.invoice', 'partner_id', string='Invoices',
-         readonly=True)
++        readonly=True, copy=False)
  
      def _find_accounting_partner(self, partner):
          '''
@@@ -179,14 -178,9 +180,11 @@@ class product_uom(osv.osv)
                  raise osv.except_osv(_('Error!'), _('Conversion from Product UoM %s to Default UoM %s is not possible as they both belong to different Category!.') % (from_unit.name,to_unit.name,))
              else:
                  return qty
-         # First round to the precision of the original unit, so that
-         # float representation errors do not bias the following ceil()
-         # e.g. with 1 / (1/12) we could get 12.0000048, ceiling to 13! 
-         amount = float_round(qty/from_unit.factor, precision_rounding=from_unit.rounding)
+         amount = qty/from_unit.factor
          if to_unit:
 -            amount = ceiling(amount * to_unit.factor, to_unit.rounding)
 +            amount = amount * to_unit.factor
 +            if round:
 +                amount = ceiling(amount, to_unit.rounding)
          return amount
  
      def _compute_price(self, cr, uid, from_uom_id, price, to_uom_id=False):
Simple merge
Simple merge
Simple merge
@@@ -524,44 -524,38 +524,52 @@@ class res_partner(osv.Model, format_add
              if not parent.is_company:
                  parent.write({'is_company': True})
  
+     def unlink(self, cr, uid, ids, context=None):
+         orphan_contact_ids = self.search(cr, uid,
+             [('parent_id', 'in', ids), ('id', 'not in', ids), ('use_parent_address', '=', True)], context=context)
+         if orphan_contact_ids:
+             # no longer have a parent address
+             self.write(cr, uid, orphan_contact_ids, {'use_parent_address': False}, context=context)
+         return super(res_partner, self).unlink(cr, uid, ids, context=context)
 -    def write(self, cr, uid, ids, vals, context=None):
 -        if isinstance(ids, (int, long)):
 -            ids = [ids]
 -        #res.partner must only allow to set the company_id of a partner if it
 -        #is the same as the company of all users that inherit from this partner
 -        #(this is to allow the code from res_users to write to the partner!) or
 -        #if setting the company_id to False (this is compatible with any user company)
 +    def _clean_website(self, website):
 +        (scheme, netloc, path, params, query, fragment) = urlparse.urlparse(website)
 +        if not scheme:
 +            if not netloc:
 +                netloc, path = path, ''
 +            website = urlparse.urlunparse(('http', netloc, path, params, query, fragment))
 +        return website
 +
 +    @api.multi
 +    def write(self, vals):
 +        # res.partner must only allow to set the company_id of a partner if it
 +        # is the same as the company of all users that inherit from this partner
 +        # (this is to allow the code from res_users to write to the partner!) or
 +        # if setting the company_id to False (this is compatible with any user
 +        # company)
 +        if vals.get('website'):
 +            vals['website'] = self._clean_website(vals['website'])
          if vals.get('company_id'):
 -            for partner in self.browse(cr, uid, ids, context=context):
 +            company = self.env['res.company'].browse(vals['company_id'])
 +            for partner in self:
                  if partner.user_ids:
 -                    user_companies = set([user.company_id.id for user in partner.user_ids])
 -                    if len(user_companies) > 1 or vals['company_id'] not in user_companies:
 +                    companies = set(user.company_id for user in partner.user_ids)
 +                    if len(companies) > 1 or company not in companies:
                          raise osv.except_osv(_("Warning"),_("You can not change the company as the partner/user has multiple user linked with different companies."))
 -        result = super(res_partner,self).write(cr, uid, ids, vals, context=context)
 -        for partner in self.browse(cr, uid, ids, context=context):
 -            self._fields_sync(cr, uid, partner, vals, context)
 +
 +        result = super(res_partner, self).write(vals)
 +        for partner in self:
 +            self._fields_sync(partner, vals)
          return result
  
 -    def create(self, cr, uid, vals, context=None):
 -        new_id = super(res_partner, self).create(cr, uid, vals, context=context)
 -        partner = self.browse(cr, uid, new_id, context=context)
 -        self._fields_sync(cr, uid, partner, vals, context)
 -        self._handle_first_contact_creation(cr, uid, partner, context)
 -        return new_id
 +    @api.model
 +    def create(self, vals):
 +        if vals.get('website'):
 +            vals['website'] = self._clean_website(vals['website'])
 +        partner = super(res_partner, self).create(vals)
 +        self._fields_sync(partner, vals)
 +        self._handle_first_contact_creation(partner)
 +        return partner
  
      def open_commercial_entity(self, cr, uid, ids, context=None):
          """ Utility method used to add an "Open Company" button in partner views """