Commit 719b86d7 authored by santi's avatar santi
Browse files

First quick & dirty controller to create an invoice. Not finished yet

#import models
import controllers
'name' : 'Invoicing interface',
'version': '1.0',
'author' : 'Santi',
'summary': 'Controller to invoices management in Odoo',
'category': 'Account',
Invoicing Interface
Crea controladores en Odoo para gestionar facturas desde otros sistemas
'data': [
'depends' : ['web','account'],
'application': False,
# -*- coding: utf-8 -*-
import werkzeug
import openerp
import logging
import pprint
import urlparse
from openerp import SUPERUSER_ID
from openerp import http
from openerp.http import request
from import _
from import slug
# import openerp.addons.website_sale.controllers.main
from openerp.addons.web.controllers.main import login_redirect
_logger = logging.getLogger(__name__)
# mapping invoice type to journal type
'out_invoice': 'sale',
'in_invoice': 'purchase',
'out_refund': 'sale_refund',
'in_refund': 'purchase_refund',
# mapping invoice type to refund type
'out_invoice': 'out_refund', # Customer Invoice
'in_invoice': 'in_refund', # Supplier Invoice
'out_refund': 'out_invoice', # Customer Refund
'in_refund': 'in_invoice', # Supplier Refund
class InvoiceController(http.Controller):
@http.route('/invoice_controller/create_json', type='json', auth='none')
def create_json(self, **post):
if not post:
return {'pdf': None}
_logger.debug('Creating invoice with post data %s', pprint.pformat(post)) # debug
return {'pdf': pdf_url }
# ['name', 'reference', 'comment', 'date_due', 'partner_id', 'company_id', 'account_id', 'currency_id', 'payment_term', 'user_id', 'fiscal_position']
@http.route('/invoice_controller/create_url', type='http', auth='none')
def create_url(self, **post):
if not post:
return {'pdf': None}
_logger.debug('Creating invoice with post data %s', pprint.pformat(post)) # debug
cr, uid, context =, request.uid, request.context
values = {}
#data_raw = request.httprequest.get_data()
#values = urlparse.parse_qs(data_raw)
#_logger.debug('Data decoded : %s' %values)
_logger.debug('user_id %s' %post.get('user_id'))
# values['invoice_line'] = self._refund_cleanup_lines(invoice.invoice_line)
if 'journal_id' in post:
journal = request.registry['account.journal'].browse(cr, int(post.get('user_id')), post['journal_id'])
elif post.get('type', False) == 'out_invoice':
journal = request.registry['account.journal'].search(cr, int(post.get('user_id')), [('type', '=', 'sale')], limit=1)
journal = request.registry['account.journal'].search(cr, int(post.get('user_id')), [('type', '=', 'purchase')], limit=1)
values['journal_id'] = journal[0]
values['type'] = post.get('type')
# values['date_invoice'] = date or fields.Date.context_today(invoice)
values['state'] = 'draft'
values['number'] = False
# values['origin'] = invoice.number
#if period_id:
# values['period_id'] = period_id
#if description:
values['name'] = post.get('name')
values['partner_id'] = post.get('partner_id')
values['company_id'] = post.get('company_id')
values['account_id'] = '19' # sales account
id = request.registry['account.invoice'].create(cr, int(post.get('user_id')), values)
_logger.debug('user_id %s' %post.get('user_id'))
return werkzeug.utils.redirect('/')
import json
import urllib
import urllib2
import logging
# ['name', 'reference', 'comment', 'date_due', 'partner_id', 'company_id', 'account_id', 'currency_id', 'payment_term', 'user_id', 'fiscal_position']
if __name__ == '__main__':
headers = {'content-type':'application/html'}
data_json = {
'name':' test',
'reference': 'comment',
'partner_id':47, # punto0
'company_id':45, #ddt cia
# 'account_id', 'currency_id', 'payment_term', 'fiscal_position'
'user_id':1, #admin,
'type': 'out_invoice' #factura de venta
data_encoded = urllib.urlencode(data_json)
logging.warning("Data encoded to send : %s" %data_encoded)
url = ''
#url = '/invoice_controller_create_url'
req = urllib2.Request(url, data_encoded, headers)
response_stream = urllib2.urlopen(req)
logging.warning('Got Response : %s' %(response_stream))
except urllib2.HTTPError as e:
logging.error("ERROR: cannot do callback in %s with data %s" %(url, data_json))
logging.error("ERROR: code : %s" %e.code)
except urllib2.URLError as e:
logging.error('ERROR: Can not contact with %s' %url)
logging.error('ERROR: Reason : %s ' % e.reason)
except ValueError, e:
logging.error("ERROR: cannot do callback in %s with data %s" %(url, data_json))
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment