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

« back to all changes in this revision

Viewing changes to account_salestax_avatax/account.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
 
import time
23
 
import string
24
 
 
25
 
from osv import osv, fields
26
 
from tools.translate import _
27
 
 
28
 
from suds_client import AvaTaxService, BaseAddress, Line
29
 
 
30
 
class account_tax(osv.osv):
31
 
    _inherit = "account.tax"
32
 
 
33
 
    def _check_compute_tax(self, cr, uid, avatax_config, doc_date, doc_code, doc_type, partner, ship_from_address_id, shipping_address_id,
34
 
                          lines, shipping_charge, user=None, commit=False, invoice_date=False, reference_code=False, context=None):
35
 
        address_obj = self.pool.get('res.partner.address')
36
 
        if not lines:
37
 
            raise osv.except_osv(_('Error !'), _('AvaTax needs atleast one sale order line defined for tax calculation.'))
38
 
        if avatax_config.force_address_validation:
39
 
            if not shipping_address.date_validation:
40
 
                raise osv.except_osv(_('Address Not Validated !'), _('Please validate the shipping address for the partner %s.'
41
 
                            % (partner.name)))
42
 
        if not ship_from_address_id:
43
 
            raise osv.except_osv(_('No Ship from Address Defined !'), _('There is no company address defined.'))
44
 
        if not shipping_address_id:
45
 
                raise osv.except_osv(_('No Shipping Address Defined !'), _('There is no shipping address defined for the partner.'))
46
 
 
47
 
        ship_from_address = address_obj.browse(cr, uid, ship_from_address_id, context=context)
48
 
        shipping_address = address_obj.browse(cr, uid, shipping_address_id, context=context)
49
 
        if not ship_from_address.date_validation:
50
 
            raise osv.except_osv(_('Address Not Validated !'), _('Please validate the company address.'))
51
 
 
52
 
        if shipping_charge:
53
 
            lines.append({
54
 
                'qty': 1,
55
 
                'amount': shipping_charge,
56
 
                'itemcode': '',
57
 
                'description': '',
58
 
                'tax_code': avatax_config.default_shipping_code_id.name
59
 
            })
60
 
        avapoint = AvaTaxService(avatax_config.account_number, avatax_config.license_key,
61
 
                                 avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging)
62
 
        avapoint.create_tax_service()
63
 
        addSvc = avapoint.create_address_service().addressSvc
64
 
        origin = BaseAddress(addSvc, ship_from_address.street or None,
65
 
                             ship_from_address.street2 or None,
66
 
                             ship_from_address.city, ship_from_address.zip,
67
 
                             ship_from_address.state_id and ship_from_address.state_id.code or None,
68
 
                             ship_from_address.country_id and ship_from_address.country_id.code or None, 0).data
69
 
        destination = BaseAddress(addSvc, shipping_address.street or None,
70
 
                                  shipping_address.street2 or None,
71
 
                                  shipping_address.city, shipping_address.zip,
72
 
                                  shipping_address.state_id and shipping_address.state_id.code or None,
73
 
                                  shipping_address.country_id and shipping_address.country_id.code or None, 1).data
74
 
        result = avapoint.get_tax(avatax_config.company_code, doc_date, doc_type,
75
 
                                 partner.name, doc_code, origin, destination,
76
 
                                 lines, partner.exemption_number or None,
77
 
                                 partner.exemption_code_id and partner.exemption_code_id.code or None,
78
 
                                 user and user.name or None, commit, invoice_date, reference_code)
79
 
 
80
 
        return result
81
 
 
82
 
    def cancel_tax(self, cr, uid, avatax_config, doc_code, doc_type, cancel_code):
83
 
         avapoint = AvaTaxService(avatax_config.account_number, avatax_config.license_key,
84
 
                                  avatax_config.service_url, avatax_config.request_timeout,
85
 
                                  avatax_config.logging)
86
 
         avapoint.create_tax_service()
87
 
         result = avapoint.cancel_tax(avatax_config.company_code, doc_code, doc_type, cancel_code)
88
 
         return result
89
 
 
90
 
account_tax()
91
 
 
92
 
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: