1
1
# -*- encoding: utf-8 -*-
2
##############################################################################
2
#################################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
4
# Copyright (C) 2010 Renato Lima - Akretion
8
6
# This program is free software: you can redistribute it and/or modify
9
7
# it under the terms of the GNU General Public License as published by
18
16
# You should have received a copy of the GNU General Public License
19
17
# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
##############################################################################
19
#################################################################################
23
21
from osv import fields, osv
31
29
result = super(account_invoice, self).onchange_partner_id(cr, uid, ids, type, partner_id, date_invoice, payment_term, partner_bank_id, company_id)
33
if not partner_id or not company_id or not result['value']['address_invoice_id']:
36
if result['value']['fiscal_position']:
39
obj_company = self.pool.get('res.company').browse(cr, uid, [company_id])[0]
31
if not partner_id or not company_id or not result['value']['address_invoice_id'] or result['value']['fiscal_position']:
34
obj_company = self.pool.get('res.company').browse(cr, uid, company_id)
41
36
company_addr = self.pool.get('res.partner').address_get(cr, uid, [obj_company.partner_id.id], ['default'])
42
37
company_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [company_addr['default']])[0]
49
44
to_country = partner_addr_default.country_id.id
50
45
to_state = partner_addr_default.state_id.id
52
fsc_pos_id = self.pool.get('account.fiscal.position.rule').search(cr, uid, [('company_id','=',company_id), ('from_country','=',from_country),('from_state','=',from_state),('to_country','=',to_country),('to_state','=',to_state),('use_invoice','=',True)])
47
fsc_pos_id = self.pool.get('account.fiscal.position.rule').search(cr, uid, ['&',('company_id','=',company_id), ('from_country','=',from_country), ('to_country','=',to_country),('use_invoice','=',True),'|',('from_state','=',from_state),('from_state','=',False),'|',('to_state','=',to_state),('to_state','=',False)])
55
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').browse(cr, uid, fsc_pos_id)[0]
56
result['value']['fiscal_position'] = obj_fpo_rule.fiscal_position_id.id
50
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').read(cr, uid, fsc_pos_id,['fiscal_position_id'])
51
result['value']['fiscal_position'] = obj_fpo_rule[0]['fiscal_position_id']
64
59
if not part_id or not company_id or not ptn_invoice_id:
67
obj_company = self.pool.get('res.company').browse(cr, uid, [company_id])[0]
62
obj_partner = self.pool.get('res.partner').browse(cr, uid, part_id)
63
if obj_partner.property_account_position:
64
result['value']['fiscal_position'] = obj_partner.property_account_position.id
67
obj_company = self.pool.get('res.company').browse(cr, uid, company_id)
69
69
company_addr = self.pool.get('res.partner').address_get(cr, uid, [obj_company.partner_id.id], ['default'])
70
70
company_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [company_addr['default']])[0]
77
77
to_country = partner_addr_invoice.country_id.id
78
78
to_state = partner_addr_invoice.state_id.id
80
fsc_pos_id = self.pool.get('account.fiscal.position.rule').search(cr, uid, [('company_id','=', company_id), ('from_country','=',from_country),('from_state','=',from_state),('to_country','=',to_country),('to_state','=',to_state),('use_invoice','=',True)])
80
fsc_pos_id = self.pool.get('account.fiscal.position.rule').search(cr, uid, ['&',('company_id','=', company_id),('from_country','=',from_country),('to_country','=',to_country),('use_invoice','=',True),'|',('from_state','=',from_state),('from_state','=',False),'|',('to_state','=',to_state),('to_state','=',False)])
83
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').browse(cr, uid, fsc_pos_id)[0]
84
result['value']['fiscal_position'] = obj_fpo_rule.fiscal_position_id.id
83
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').read(cr, uid, fsc_pos_id, ['fiscal_position_id'])
84
result['value']['fiscal_position'] = obj_fpo_rule[0]['fiscal_position_id']
90
90
result = {'value': {'fiscal_position': False}}
92
if not ptn_id or not cpy_id or not ptn_invoice_id:
95
if result['value']['fiscal_position']:
98
obj_company = self.pool.get('res.company').browse(cr, uid, [cpy_id])[0]
92
if not ptn_id or not cpy_id or not ptn_invoice_id or result['value']['fiscal_position']:
95
obj_partner = self.pool.get('res.partner').browse(cr, uid, ptn_id)
96
if obj_partner.property_account_position:
97
result['value']['fiscal_position'] = obj_partner.property_account_position.id
100
obj_company = self.pool.get('res.company').browse(cr, uid, cpy_id)
100
102
company_addr = self.pool.get('res.partner').address_get(cr, uid, [obj_company.partner_id.id], ['default'])
101
103
company_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [company_addr['default']])[0]
103
105
from_country = company_addr_default.country_id.id
104
106
from_state = company_addr_default.state_id.id
106
partner_addr_invoice = self.pool.get('res.partner.address').browse(cr, uid, [ptn_invoice_id])[0]
108
partner_addr_invoice = self.pool.get('res.partner.address').browse(cr, uid, ptn_invoice_id)
108
110
to_country = partner_addr_invoice.country_id.id
109
111
to_state = partner_addr_invoice.state_id.id
111
fsc_pos_id = self.pool.get('account.fiscal.position.rule').search(cr, uid, [('company_id','=', cpy_id), ('from_country','=',from_country),('from_state','=',from_state),('to_country','=',to_country),('to_state','=',to_state),('use_invoice','=',True)])
113
fsc_pos_id = self.pool.get('account.fiscal.position.rule').search(cr, uid, ['&',('company_id','=', cpy_id), ('from_country','=',from_country),('to_country','=',to_country),('use_invoice','=',True),'|',('from_state','=',from_state),('from_state','=',False),'|',('to_state','=',to_state),('to_state','=',False)])
114
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').browse(cr, uid, fsc_pos_id)[0]
115
result['value']['fiscal_position'] = obj_fpo_rule.fiscal_position_id.id
116
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').read(cr, uid, fsc_pos_id,['fiscal_position_id'])
117
result['value']['fiscal_position'] = obj_fpo_rule[0]['fiscal_position_id']
119
121
account_invoice()