You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
1.2 KiB

  1. # Copyright 2018 Creu Blanca
  2. # Copyright 2018 Eficent Business and IT Consulting Services, S.L.
  3. # License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
  4. import json
  5. from odoo import api, models, _
  6. from odoo.tools.safe_eval import safe_eval
  7. class ResPartner(models.Model):
  8. _inherit = 'res.partner'
  9. @api.multi
  10. def find_res_partner_by_ref_using_barcode(self, barcode):
  11. partner = self.search([('ref', '=', barcode)], limit=1)
  12. if not partner:
  13. action = self.env.ref('res_partner_find')
  14. result = action.read()[0]
  15. context = safe_eval(result['context'])
  16. context.update({
  17. 'default_state': 'warning',
  18. 'default_status': _('Partner with Internal Reference '
  19. '%s cannot be found') % barcode
  20. })
  21. result['context'] = json.dumps(context)
  22. return result
  23. action = self.env.ref('base.action_partner_form')
  24. result = action.read()[0]
  25. res = self.env.ref('base.view_partner_form', False)
  26. result['views'] = [(res and res.id or False, 'form')]
  27. result['res_id'] = partner.id
  28. return result