product.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- encoding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU Affero General Public License as published
  6. # by the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see http://www.gnu.org/licenses/.
  16. #
  17. ##############################################################################
  18. from openerp import models, api
  19. class ProductTemplate(models.Model):
  20. _inherit = 'product.template'
  21. @api.multi
  22. def write(self, vals):
  23. res = {}
  24. for product_tmpl in self:
  25. write_vals = {}
  26. if 'uom_po_id' in vals:
  27. write_vals['uom_po_id'] = vals.pop("uom_po_id", None)
  28. write_vals['uom_id'] = vals.pop("uom_id", None)
  29. if vals:
  30. res = super(ProductTemplate, self).write(vals)
  31. if write_vals:
  32. product_obj = self.env['product.product']
  33. st_mv_obj = self.env['stock.move']
  34. product_lst = product_obj.search([('product_tmpl_id', '=',
  35. product_tmpl.id)])
  36. if not st_mv_obj.search([('product_id', 'in',
  37. product_lst.ids)]):
  38. models.Model.write(self, write_vals)
  39. else:
  40. res = super(ProductTemplate, self).write(write_vals)
  41. return res