~serpent-consulting-services/openerp-usa/fix-shipping_api_ups_cc

« back to all changes in this revision

Viewing changes to account_salestax_avatax/account_salestax_avatax.py

  • Committer: npgllc
  • Date: 2012-08-02 17:13:27 UTC
  • Revision ID: npgllc-20120802171327-2xgyyjjb5d1kx26y
Removed all the 6.0 compatible modules

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
##############################################################################
3
 
#
4
 
#    OpenERP, Open Source Management Solution
5
 
#    Copyright (C) 2011 NovaPoint Group LLC (<http://www.novapointgroup.com>)
6
 
#    Copyright (C) 2004-2010 OpenERP SA (<http://www.openerp.com>)
7
 
#
8
 
#    This program is free software: you can redistribute it and/or modify
9
 
#    it under the terms of the GNU Affero General Public License as
10
 
#    published by the Free Software Foundation, either version 3 of the
11
 
#    License, or (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 Affero General Public License for more details.
17
 
#
18
 
#    You should have received a copy of the GNU Affero General Public License
19
 
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
#
21
 
##############################################################################
22
 
from osv import osv, fields
23
 
from tools.translate import _
24
 
import decimal_precision as dp
25
 
 
26
 
class tax_schedule(osv.osv):
27
 
    _name = "tax.schedule"
28
 
    _description = "Tax Schedule"
29
 
    _columns = {
30
 
        'name': fields.char('Name', size=64, required=True),
31
 
        'code': fields.char('Code', size=32),
32
 
        'jurisdiction_code_ids': fields.one2many('jurisdiction.code', 'tax_schedule_id', 'Jurisdiction Codes'),
33
 
        'company_id': fields.many2one('res.company', 'Company', required=True),
34
 
        'country_id': fields.many2one('res.country', 'Country', required=True),
35
 
    }
36
 
    _defaults = {
37
 
        'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'tax.schedule', context=c),
38
 
    }
39
 
 
40
 
tax_schedule()
41
 
 
42
 
class jurisdiction_code(osv.osv):
43
 
    _name = "jurisdiction.code"
44
 
    _description = "Jurisdiction Code"
45
 
    _columns = {
46
 
        'name': fields.char('Description', size=32, required=True),
47
 
        'type': fields.selection([('country', 'Country'), ('composite', 'Composite'), ('state', 'State'),
48
 
                          ('county', 'County'), ('city', 'City'), ('special', 'Special')], 'Type', required=True,
49
 
                          help="Type of tax jurisdiction"),
50
 
        'state_id': fields.many2one('res.country.state', 'State', required=True, help="State for which the tax jurisdiction is defined"),
51
 
        'code':fields.char('Code', size=32),
52
 
        'tax_schedule_id': fields.many2one('tax.schedule', 'Tax Schedule'),
53
 
        'account_collected_id':fields.many2one('account.account', 'Invoice Tax Account', required=True, help="Use this tax account for Invoices"),
54
 
        'account_paid_id':fields.many2one('account.account', 'Refund Tax Account', required=True, help="Use this tax account for Refunds"),
55
 
        'base_code_id': fields.many2one('account.tax.code', 'Account Base Code', help="Use this base code for the Invoices"),
56
 
        'tax_code_id': fields.many2one('account.tax.code', 'Account Tax Code', help="Use this tax code for the Invoices"),
57
 
        'base_sign': fields.float('Base Code Sign', help="Usually 1 or -1"),
58
 
        'tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1"),
59
 
        'ref_base_code_id': fields.many2one('account.tax.code', 'Refund Base Code', help="Use this base code for the Refunds"),
60
 
        'ref_tax_code_id': fields.many2one('account.tax.code', 'Refund Tax Code', help="Use this tax code for the Refunds"),
61
 
        'ref_base_sign': fields.float('Base Code Sign', help="Usually 1 or -1"),
62
 
        'ref_tax_sign': fields.float('Tax Code Sign', help="Usually 1 or -1"),
63
 
    }
64
 
    _defaults = {
65
 
        'ref_tax_sign': 1,
66
 
        'ref_base_sign': 1,
67
 
        'tax_sign': 1,
68
 
        'base_sign': 1,
69
 
    }
70
 
 
71
 
jurisdiction_code()
72
 
 
73
 
class exemption_code(osv.osv):
74
 
    _name = 'exemption.code'
75
 
    _description = 'Exemption Code'
76
 
    _columns = {
77
 
        'name': fields.char('Name', size=64),
78
 
        'code': fields.char('Code', size=2)
79
 
    }
80
 
 
81
 
    def name_get(self, cr, uid, ids, context=None):
82
 
        if not ids:
83
 
            return []
84
 
        reads = self.read(cr, uid, ids, ['name', 'code'], context=context)
85
 
        res = []
86
 
        for record in reads:
87
 
            name = record['name']
88
 
            if record['code']:
89
 
                name = '(' + record['code'] + ')' + ' ' + name
90
 
            res.append((record['id'], name))
91
 
        return res
92
 
 
93
 
exemption_code()
94
 
 
95
 
class account_salestax_avatax(osv.osv):
96
 
    _name = 'account.salestax.avatax'
97
 
    _description = 'AvaTax Configuration'
98
 
    __rec_name = 'account_number'
99
 
 
100
 
    def _get_avatax_supported_countries(self, cr, uid, context=None):
101
 
        """ Returns the countries supported by AvaTax Address Validation Service."""
102
 
 
103
 
        country_pool = self.pool.get('res.country')
104
 
        return country_pool.search(cr, uid, [('code', 'in', ['US', 'CA'])], context=context)
105
 
 
106
 
    _columns = {
107
 
        'account_number':fields.char('Account Number', size=64, required=True, help="Account Number provided by AvaTax"),
108
 
        'license_key': fields.char('License Key', size=64, required=True, help="License Key provided by AvaTax"),
109
 
        'service_url': fields.char('Service URL', size=64, required=True, help="The url to connect with"),
110
 
        'date_expiration': fields.date('Service Expiration Date', readonly=True, help="The expiration date of the service"),
111
 
        'request_timeout': fields.integer('Request Timeout', help="Defines AvaTax request time out length, AvaTax best practices prescribes default setting of 300 seconds"),
112
 
        'company_code': fields.char('Company Code', size=64, required=True, help="The company code as defined in the Admin Console of AvaTax"),
113
 
        'logging': fields.boolean('Enable Logging', help="Enables detailed AvaTax transaction logging within application"),
114
 
        'address_validation': fields.boolean('Disable Address Validation', help="Check to disable address validation"),
115
 
        'result_in_uppercase': fields.boolean('Results in Upper Case', help="Check is address validation results desired to be in upper case"),
116
 
        'validation_on_save': fields.boolean('Address Validation on Save', help="Check if each address when saved should be validated"),
117
 
        'force_address_validation': fields.boolean('Force Address Validation', help="Check if address validation should be done before tax calculation"),
118
 
        'disable_tax_calculation': fields.boolean('Disable Tax Calculation', help="Check to disable tax calculation"),
119
 
        'default_tax_schedule_id': fields.many2one('tax.schedule', 'Default Tax Schedule', help="Identifies customers using AVATAX. Only customers with AVATAX designation triggers tax calculation from Avatax otherwise it will follow the normal tax calculation that OpenERP provides"),
120
 
        'default_shipping_code_id': fields.many2one('product.tax.code', 'Default Shipping Code', help="The default shipping code which will be passed to Avalara"),
121
 
        'country_ids': fields.many2many('res.country', 'account_salestax_avatax_country_rel', 'account_salestax_avatax_id', 'country_id', 'Countries', help="Countries where address validation will be used"),
122
 
        'active': fields.boolean('Active', help="Uncheck the active field to hide the record"),
123
 
        'company_id': fields.many2one('res.company', 'Company', required=True, help="Company which has subscribed to the AvaTax service"),
124
 
    }
125
 
    _defaults = {
126
 
        'active': True,
127
 
        'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'account.salestax.avatax', context=c),
128
 
        'request_timeout': 300,
129
 
        'country_ids': _get_avatax_supported_countries
130
 
    }
131
 
 
132
 
    _sql_constraints = [
133
 
        ('code_company_uniq', 'unique (company_code)', 'The code of the company must be unique!'),
134
 
        ('account_number_company_uniq', 'unique (account_number, company_id)', 'The account number must be unique per company!'),
135
 
    ]
136
 
 
137
 
    def _get_avatax_config_company(self, cr, uid, context=None):
138
 
        """ Returns the AvaTax configuration for the user company """
139
 
 
140
 
        user_obj = self.pool.get('res.users')
141
 
        user = user_obj.browse(cr, uid, uid, context=context)
142
 
        avatax_config_ids = self.search(cr, uid, [('company_id', '=', user.company_id.id)], context=context)
143
 
        return avatax_config_ids and self.browse(cr, uid, avatax_config_ids[0], context=context) or False
144
 
 
145
 
account_salestax_avatax()
146
 
 
147
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
 
 
b'\\ No newline at end of file'