1
# -*- coding: utf-8 -*-
2
##############################################################################
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>)
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.
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.
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/>.
21
##############################################################################
25
from osv import osv, fields
26
from tools.translate import _
28
from suds_client import AvaTaxService, BaseAddress, Line
30
class account_tax(osv.osv):
31
_inherit = "account.tax"
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')
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.'
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.'))
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.'))
55
'amount': shipping_charge,
58
'tax_code': avatax_config.default_shipping_code_id.name
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)
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)
92
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: