account_invoice.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, fields, api, tools, _
  3. from openerp.exceptions import Warning
  4. class account_invoice(models.Model):
  5. _inherit = 'account.invoice'
  6. street = fields.Char(string="Calle", compute="_get_partner_data")
  7. state_id = fields.Many2one('res.country.state',string="Departamento", compute="_get_partner_data")
  8. country_id = fields.Many2one('res.country',string="País", compute="_get_partner_data")
  9. email = fields.Char(string="Email", compute="_get_partner_data")
  10. phone = fields.Char(string="Teléfono", compute="_get_partner_data")
  11. mobile = fields.Char(string="Celular", compute="_get_partner_data")
  12. credit_limit = fields.Float(string="Límite de crédito", compute="_get_partner_data")
  13. @api.onchange('partner_id')
  14. def onchange_partner_id(self):
  15. res = super(account_invoice, self).onchange_partner_id(self.type, self.partner_id.id, self.date_invoice,self.payment_term, self.partner_bank_id.id, self.company_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.street = partner.street
  24. self.state_id = partner.state_id and partner.state_id.id or False
  25. self.country_id = partner.country_id and partner.country_id.id or False
  26. self.email = partner.email
  27. self.phone = partner.phone
  28. self.mobile = partner.mobile
  29. self.credit_limit = partner.credit_limit
  30. return res
  31. @api.one
  32. def _get_partner_data(self):
  33. domain = [('id', '=', self.partner_id.id)]
  34. partner = self.env['res.partner'].search(domain)
  35. self.street = partner.street
  36. self.state_id = partner.state_id and partner.state_id.id or False
  37. self.country_id = partner.country_id and partner.country_id.id or False
  38. self.email = partner.email
  39. self.phone = partner.phone
  40. self.mobile = partner.mobile
  41. self.credit_limit = partner.credit_limit