network_partner
This commit is contained in:
parent
cf798a996b
commit
d2ac963ee1
15 changed files with 437 additions and 1 deletions
4
network_partner/models/__init__.py
Normal file
4
network_partner/models/__init__.py
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
from . import res_partner
|
||||
from . import partner_node
|
||||
from . import partner_network
|
||||
|
||||
19
network_partner/models/partner_network.py
Normal file
19
network_partner/models/partner_network.py
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
#import logging
|
||||
|
||||
from odoo import models, fields, api
|
||||
|
||||
#_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PartnerNetwork(models.Model):
|
||||
_name = 'partner.network'
|
||||
#_inherit = 'mail.thread'
|
||||
_description = 'A network of nodes.'
|
||||
|
||||
name = fields.Char(string="Nombre", help="El nombre de la red.")
|
||||
#Fields
|
||||
#network_partner_id = fields.Many2one('res.partner', required=True, ondelete='restrict')
|
||||
#'groups_id': fields.many2many('res.groups', 'res_groups_users_rel', 'uid', 'gid', 'Groups'),
|
||||
#member_id = fields.Many2many('res.partner', 'res_partner_network_rel', 'uid', 'nid', "Partners" )
|
||||
|
||||
|
||||
79
network_partner/models/partner_node.py
Normal file
79
network_partner/models/partner_node.py
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
#import logging
|
||||
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
#_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class PartnerNode(models.Model):
|
||||
_name = 'partner.node'
|
||||
_inherit = 'res.partner'
|
||||
_description = 'A node of partners in a network'
|
||||
|
||||
network_id = fields.Many2one('network.partner', string="Red", help="La red a la que pertenece el nodo.")
|
||||
partner_ids = fields.One2many('res.partner', 'node_id', string='Contactos del nodo', help='Los contactos asociados a éste nodo.')
|
||||
|
||||
"""
|
||||
name = fields.Char(related='partner_id.name', string='Node Name', required=True, store=True, readonly=False)
|
||||
partner_id = fields.Many2one('res.partner',
|
||||
string="Contacto asociado",
|
||||
help="El contacto asociado del nodo con sus datos como la dirección",
|
||||
required=True
|
||||
)
|
||||
#street = fields.Char(compute='_compute_address', inverse='_inverse_street')
|
||||
#street2 = fields.Char(compute='_compute_address', inverse='_inverse_street2')
|
||||
#zip = fields.Char(compute='_compute_address', inverse='_inverse_zip')
|
||||
#city = fields.Char(compute='_compute_address', inverse='_inverse_city')
|
||||
#state_id = fields.Many2one('res.country.state', compute='_compute_address', inverse='_inverse_state', string="Fed. State")
|
||||
#country_id = fields.Many2one('res.country', compute='_compute_address', inverse='_inverse_country', string="Country")
|
||||
street = fields.Char(related='partner_id.street', store=True, readonly=False)
|
||||
street2 = fields.Char(related='partner_id.street2', store=True, readonly=False)
|
||||
zip = fields.Char(related='partner_id.zip', store=True, readonly=False)
|
||||
city = fields.Char(related='partner_id.city', store=True, readonly=False)
|
||||
#state_id = fields.Char(related='partner_id.state_id', store=True, readonly=False)
|
||||
#country_id = fields.Char(related='partner_id.country_id', store=True, readonly=False)
|
||||
email = fields.Char(related='partner_id.email', store=True, readonly=False)
|
||||
phone = fields.Char(related='partner_id.phone', store=True, readonly=False)
|
||||
|
||||
def _get_company_address_fields(self, partner):
|
||||
return {
|
||||
'street' : partner.street,
|
||||
'street2' : partner.street2,
|
||||
'city' : partner.city,
|
||||
'zip' : partner.zip,
|
||||
'state_id' : partner.state_id,
|
||||
'country_id' : partner.country_id,
|
||||
}
|
||||
|
||||
def _compute_address(self):
|
||||
for node in self.filtered(lambda node: node.partner_id):
|
||||
address_data = node.partner_id.sudo().address_get(adr_pref=['contact'])
|
||||
if address_data['contact']:
|
||||
partner = node.partner_id.browse(address_data['contact']).sudo()
|
||||
node.update(node._get_company_address_fields(partner))
|
||||
|
||||
def _inverse_street(self):
|
||||
for company in self:
|
||||
company.partner_id.street = company.street
|
||||
|
||||
def _inverse_street2(self):
|
||||
for company in self:
|
||||
company.partner_id.street2 = company.street2
|
||||
|
||||
def _inverse_zip(self):
|
||||
for company in self:
|
||||
company.partner_id.zip = company.zip
|
||||
|
||||
def _inverse_city(self):
|
||||
for company in self:
|
||||
company.partner_id.city = company.city
|
||||
|
||||
def _inverse_state(self):
|
||||
for company in self:
|
||||
company.partner_id.state_id = company.state_id
|
||||
|
||||
def _inverse_country(self):
|
||||
for company in self:
|
||||
company.partner_id.country_id = company.country_id
|
||||
"""
|
||||
14
network_partner/models/res_partner.py
Normal file
14
network_partner/models/res_partner.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#import logging
|
||||
|
||||
from odoo import models, fields, api
|
||||
|
||||
|
||||
#_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class ResPartner(models.Model):
|
||||
_inherit = 'res.partner'
|
||||
#'users': fields.many2many('res.users', 'res_groups_users_rel', 'gid', 'uid', 'Users'),
|
||||
node_id = fields.Many2one('partner.node', string="Nodo")
|
||||
is_node = fields.Boolean(string="Es un nodo", help="Éste partner representa un nodo en una red.")
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue