Commit c891d226 authored by santi's avatar santi
Browse files

Cleaning the partner form

parent 719b86d7
......@@ -14,22 +14,6 @@ from openerp.addons.web.controllers.main import login_redirect
_logger = logging.getLogger(__name__)
# mapping invoice type to journal type
TYPE2JOURNAL = {
'out_invoice': 'sale',
'in_invoice': 'purchase',
'out_refund': 'sale_refund',
'in_refund': 'purchase_refund',
}
# mapping invoice type to refund type
TYPE2REFUND = {
'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')
......@@ -37,10 +21,10 @@ class InvoiceController(http.Controller):
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')
@http.route('/invoice_controller/create_url', type='http', auth='user')
def create_url(self, **post):
if not post:
return {'pdf': None}
......
......@@ -2,37 +2,63 @@ import json
import urllib
import urllib2
import logging
from requests import Request,Session
# http://devmarket.punto0.org/invoice_controller/create_url?user_id=1&name=+test&reference=comment&partner_id=47&company_id=45&type=out_invoice
# devmarket.punto0.org/invoice_controller/create_url?user_id=1&name=+test&reference=comment&partner_id=132&company_id=45&type=out_invoice
# ['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
}
base_url = 'http://devmarket.punto0.org'
user = 'contable'
password = 'haciendofacturas'
db = "invoices"
def login():
# login
url = "%s/web/session/authenticate" % base_url
s = Session()
data = {
'jsonrpc': '2.0',
'params': {
'context': {},
'db': db,
'login': user,
'password': password,
},
}
headers = {
'Content-type': 'application/json'
}
req = Request('POST',url,data=json.dumps(data),headers=headers)
prepped = req.prepare()
resp = s.send(prepped)
r_data = json.loads(resp.text)
return r_data['result']['session_id']
data_encoded = urllib.urlencode(data_json)
logging.warning("Data encoded to send : %s" %data_encoded)
url = 'http://devmarket.punto0.org/invoice_controller/create_url?'
#url = '/invoice_controller_create_url'
req = urllib2.Request(url, data_encoded, headers)
try:
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(e)
logging.error("ERROR: cannot do callback in %s with data %s" %(url, data_json))
if __name__ == '__main__':
session_id = login()
url = "%s/invoice_controller/create" % base_url
headers = {'content-type':'application/html'}
# 'account_id', 'currency_id', 'payment_term', 'fiscal_position'
data_json = {
'db': db, #nombre de la base de datos, necesario para multidatabases sites
'name':' test',
'reference': 'comment',
'partner_id':8, # cliente
'company_id':1, # cia datos factura
'user_id':5, # usuario que crea la factura, debe tener permisos y es el que hace login
'type': 'out_invoice' # factura de venta
}
data_encoded = urllib.urlencode(data_json)
logging.warning("Data encoded to send : %s" %data_encoded)
req = urllib2.Request(url, data_encoded, headers)
try:
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(e)
logging.error("ERROR: cannot do callback in %s with data %s" %(url, data_json))
# -*- coding: utf-8 -*-
#import models
# -*- coding: utf-8 -*-
{
'name': 'Partner FreedomCoop Custom',
'depends': ['base'],
'author': 'Santi Punto0 - FairCooop',
'category': 'Base',
'description': """
Customization on the product model for FreedomCoop
""",
'website': 'https://punto0.org',
'data': [
'views/partner_view.xml',
],
'installable': True,
'auto_install': False,
}
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<record id="partner_form_view_inherit" model="ir.ui.view">
<field name="name">partner.form.view.inherit</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='user_id']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
<xpath expr="//field[@name='ref']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
<xpath expr="//group/field[@name='date']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
<xpath expr="//group/field[@name='customer']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
<!--
<xpath expr="//field[@name='notify_email']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
<xpath expr="//field[@name='opt_out']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
<xpath expr="//group/field[@name='supplier']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
<xpath expr="//field[@name='active']" position="attributes">
<attribute name="groups">"account.group_account_user"</attribute>
</xpath>
-->
</field>
</record>
</data>
</openerp>
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