sale_order.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. self.user_id = partner.user_id
  34. self.fiscal_position = partner.property_account_position
  35. return res
  36. @api.one
  37. def _get_partner_data(self):
  38. domain = [('id', '=', self.partner_id.id)]
  39. partner = self.env['res.partner'].search(domain)
  40. self.ruc = partner.ruc
  41. self.street = partner.street
  42. self.state_id = partner.state_id and partner.state_id.id or False
  43. self.country_id = partner.country_id and partner.country_id.id or False
  44. self.email = partner.email
  45. self.phone = partner.phone
  46. self.mobile = partner.mobile
  47. self.credit_limit = partner.credit_limit
  48. @api.one
  49. def _get_total_weight(self):
  50. total_weight = 0
  51. for item in self.order_line:
  52. order_line = self.env['sale.order.line'].search([('id','=',item.id)])
  53. total_weight = total_weight + order_line.th_weight
  54. self.total_weight = total_weight