[REF] refoctoring the code
bzr revid: mva@openerp.com-20120216144911-na2dzlnq064ctsur
This commit is contained in:
parent
151cedd71b
commit
5e5ad36ffd
|
@ -0,0 +1,100 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from osv import fields, osv
|
||||
import xmlrpclib
|
||||
|
||||
|
||||
class event_moodle(osv.osv):
|
||||
""" Event Type """
|
||||
_name = 'event.moodle'
|
||||
_inherit = 'event.registration'
|
||||
_columns = {
|
||||
'moodle_ok' : fields.boolean('moodle_ok'),
|
||||
'moodle_username' : fields.char('Moodle username', 128),
|
||||
'moodle_password' : fields.char('Moodle password', 128),
|
||||
'moodle_token' : fields.char('Moodle token', 128),
|
||||
'serveur_moodle': fields.char('Moodle token', 128),
|
||||
}
|
||||
|
||||
|
||||
def Get_url():
|
||||
"""
|
||||
attr:
|
||||
serveur_moodle
|
||||
token
|
||||
password
|
||||
username
|
||||
"""
|
||||
hostname="127.0.0.1"
|
||||
password="Administrateur1%2b"
|
||||
username="admin"
|
||||
|
||||
#if token
|
||||
token='3ecfb383330044a884b1ee86e0872b47'
|
||||
url='http://'+hostname+'/moodle/webservice/xmlrpc/server.php?wstoken='+token
|
||||
#if user connect
|
||||
url='http://'+hostname+'/moodle/webservice/xmlrpc/simpleserver.php?wsusername='+username+'&wspassword='+password
|
||||
return url
|
||||
|
||||
def create_moodle_user():
|
||||
#user is a list of dictionaries with every required datas for moodle
|
||||
users=[{
|
||||
'username' : 'efegt(gtrhf',
|
||||
'password' : 'Azertyui1+',
|
||||
'firstname' : 'res',
|
||||
'lastname': 'ezr',
|
||||
'email': 'gegtr@ggtr.com'
|
||||
}]
|
||||
|
||||
#connect to moodle
|
||||
sock = xmlrpclib.ServerProxy(self.Get_url())
|
||||
|
||||
#add user un moodle
|
||||
return sock.core_user_create_users(users)
|
||||
|
||||
#return list of id and username
|
||||
|
||||
def create_moodle_courses():
|
||||
courses=[{
|
||||
'fullname' :'',
|
||||
'shortname' :'',
|
||||
'categoryid':''
|
||||
}]
|
||||
#connect to moodle
|
||||
sock = xmlrpclib.ServerProxy(self.Get_url())
|
||||
|
||||
#add course un moodle
|
||||
sock.core_course_create_courses(courses)
|
||||
|
||||
def moodleenrolled():
|
||||
enrolled=[{
|
||||
'roleid' :'',
|
||||
'userid' :'',
|
||||
'courseid' :''
|
||||
}]
|
||||
#connect to moodle
|
||||
sock = xmlrpclib.ServerProxy(self.Get_url())
|
||||
|
||||
#add enrolled un moodle
|
||||
sock.enrol_manual_enrol_users(enrolled)
|
||||
|
||||
event_moodle()
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<data>
|
||||
<menuitem name="Marketingdcdc" icon="terp-crm" id="base.test" sequence="23"/>
|
||||
<record model="ir.ui.view" id="moodle_configuration">
|
||||
<field name="name">moodle</field>
|
||||
<field name="model">event.event</field>
|
||||
<field name="type">form</field>
|
||||
<field name="inherit_id" ref="event.view_event_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="/form/notebook/page[@string='Extra Info']" position="after">
|
||||
<page string="Moodle">
|
||||
|
||||
</page>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
|
@ -0,0 +1,18 @@
|
|||
from osv import fields,osv
|
||||
|
||||
|
||||
class moodle_config_memory(osv.osv_memory):
|
||||
_name = 'moodle.config.memory'
|
||||
_columns = {
|
||||
'hostname': fields.char('Name',64),
|
||||
'token': fields.char('test',64),
|
||||
'user_moodle': fields.char('teste',64),
|
||||
'pass_moodle': fields.char('ssss',64),
|
||||
}
|
||||
|
||||
|
||||
def get_connect_moodle_info(self, cr, uid, context=None):
|
||||
if not context:
|
||||
return False
|
||||
else:
|
||||
return context.get('hostname')
|
|
@ -0,0 +1,18 @@
|
|||
from osv import fields,osv
|
||||
|
||||
|
||||
class moodle_config_memory(osv.osv_memory):
|
||||
_name = 'moodle.config.memory'
|
||||
_columns = {
|
||||
'hostname': fields.char('Name',64),
|
||||
'token': fields.char('test',64),
|
||||
'user_moodle': fields.char('teste',64),
|
||||
'pass_moodle': fields.char('ssss',64),
|
||||
}
|
||||
|
||||
|
||||
def get_connect_moodle_info(self, cr, uid, context=None):
|
||||
if not context:
|
||||
return False
|
||||
else:
|
||||
return context.get('hostname')
|
|
@ -21,7 +21,7 @@
|
|||
|
||||
|
||||
{
|
||||
'name': 'Events Sales Order',
|
||||
'name': 'Events Sales',
|
||||
'version': '0.1',
|
||||
'category': 'Tools',
|
||||
'complexity': "easy",
|
|
@ -24,7 +24,7 @@ from osv import fields, osv
|
|||
class product(osv.osv):
|
||||
_inherit='product.product'
|
||||
_columns={
|
||||
'event_ok':fields.boolean('Event'),
|
||||
'event_ok':fields.boolean('Event',help='Match a product with an event'),
|
||||
'event_type_id':fields.many2one('event.type','Type of Event'),
|
||||
}
|
||||
product()
|
||||
|
@ -32,7 +32,7 @@ product()
|
|||
class sale_order_line(osv.osv):
|
||||
_inherit='sale.order.line'
|
||||
_columns={
|
||||
'event':fields.many2one('event.event','Event'),
|
||||
'event':fields.many2one('event.event','Event',help="Choose an event and it will authomaticaly create a registration for this event"),
|
||||
'event_type_id':fields.related('event_type',type='many2one', relation="event.type", string="Event Type"),
|
||||
'event_ok':fields.related('event_ok',string='event_ok' ,type='boolean'),
|
||||
}
|
||||
|
@ -72,13 +72,12 @@ class sale_order_line(osv.osv):
|
|||
'name':registration.order_id.partner_invoice_id.name,
|
||||
'partner_id':registration.order_id.partner_id.id,
|
||||
'contact_id':registration.order_id.partner_invoice_id.id,
|
||||
'nb_register':registration.product_uom_qty,
|
||||
'nb_register':int(registration.product_uom_qty),
|
||||
'email':registration.order_id.partner_id.email,
|
||||
'phone':registration.order_id.partner_id.phone,
|
||||
'street':registration.order_id.partner_invoice_id.street,
|
||||
'city':registration.order_id.partner_invoice_id.city,
|
||||
'origin':registration.order_id.name,
|
||||
'nb_register':1,
|
||||
'event_id':registration.event.id,
|
||||
}
|
||||
self.pool.get('event.registration').create(cr,uid,dic,context=context)
|
||||
|
@ -87,4 +86,13 @@ class sale_order_line(osv.osv):
|
|||
return super(sale_order_line, self).button_confirm(cr, uid, ids, context)
|
||||
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
print 'wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww'
|
||||
if not default:
|
||||
default = {}
|
||||
default.update({
|
||||
'event_id',1
|
||||
})
|
||||
print '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<'
|
||||
return super(sale_order, self).copy(cr, uid, id, default, context=context)
|
||||
|
|
@ -4,11 +4,10 @@
|
|||
create a product
|
||||
-
|
||||
!record {model: product.product, id: event_product}:
|
||||
name: formation
|
||||
name: test_formation
|
||||
type: service
|
||||
event_ok: True
|
||||
event_type_id: 1
|
||||
default_code: EVT
|
||||
-
|
||||
create a sale order
|
||||
-
|
||||
|
@ -18,6 +17,19 @@
|
|||
payment_term: account.account_payment_term
|
||||
-
|
||||
create sale order line from the sale order with the product
|
||||
-
|
||||
!record {model: event.event,id: event}:
|
||||
name: test_event
|
||||
type: 1
|
||||
date_end: '2012-01-01 19:05:15'
|
||||
date_begin: '2012-01-01 18:05:15'
|
||||
-
|
||||
create a sale order
|
||||
-
|
||||
!record {model: sale.order, id: order}:
|
||||
partner_id: base.res_partner_agrolait
|
||||
note: Invoice after delivery
|
||||
payment_term: account.account_payment_term
|
||||
-
|
||||
!record {model: sale.order.line, id: line}:
|
||||
product_id: event_product
|
||||
|
@ -25,6 +37,7 @@
|
|||
product_uom_qty: 8
|
||||
order_id: order
|
||||
name: sale order line
|
||||
event: event
|
||||
-
|
||||
confirm the sale order
|
||||
-
|
||||
|
@ -40,14 +53,7 @@
|
|||
!python {model: event.registration}: |
|
||||
order_id = ref('order')
|
||||
order = self.pool.get('sale.order').browse(cr, uid,order_id)
|
||||
print order.name
|
||||
registration_ids = self.search(cr,uid,[('origin','=',order.name)])
|
||||
if registration_ids == []:
|
||||
print 'erreur'
|
||||
else:
|
||||
if registration_ids[0].state == 'draft':
|
||||
print 'erreur mauvais state'
|
||||
-
|
||||
check registration has been created
|
||||
check the right type the good person state = draft
|
||||
-
|
||||
raise osv.except_osv(_('Error!'),_("The registration is not created"))
|
||||
|
Loading…
Reference in New Issue