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

« back to all changes in this revision

Viewing changes to account_fiscal_position_rule/invoice.py

  • Committer: Albert Cervera i Areny
  • Date: 2011-06-14 09:51:35 UTC
  • mfrom: (5345.1.165 openobject-addons)
  • Revision ID: albert@nan-tic.com-20110614095135-1x3p6tmil5lxkl9b
Merge and add nan_remove_default_filters

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- encoding: utf-8 -*-
2
 
##############################################################################
 
2
#################################################################################
3
3
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6
 
#    $Id$
 
4
#    Copyright (C) 2010  Renato Lima - Akretion
7
5
#
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/>.
20
18
#
21
 
##############################################################################
 
19
#################################################################################
22
20
 
23
21
from osv import fields, osv
24
22
 
30
28
 
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)
32
30
 
33
 
        if not partner_id or not company_id or not result['value']['address_invoice_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]
 
31
        if not partner_id or not company_id or not result['value']['address_invoice_id'] or result['value']['fiscal_position']:
 
32
            return result
 
33
 
 
34
        obj_company = self.pool.get('res.company').browse(cr, uid, company_id)
40
35
 
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
51
46
 
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)])
53
48
        
54
49
        if fsc_pos_id:
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']
57
52
 
58
53
        return result
59
54
                            
64
59
        if not part_id or not company_id or not ptn_invoice_id:
65
60
            return result
66
61
        
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
 
65
            return result
 
66
        
 
67
        obj_company = self.pool.get('res.company').browse(cr, uid, company_id)
68
68
        
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
79
79
 
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)])
81
81
        
82
82
        if fsc_pos_id:
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']
85
85
       
86
86
        return result   
87
87
    
89
89
 
90
90
        result = {'value': {'fiscal_position': False}}
91
91
        
92
 
        if not ptn_id or not cpy_id or not ptn_invoice_id:
93
 
            return result
94
 
        
95
 
        if result['value']['fiscal_position']:
96
 
            return result
97
 
        
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']:
 
93
            return result
 
94
 
 
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
 
98
            return result
 
99
 
 
100
        obj_company = self.pool.get('res.company').browse(cr, uid, cpy_id)
99
101
        
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
105
107
 
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)
107
109
 
108
110
        to_country = partner_addr_invoice.country_id.id
109
111
        to_state = partner_addr_invoice.state_id.id
110
112
 
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)])
112
114
        
113
115
        if fsc_pos_id:
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
 
       
117
 
        return result      
118
 
        
 
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']
 
118
 
 
119
        return result
 
120
 
119
121
account_invoice()