test_product_template.py 917 B

123456789101112131415161718192021222324252627
  1. from odoo.tests.common import TransactionCase
  2. class TestProductTemplate(TransactionCase):
  3. def test_name_search(self):
  4. partner = self.env['res.partner'].create({
  5. 'name': 'Azure Interior',
  6. })
  7. seller = self.env['product.supplierinfo'].create({
  8. 'partner_id': partner.id,
  9. 'price': 12.0,
  10. 'delay': 1,
  11. 'product_code': 'VOB2a',
  12. })
  13. product_tmpl = self.env['product.template'].create({
  14. 'name': 'Rubber Duck',
  15. 'type': 'product',
  16. 'default_code': 'VOB2A',
  17. 'seller_ids': [seller.id],
  18. 'purchase_ok': True,
  19. })
  20. ns = self.env['product.template'].with_context(partner_id=partner.id).name_search('VOB2', [['purchase_ok', '=', True]])
  21. self.assertEqual(len(ns), 1, "name_search should have 1 item")
  22. self.assertEqual(ns[0][1], '[VOB2A] Rubber Duck', "name_search should return the expected result")