sale_order.py 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- encoding: utf-8 -*-
  2. from openerp import models, fields, api, tools, _
  3. from openerp.exceptions import Warning
  4. class sale_order(models.Model):
  5. _inherit = 'sale.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. credit_limit = fields.Float(string="Límite de crédito", compute="_get_partner_data")
  14. total_weight = fields.Float(string="Peso total", compute="_get_total_weight")
  15. @api.onchange('partner_id')
  16. def onchange_partner_id(self):
  17. res = super(sale_order, self).onchange_partner_id(self.partner_id.id)
  18. if type(res) is dict and res.has_key('value'):
  19. for field, value in res.get('value').items():
  20. if hasattr(self, field):
  21. setattr(self, field, value)
  22. if self.partner_id:
  23. domain = [('id', '=', self.partner_id.id)]
  24. partner = self.env['res.partner'].search(domain)
  25. self.ruc = partner.ruc
  26. self.street = partner.street
  27. self.state_id = partner.state_id and partner.state_id.id or False
  28. self.country_id = partner.country_id and partner.country_id.id or False
  29. self.email = partner.email
  30. self.phone = partner.phone
  31. self.mobile = partner.mobile
  32. self.credit_limit = partner.credit_limit
  33. return res
  34. @api.one
  35. def _get_partner_data(self):
  36. domain = [('id', '=', self.partner_id.id)]
  37. partner = self.env['res.partner'].search(domain)
  38. self.ruc = partner.ruc
  39. self.street = partner.street
  40. self.state_id = partner.state_id and partner.state_id.id or False
  41. self.country_id = partner.country_id and partner.country_id.id or False
  42. self.email = partner.email
  43. self.phone = partner.phone
  44. self.mobile = partner.mobile
  45. self.credit_limit = partner.credit_limit
  46. @api.one
  47. def _get_total_weight(self):
  48. total_weight = 0
  49. for item in self.order_line:
  50. order_line = self.env['sale.order.line'].search([('id','=',item.id)])
  51. total_weight = total_weight + order_line.th_weight
  52. self.total_weight = total_weight