purchase_order.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, fields, api, tools, _
  3. from openerp.exceptions import Warning
  4. class purchase_order(models.Model):
  5. _inherit = 'purchase.order'
  6. ruc = fields.Char(string="Cédula/R.U.C", compute="_get_partner_data")
  7. street = fields.Char(string="Dirección", compute="_get_partner_data")
  8. state_id = fields.Many2one('res.country.state',string="Departamento", compute="_get_partner_data")
  9. country_id = fields.Many2one('res.country',string="País", compute="_get_partner_data")
  10. email = fields.Char(string="Email", compute="_get_partner_data")
  11. phone = fields.Char(string="Teléfono", compute="_get_partner_data")
  12. mobile = fields.Char(string="Celular", compute="_get_partner_data")
  13. @api.onchange('partner_id')
  14. def onchange_partner_id(self):
  15. res = super(purchase_order, self).onchange_partner_id(self.partner_id.id)
  16. if type(res) is dict and res.has_key('value'):
  17. for field, value in res.get('value').items():
  18. if hasattr(self, field):
  19. setattr(self, field, value)
  20. if self.partner_id:
  21. domain = [('id', '=', self.partner_id.id)]
  22. partner = self.env['res.partner'].search(domain)
  23. self.ruc = partner.ruc
  24. self.street = partner.street
  25. self.state_id = partner.state_id and partner.state_id.id or False
  26. self.country_id = partner.country_id and partner.country_id.id or False
  27. self.email = partner.email
  28. self.phone = partner.phone
  29. self.mobile = partner.mobile
  30. if self.partner_id.supplier_type == 'exterior':
  31. msj = {
  32. 'warning':{
  33. 'title': "Atención",
  34. 'message': "El proveedor seleccionado es del exterior"
  35. }
  36. }
  37. return msj
  38. return res
  39. @api.one
  40. def _get_partner_data(self):
  41. domain = [('id', '=', self.partner_id.id)]
  42. partner = self.env['res.partner'].search(domain)
  43. self.ruc = partner.ruc
  44. self.street = partner.street
  45. self.state_id = partner.state_id and partner.state_id.id or False
  46. self.country_id = partner.country_id and partner.country_id.id or False
  47. self.email = partner.email
  48. self.phone = partner.phone
  49. self.mobile = partner.mobile