123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- # -*- encoding: utf-8 -*-
- from openerp import models, fields, api, tools, _
- from openerp.exceptions import Warning
- class purchase_order(models.Model):
- _inherit = 'purchase.order'
- ruc = fields.Char(string="Cédula/R.U.C", compute="_get_partner_data")
- street = fields.Char(string="Dirección", compute="_get_partner_data")
- state_id = fields.Many2one('res.country.state',string="Departamento", compute="_get_partner_data")
- country_id = fields.Many2one('res.country',string="País", compute="_get_partner_data")
- email = fields.Char(string="Email", compute="_get_partner_data")
- phone = fields.Char(string="Teléfono", compute="_get_partner_data")
- mobile = fields.Char(string="Celular", compute="_get_partner_data")
- @api.onchange('partner_id')
- def onchange_partner_id(self):
- res = super(purchase_order, self).onchange_partner_id(self.partner_id.id)
- if type(res) is dict and res.has_key('value'):
- for field, value in res.get('value').items():
- if hasattr(self, field):
- setattr(self, field, value)
- if self.partner_id:
- domain = [('id', '=', self.partner_id.id)]
- partner = self.env['res.partner'].search(domain)
- self.ruc = partner.ruc
- self.street = partner.street
- self.state_id = partner.state_id and partner.state_id.id or False
- self.country_id = partner.country_id and partner.country_id.id or False
- self.email = partner.email
- self.phone = partner.phone
- self.mobile = partner.mobile
- if self.partner_id.supplier_type == 'exterior':
- msj = {
- 'warning':{
- 'title': "Atención",
- 'message': "El proveedor seleccionado es del exterior"
- }
- }
- return msj
- return res
- @api.one
- def _get_partner_data(self):
- domain = [('id', '=', self.partner_id.id)]
- partner = self.env['res.partner'].search(domain)
- self.ruc = partner.ruc
- self.street = partner.street
- self.state_id = partner.state_id and partner.state_id.id or False
- self.country_id = partner.country_id and partner.country_id.id or False
- self.email = partner.email
- self.phone = partner.phone
- self.mobile = partner.mobile
|