12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- # -*- encoding: utf-8 -*-
- from openerp import models, fields, api, tools, _
- from openerp.exceptions import Warning
- class sale_order(models.Model):
- _inherit = 'sale.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")
- credit_limit = fields.Float(string="Límite de crédito", compute="_get_partner_data")
- total_weight = fields.Float(string="Peso total", compute="_get_total_weight")
- @api.onchange('partner_id')
- def onchange_partner_id(self):
- res = super(sale_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
- self.credit_limit = partner.credit_limit
- self.user_id = partner.user_id
- self.fiscal_position = partner.property_account_position
- 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
- self.credit_limit = partner.credit_limit
- @api.one
- def _get_total_weight(self):
- total_weight = 0
- for item in self.order_line:
- order_line = self.env['sale.order.line'].search([('id','=',item.id)])
- total_weight = total_weight + order_line.th_weight
- self.total_weight = total_weight
|