attribute.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. # coding: utf-8
  2. # © 2016 David BEAL @ Akretion <david.beal@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. import logging
  5. from openerp import api, models
  6. _logger = logging.getLogger(__name__)
  7. class ProductAttributeValue(models.Model):
  8. _inherit = 'product.attribute.value'
  9. @api.multi
  10. def write(self, vals):
  11. """ Attribute Values update impact products: we take care
  12. to propagate changes on attribute_str field"""
  13. res = super(ProductAttributeValue, self).write(vals)
  14. if 'name' in vals:
  15. sql = """SELECT prod_id
  16. FROM product_attribute_value_product_product_rel
  17. WHERE att_id = %s""" % self.id
  18. self._cr.execute(sql)
  19. product_ids = self._cr.fetchall() # [(99999), (...)]
  20. if product_ids:
  21. product_ids = [x[0] for x in product_ids]
  22. products = self.env['product.product'].browse(product_ids)
  23. _logger.debug(" >>> '%s' products to update after attribute "
  24. "('%s') modified" % (len(product_ids), self.id))
  25. products._compute_attrib_str_after_attrib_value_change()
  26. _logger.debug(" >>> '%s' products update done")
  27. return res