def _validate_address(self, cr, uid, address, avatax_config=False, context=None): """ Returns the valid address from the AvaTax Address Validation Service. """ avatax_config_obj= self.pool.get('avalara.salestax') if context is None: context = {} if not avatax_config: avatax_config = avatax_config_obj._get_avatax_config_company(cr, uid, context=context) if not avatax_config: raise osv.except_osv("AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation.") # Create the AvaTax Address service with the configuration parameters set for the instance if (not avatax_config.account_number or not avatax_config.license_key or not avatax_config.service_url or not avatax_config.request_timeout): raise osv.except_osv("AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation.") avapoint = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) addSvc = avapoint.create_address_service().addressSvc # Obtain the state code & country code and create a BaseAddress Object state_code = address.get('state_id') and self.get_state_code(cr, uid, address['state_id'], context=context) country_code = address.get('country_id') and self.get_country_code(cr, uid, address['country_id'], context=context) baseaddress = BaseAddress(addSvc, address.get('street') or None, address.get('street2') or None, address.get('city'), address.get('zip'), state_code, country_code, 0).data result = avapoint.validate_address(baseaddress, avatax_config.result_in_uppercase and 'Upper' or 'Default') valid_address = result.ValidAddresses[0][0] return valid_address
def cancel_tax(self, cr, uid, avatax_config, doc_code, doc_type, cancel_code): """Sometimes we have not need to tax calculation, then method is used to cancel taxation""" avalara_obj = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) avalara_obj.create_tax_service() result = avalara_obj.cancel_tax(avatax_config.company_code, doc_code, doc_type, cancel_code) return result
def _validate_address(self, cr, uid, address, avatax_config=False, context=None): """ Returns the valid address from the AvaTax Address Validation Service. """ avatax_config_obj = self.pool.get('avalara.salestax') if context is None: context = {} if not avatax_config: avatax_config = avatax_config_obj._get_avatax_config_company( cr, uid, context=context) if not avatax_config: raise osv.except_osv( "AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation." ) # Create the AvaTax Address service with the configuration parameters set for the instance if (not avatax_config.account_number or not avatax_config.license_key or not avatax_config.service_url or not avatax_config.request_timeout): raise osv.except_osv( "AvaTax: Error", "This module has not yet been setup. Please refer to the Avatax module documentation." ) avapoint = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) addSvc = avapoint.create_address_service().addressSvc # Obtain the state code & country code and create a BaseAddress Object state_code = address.get('state_id') and self.get_state_code( cr, uid, address['state_id'], context=context) country_code = address.get('country_id') and self.get_country_code( cr, uid, address['country_id'], context=context) baseaddress = BaseAddress(addSvc, address.get('street') or None, address.get('street2') or None, address.get('city'), address.get('zip'), state_code, country_code, 0).data result = avapoint.validate_address( baseaddress, avatax_config.result_in_uppercase and 'Upper' or 'Default') valid_address = result.ValidAddresses[0][0] return valid_address
def _get_compute_tax(self, cr, uid, avatax_config, doc_date, doc_code, doc_type, partner, ship_from_address_id, shipping_address_id, lines, user=None, exemption_number=None, exemption_code_name=None, commit=False, invoice_date=False, reference_code=False, location_code=False, context=None): address_obj = self.pool.get('res.partner') currency_code = self._get_currency(cr, uid, context) if not partner.customer_code: raise osv.except_osv(_('Avatax: Warning !'), _('Customer Code for customer %s not define'% (partner.name))) if not shipping_address_id: raise osv.except_osv(_('Avatax: No Shipping Address Defined !'), _('There is no shipping address defined for the partner.')) #it's show destination address shipping_address = address_obj.browse(cr, uid, shipping_address_id, context=context) if not lines: raise osv.except_osv(_('Avatax: Error !'), _('AvaTax needs atleast one sale order line defined for tax calculation.')) if avatax_config.force_address_validation: if not shipping_address.date_validation: raise osv.except_osv(_('Avatax: Address Not Validated !'), _('Please validate the shipping address for the partner %s.' % (partner.name))) if not ship_from_address_id: raise osv.except_osv(_('Avatax: No Ship from Address Defined !'), _('There is no company address defined.')) #it's show source address ship_from_address = address_obj.browse(cr, uid, ship_from_address_id, context=context) if not ship_from_address.date_validation: raise osv.except_osv(_('Avatax: Address Not Validated !'), _('Please validate the company address.')) #For check credential avalara_obj = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) avalara_obj.create_tax_service() addSvc = avalara_obj.create_address_service().addressSvc origin = BaseAddress(addSvc, ship_from_address.street or None, ship_from_address.street2 or None, ship_from_address.city, ship_from_address.zip, ship_from_address.state_id and ship_from_address.state_id.code or None, ship_from_address.country_id and ship_from_address.country_id.code or None, 0).data destination = BaseAddress(addSvc, shipping_address.street or None, shipping_address.street2 or None, shipping_address.city, shipping_address.zip, shipping_address.state_id and shipping_address.state_id.code or None, shipping_address.country_id and shipping_address.country_id.code or None, 1).data #using get_tax method to calculate tax based on address result = avalara_obj.get_tax(avatax_config.company_code, doc_date, doc_type, partner.customer_code, doc_code, origin, destination, lines, exemption_number, exemption_code_name, user and user.name or None, commit, invoice_date, reference_code, location_code, currency_code, partner.vat_id or None) return result
def _get_compute_tax(self, cr, uid, avatax_config, doc_date, doc_code, doc_type, partner, ship_from_address_id, shipping_address_id, lines, user=None, exemption_number=None, exemption_code_name=None, commit=False, invoice_date=False, reference_code=False, location_code=False, context=None): # Clean extended descriptions to 255 chars to be compatible with Avatax server for line in lines: line['description'] = line['description'] and line['description'][:255] address_obj = self.pool.get('res.partner') currency_code = self._get_currency(cr, uid, context) if not partner.customer_code: raise osv.except_osv(_('Avatax: Warning !'), _('Customer Code for customer %s not define'% (partner.name))) if not shipping_address_id: raise osv.except_osv(_('Avatax: No Shipping Address Defined !'), _('There is no shipping address defined for the partner.')) #it's show destination address shipping_address = address_obj.browse(cr, uid, shipping_address_id, context=context) if not lines: raise osv.except_osv(_('Avatax: Error !'), _('AvaTax needs atleast one sale order line defined for tax calculation.')) #this condition is required, in case user select force address validation on Avatax API Configuration if avatax_config.force_address_validation: if not shipping_address.date_validation: raise osv.except_osv(_('Avatax: Address Not Validated !'), _('Please validate the shipping address for the partner %s.' % (partner.name))) if not ship_from_address_id: raise osv.except_osv(_('Avatax: No Ship from Address Defined !'), _('There is no company address defined.')) #it's show source address ship_from_address = address_obj.browse(cr, uid, ship_from_address_id, context=context) if not ship_from_address.date_validation: raise osv.except_osv(_('Avatax: Address Not Validated !'), _('Please validate the address for your company in OpenERP. When you setup a new instance of OpenERP you must also find your company in the contacts and ensure that the address is validated.')) #For check credential avalara_obj = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) avalara_obj.create_tax_service() addSvc = avalara_obj.create_address_service().addressSvc origin = BaseAddress(addSvc, ship_from_address.street or None, ship_from_address.street2 or None, ship_from_address.city, ship_from_address.zip, ship_from_address.state_id and ship_from_address.state_id.code or None, ship_from_address.country_id and ship_from_address.country_id.code or None, 0).data destination = BaseAddress(addSvc, shipping_address.street or None, shipping_address.street2 or None, shipping_address.city, shipping_address.zip, shipping_address.state_id and shipping_address.state_id.code or None, shipping_address.country_id and shipping_address.country_id.code or None, 1).data #using get_tax method to calculate tax based on address result = avalara_obj.get_tax(avatax_config.company_code, doc_date, doc_type, partner.customer_code, doc_code, origin, destination, lines, exemption_number, exemption_code_name, user and user.name or None, commit, invoice_date, reference_code, location_code, currency_code, partner.vat_id or None) return result
def cancel_tax(self, cr, uid, avatax_config, doc_code, doc_type, cancel_code): """Sometimes we have not need to tax calculation, then method is used to cancel taxation""" avalara_obj = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) avalara_obj.create_tax_service() try: result = avalara_obj.get_tax_history(avatax_config.company_code, doc_code, doc_type) except: return True result = avalara_obj.cancel_tax(avatax_config.company_code, doc_code, doc_type, cancel_code) return result
def _get_compute_tax(self, cr, uid, avatax_config, doc_date, doc_code, doc_type, partner, ship_from_address_id, shipping_address_id, lines, user=None, exemption_number=None, exemption_code_name=None, commit=False, invoice_date=False, reference_code=False, location_code=False, context=None): address_obj = self.pool.get('res.partner') currency_code = self._get_currency(cr, uid, context) #if not partner.customer_code: # raise osv.except_osv(_('AvaTax: Warning !'), _('Customer Code for customer %s not defined.\n\n You can edit the Customer Code in customer profile. You can fix by clicking "Generate Customer Code" button in the customer contact information"'% (partner.name))) if not partner.customer_code: if not avatax_config.auto_generate_customer_code: raise osv.except_osv(_('AvaTax: Warning !'), _('Customer Code for customer %s not defined.\n\n You can edit the Customer Code in customer profile. You can fix by clicking "Generate Customer Code" button in the customer contact information"'% (partner.name))) else: address_obj.generate_cust_code(cr, 1, [partner.id], partner.id) if not shipping_address_id: raise osv.except_osv(_('AvaTax: No Shipping Address Defined !'), _('There is no shipping address defined for the partner.')) #it's show destination address shipping_address = address_obj.browse(cr, uid, shipping_address_id, context=context) # if not lines: # raise osv.except_osv(_('AvaTax: Error !'), _('AvaTax needs at least one sale order line defined for tax calculation.')) if not ship_from_address_id: raise osv.except_osv(_('AvaTax: No Ship from Address Defined !'), _('There is no company address defined.')) #it's show source address ship_from_address = address_obj.browse(cr, uid, ship_from_address_id, context=context) #this condition is required, in case user select force address validation on AvaTax API Configuration if not avatax_config.address_validation: if avatax_config.force_address_validation: if not shipping_address.date_validation: raise osv.except_osv(_('AvaTax: Address Not Validated !'), _('Please validate the shipping address for the partner %s.' % (partner.name))) # if not avatax_config.address_validation: if not ship_from_address.date_validation: raise osv.except_osv(_('AvaTax: Address Not Validated !'), _('Please validate the company address.')) #For check credential avalara_obj = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) avalara_obj.create_tax_service() addSvc = avalara_obj.create_address_service().addressSvc origin = BaseAddress(addSvc, ship_from_address.street or None, ship_from_address.street2 or None, ship_from_address.city, ship_from_address.zip, ship_from_address.state_id and ship_from_address.state_id.code or None, ship_from_address.country_id and ship_from_address.country_id.code or None, 0).data destination = BaseAddress(addSvc, shipping_address.street or None, shipping_address.street2 or None, shipping_address.city, shipping_address.zip, shipping_address.state_id and shipping_address.state_id.code or None, shipping_address.country_id and shipping_address.country_id.code or None, 1).data #using get_tax method to calculate tax based on address # doc_date = datetime.strftime(datetime.strptime(doc_date,DEFAULT_SERVER_DATETIME_FORMAT), DEFAULT_SERVER_DATE_FORMAT) # print"doc_date",type(doc_date) invoice_date = invoice_date.split(' ')[0] if invoice_date else False result = avalara_obj.get_tax(avatax_config.company_code, doc_date, doc_type, partner.customer_code, doc_code, origin, destination, lines, exemption_number, exemption_code_name, user and user.name or None, commit, invoice_date, reference_code, location_code, currency_code, partner.vat_id or None) return result
def _get_compute_tax(self, cr, uid, avatax_config, doc_date, doc_code, doc_type, partner, ship_from_address_id, shipping_address_id, lines, user=None, exemption_number=None, exemption_code_name=None, commit=False, invoice_date=False, reference_code=False, location_code=False, context=None): address_obj = self.pool.get('res.partner') currency_code = self._get_currency(cr, uid, context) #if not partner.customer_code: # raise osv.except_osv(_('AvaTax: Warning !'), _('Customer Code for customer %s not defined.\n\n You can edit the Customer Code in customer profile. You can fix by clicking "Generate Customer Code" button in the customer contact information"'% (partner.name))) if not partner.customer_code: if not avatax_config.auto_generate_customer_code: raise osv.except_osv( _('AvaTax: Warning !'), _('Customer Code for customer %s not defined.\n\n You can edit the Customer Code in customer profile. You can fix by clicking "Generate Customer Code" button in the customer contact information"' % (partner.name))) else: address_obj.generate_cust_code(cr, 1, [partner.id], partner.id) if not shipping_address_id: raise osv.except_osv( _('AvaTax: No Shipping Address Defined !'), _('There is no shipping address defined for the partner.')) #it's show destination address shipping_address = address_obj.browse(cr, uid, shipping_address_id, context=context) # if not lines: # raise osv.except_osv(_('AvaTax: Error !'), _('AvaTax needs at least one sale order line defined for tax calculation.')) if not ship_from_address_id: raise osv.except_osv(_('AvaTax: No Ship from Address Defined !'), _('There is no company address defined.')) #it's show source address ship_from_address = address_obj.browse(cr, uid, ship_from_address_id, context=context) #this condition is required, in case user select force address validation on AvaTax API Configuration if not avatax_config.address_validation: if avatax_config.force_address_validation: if not shipping_address.date_validation: raise osv.except_osv( _('AvaTax: Address Not Validated !'), _('Please validate the shipping address for the partner %s.' % (partner.name))) # if not avatax_config.address_validation: if not ship_from_address.date_validation: raise osv.except_osv(_('AvaTax: Address Not Validated !'), _('Please validate the company address.')) #For check credential avalara_obj = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) avalara_obj.create_tax_service() addSvc = avalara_obj.create_address_service().addressSvc origin = BaseAddress( addSvc, ship_from_address.street or None, ship_from_address.street2 or None, ship_from_address.city, ship_from_address.zip, ship_from_address.state_id and ship_from_address.state_id.code or None, ship_from_address.country_id and ship_from_address.country_id.code or None, 0).data destination = BaseAddress( addSvc, shipping_address.street or None, shipping_address.street2 or None, shipping_address.city, shipping_address.zip, shipping_address.state_id and shipping_address.state_id.code or None, shipping_address.country_id and shipping_address.country_id.code or None, 1).data #using get_tax method to calculate tax based on address # doc_date = datetime.strftime(datetime.strptime(doc_date,DEFAULT_SERVER_DATETIME_FORMAT), DEFAULT_SERVER_DATE_FORMAT) # print"doc_date",type(doc_date) invoice_date = invoice_date.split(' ')[0] if invoice_date else False result = avalara_obj.get_tax( avatax_config.company_code, doc_date, doc_type, partner.customer_code, doc_code, origin, destination, lines, exemption_number, exemption_code_name, user and user.name or None, commit, invoice_date, reference_code, location_code, currency_code, partner.vat_id or None) return result
def _get_compute_tax(self, cr, uid, avatax_config, doc_date, doc_code, doc_type, partner, ship_from_address_id, shipping_address_id, lines, user=None, exemption_number=None, exemption_code_name=None, commit=False, invoice_date=False, reference_code=False, location_code=False, context=None): address_obj = self.pool.get('res.partner') currency_code = self._get_currency(cr, uid, context) if not partner.customer_code: raise osv.except_osv( _('Avatax: Warning !'), _('Customer Code for customer %s not define' % (partner.name))) if not shipping_address_id: raise osv.except_osv( _('Avatax: No Shipping Address Defined !'), _('There is no shipping address defined for the partner.')) #it's show destination address shipping_address = address_obj.browse(cr, uid, shipping_address_id, context=context) if not lines: raise osv.except_osv( _('Avatax: Error !'), _('AvaTax needs atleast one sale order line defined for tax calculation.' )) if avatax_config.force_address_validation: if not shipping_address.date_validation: raise osv.except_osv( _('Avatax: Address Not Validated !'), _('Please validate the shipping address for the partner %s.' % (partner.name))) if not ship_from_address_id: raise osv.except_osv(_('Avatax: No Ship from Address Defined !'), _('There is no company address defined.')) #it's show source address ship_from_address = address_obj.browse(cr, uid, ship_from_address_id, context=context) if not ship_from_address.date_validation: raise osv.except_osv(_('Avatax: Address Not Validated !'), _('Please validate the company address.')) #For check credential avalara_obj = AvaTaxService(avatax_config.account_number, avatax_config.license_key, avatax_config.service_url, avatax_config.request_timeout, avatax_config.logging) avalara_obj.create_tax_service() addSvc = avalara_obj.create_address_service().addressSvc origin = BaseAddress( addSvc, ship_from_address.street or None, ship_from_address.street2 or None, ship_from_address.city, ship_from_address.zip, ship_from_address.state_id and ship_from_address.state_id.code or None, ship_from_address.country_id and ship_from_address.country_id.code or None, 0).data destination = BaseAddress( addSvc, shipping_address.street or None, shipping_address.street2 or None, shipping_address.city, shipping_address.zip, shipping_address.state_id and shipping_address.state_id.code or None, shipping_address.country_id and shipping_address.country_id.code or None, 1).data #using get_tax method to calculate tax based on address result = avalara_obj.get_tax( avatax_config.company_code, doc_date, doc_type, partner.customer_code, doc_code, origin, destination, lines, exemption_number, exemption_code_name, user and user.name or None, commit, invoice_date, reference_code, location_code, currency_code, partner.vat_id or None) return result