~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to account_fiscal_position_rule/invoice.py

  • Committer: Renato Lima
  • Date: 2010-07-23 13:30:48 UTC
  • Revision ID: renato@renato-laptop-20100723133048-i1eg8cowzjfzgwd5
Added new module account_fiscal_position_rule

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import fields, osv
 
24
 
 
25
class account_invoice(osv.osv):
 
26
    _inherit = 'account.invoice'
 
27
 
 
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 ):
 
30
 
 
31
        result = super(account_invoice, self).onchange_partner_id(cr,uid,ids,type,partner_id,date_invoice,payment_term,partner_bank_id)
 
32
 
 
33
        if not partner_id or not company_id:
 
34
            return result
 
35
 
 
36
        if result['value']['fiscal_position']:
 
37
            return result
 
38
 
 
39
        obj_company = self.pool.get('res.company').browse(cr, uid, [company_id])[0]
 
40
 
 
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]
 
43
 
 
44
        from_country = company_addr_default.country_id.id
 
45
        from_state = company_addr_default.state_id.id
 
46
 
 
47
        if result['value']['address_invoice_id']:
 
48
            ptn_invoice_id = result['value']['address_invoice_id']
 
49
 
 
50
        partner_addr_default = self.pool.get('res.partner.address').browse(cr, uid, [ptn_invoice_id])[0]
 
51
 
 
52
        to_country = partner_addr_default.country_id.id
 
53
        to_state = partner_addr_default.state_id.id
 
54
 
 
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)])
 
56
        
 
57
        if fsc_pos_id:
 
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
 
60
 
 
61
        return result
 
62
    
 
63
    def onchange_company_id(self, cr, uid, ids, cpy_id, ptn_id, ptn_invoice_id):
 
64
         
 
65
        result = {'value': {'fiscal_position': False}}
 
66
        
 
67
        if not ptn_id or not cpy_id or not ptn_invoice_id:
 
68
            return result
 
69
        
 
70
        if result['value']['fiscal_position']:
 
71
            return result
 
72
        
 
73
        obj_company = self.pool.get('res.company').browse(cr, uid, [cpy_id])[0]
 
74
        
 
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]
 
77
        
 
78
        from_country = company_addr_default.country_id.id
 
79
        from_state = company_addr_default.state_id.id
 
80
 
 
81
        partner_addr_invoice = self.pool.get('res.partner.address').browse(cr, uid, [ptn_invoice_id])[0]
 
82
 
 
83
        to_country = partner_addr_invoice.country_id.id
 
84
        to_state = partner_addr_invoice.state_id.id
 
85
 
 
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)])
 
87
        
 
88
        if fsc_pos_id:
 
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
 
91
       
 
92
        return result   
 
93
    
 
94
    def onchange_address_invoice_id(self, cr, uid, ids, cpy_id, ptn_id, ptn_invoice_id):
 
95
 
 
96
        result = {'value': {'fiscal_position': False}}
 
97
        
 
98
        if not ptn_id or not cpy_id or not ptn_invoice_id:
 
99
            return result
 
100
        
 
101
        if result['value']['fiscal_position']:
 
102
            return result
 
103
        
 
104
        obj_company = self.pool.get('res.company').browse(cr, uid, [cpy_id])[0]
 
105
        
 
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]
 
108
        
 
109
        from_country = company_addr_default.country_id.id
 
110
        from_state = company_addr_default.state_id.id
 
111
 
 
112
        partner_addr_invoice = self.pool.get('res.partner.address').browse(cr, uid, [ptn_invoice_id])[0]
 
113
 
 
114
        to_country = partner_addr_invoice.country_id.id
 
115
        to_state = partner_addr_invoice.state_id.id
 
116
 
 
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)])
 
118
        
 
119
        if fsc_pos_id:
 
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
 
122
       
 
123
        return result      
 
124
        
 
125
account_invoice()
 
 
b'\\ No newline at end of file'