1
# -*- encoding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Open Source Management Solution
5
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
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
from osv import fields, osv
25
class account_invoice(osv.osv):
26
_inherit = 'account.invoice'
28
def onchange_partner_id(self, cr, uid, ids, type, partner_id,
29
date_invoice=False, payment_term=False,company_id=False, partner_bank_id=False ):
31
result = super(account_invoice, self).onchange_partner_id(cr,uid,ids,type,partner_id,date_invoice,payment_term,partner_bank_id)
33
if not partner_id or not company_id:
36
if result['value']['fiscal_position']:
39
obj_company = self.pool.get('res.company').browse(cr, uid, [company_id])[0]
41
company_addr = self.pool.get('res.partner').address_get(cr, uid, [obj_company.partner_id.id], ['default'])
42
company_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [company_addr['default']])[0]
44
from_country = company_addr_default.country_id.id
45
from_state = company_addr_default.state_id.id
47
if result['value']['address_invoice_id']:
48
ptn_invoice_id = result['value']['address_invoice_id']
50
partner_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [ptn_invoice_id])[0]
52
to_country = partner_addr_default.country_id.id
53
to_state = partner_addr_default.state_id.id
55
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)])
58
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').browse(cr, uid, fsc_pos_id)[0]
59
result['value']['fiscal_position'] = obj_fpo_rule.fiscal_position_id.id
63
def onchange_company_id(self, cr, uid, ids, cpy_id, ptn_id, ptn_invoice_id):
65
result = {'value': {'fiscal_position': False}}
67
if not ptn_id or not cpy_id or not ptn_invoice_id:
70
if result['value']['fiscal_position']:
73
obj_company = self.pool.get('res.company').browse(cr, uid, [cpy_id])[0]
75
company_addr = self.pool.get('res.partner').address_get(cr, uid, [obj_company.partner_id.id], ['default'])
76
company_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [company_addr['default']])[0]
78
from_country = company_addr_default.country_id.id
79
from_state = company_addr_default.state_id.id
81
partner_addr_invoice = self.pool.get('res.partner.address').browse(cr, uid, [ptn_invoice_id])[0]
83
to_country = partner_addr_invoice.country_id.id
84
to_state = partner_addr_invoice.state_id.id
86
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)])
89
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').browse(cr, uid, fsc_pos_id)[0]
90
result['value']['fiscal_position'] = obj_fpo_rule.fiscal_position_id.id
94
def onchange_address_invoice_id(self, cr, uid, ids, cpy_id, ptn_id, ptn_invoice_id):
96
result = {'value': {'fiscal_position': False}}
98
if not ptn_id or not cpy_id or not ptn_invoice_id:
101
if result['value']['fiscal_position']:
104
obj_company = self.pool.get('res.company').browse(cr, uid, [cpy_id])[0]
106
company_addr = self.pool.get('res.partner').address_get(cr, uid, [obj_company.partner_id.id], ['default'])
107
company_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [company_addr['default']])[0]
109
from_country = company_addr_default.country_id.id
110
from_state = company_addr_default.state_id.id
112
partner_addr_invoice = self.pool.get('res.partner.address').browse(cr, uid, [ptn_invoice_id])[0]
114
to_country = partner_addr_invoice.country_id.id
115
to_state = partner_addr_invoice.state_id.id
117
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)])
120
obj_fpo_rule = self.pool.get('account.fiscal.position.rule').browse(cr, uid, fsc_pos_id)[0]
121
result['value']['fiscal_position'] = obj_fpo_rule.fiscal_position_id.id
b'\\ No newline at end of file'