1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2011 Pexego (<www.pexego.es>). All Rights Reserved
6
# $Omar Castiñeira Saavedra$
8
# This program is free software: you can redistribute it and/or modify
9
# it under the terms of the GNU General Public License as published by
10
# the Free Software Foundation, either version 3 of the License, or
11
# (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# GNU General Public License for more details.
18
# You should have received a copy of the GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
23
"""inherit res.partner for adds the functionally that a partner have a location"""
25
from osv import osv, fields
27
class res_partner(osv.osv):
28
"""inherit res.partner for adds the functionally that customer has a location"""
29
_inherit = 'res.partner'
32
'create_customer_location': fields.boolean('Create customer location', help="If check creates a location if not exists for this customer to follow sent goods.")
36
'create_customer_location': lambda *a: True
39
def _set_partner_customer_location(self, cr, uid, partner_id, context=None):
40
"""creates customer location for partner in arguments"""
41
if context is None: context = {}
43
partner_id_obj = self.browse(cr, uid, partner_id)
45
#checks if already exists partner location
46
locations = self.pool.get('stock.location').search(cr, uid, [('partner_id', '=', partner_id)])
49
#creates a customer location for a specific partner if the partner is a costumer
50
partner_location_id = self.pool.get('stock.location').create(cr, uid, vals = {
51
'location_id': partner_id_obj.property_stock_customer and partner_id_obj.property_stock_customer.id or False,
52
'name':partner_id_obj.name,
54
'partner_id': partner_id,
55
'company_id': self.pool.get('res.users').browse(cr, uid, uid).company_id.id
58
#updates the property of stock customer location for partner
59
self.write(cr, uid, partner_id, vals={
60
'property_stock_customer': partner_location_id,
65
def create(self, cr, uid, vals, context=None):
66
"""Check to create customer location"""
67
if context is None: context = {}
68
partner_id = super(res_partner, self).create(cr, uid, vals, context = context)
70
if vals.get('create_customer_location', False):
71
self._set_partner_customer_location(cr, uid, partner_id, context=context)
75
def write(self, cr, uid, ids, vals, context=None):
76
"""Check to create customer location"""
77
if context is None: context = {}
78
res = super(res_partner, self).write(cr, uid, ids, vals, context = context)
80
if vals.get('create_customer_location', False):
81
if isinstance(ids, (int, long)):
84
for partner_id in ids:
85
self._set_partner_customer_location(cr, uid, partner_id, context=context)
91
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: