From 8d91d9a580d9a3333e09220cada6ecd4ed01fbce Mon Sep 17 00:00:00 2001 From: "Atul Patel (OpenERP)" Date: Mon, 30 Apr 2012 13:09:03 +0530 Subject: [PATCH] [IMP]: Improve code . remove unused code. bzr revid: atp@tinyerp.com-20120430073903-52rcd0khdkcyx292 --- addons/event/event_view.xml | 2 +- addons/event_sale/event_sale.py | 23 ++++--- addons/event_sale/event_sale_view.xml | 9 +-- addons/portal_event/__init__.py | 22 ++++++ addons/portal_event/__openerp__.py | 40 +++++++++++ addons/portal_event/portal_event.py | 69 +++++++++++++++++++ .../portal_event/security/ir.model.access.csv | 4 ++ .../security/portal_event_security.xml | 33 +++++++++ 8 files changed, 184 insertions(+), 18 deletions(-) create mode 100644 addons/portal_event/__init__.py create mode 100644 addons/portal_event/__openerp__.py create mode 100644 addons/portal_event/portal_event.py create mode 100644 addons/portal_event/security/ir.model.access.csv create mode 100644 addons/portal_event/security/portal_event_security.xml diff --git a/addons/event/event_view.xml b/addons/event/event_view.xml index c6cf379ffb7..92e850c011e 100644 --- a/addons/event/event_view.xml +++ b/addons/event/event_view.xml @@ -102,7 +102,7 @@ - +
Venue :
diff --git a/addons/event_sale/event_sale.py b/addons/event_sale/event_sale.py index 1e0e745edce..911d316cca8 100644 --- a/addons/event_sale/event_sale.py +++ b/addons/event_sale/event_sale.py @@ -35,15 +35,6 @@ class product(osv.osv): product() -class sale_order(osv.osv): - _inherit = 'sale.order' - _columns = { - 'partner_id': fields.many2one('res.partner', 'Customer', readonly=False, states={'draft': [('readonly', False)]}, required=False, change_default=True, select=True), - 'partner_invoice_id': fields.many2one('res.partner', 'Invoice Address', readonly=False, required=False, states={'draft': [('readonly', False)]}, help="Invoice address for current sales order."), - 'partner_shipping_id': fields.many2one('res.partner', 'Shipping Address', readonly=False, required=False, states={'draft': [('readonly', False)]}, help="Shipping address for current sales order."), - } - - class sale_order_line(osv.osv): _inherit = 'sale.order.line' _columns = { @@ -108,13 +99,20 @@ class event_event(osv.osv): 'event_item_ids': fields.one2many('event.items','event_id', 'Event Items'), } - def open_qoutation(self, cr, uid, ids, partner_id, context=None): + def make_quotation(self, cr, uid, ids, context=None): res = {} event_pool = self.pool.get('event.event') register_pool = self.pool.get('event.registration') sale_order_line_pool = self.pool.get('sale.order.line') sale_order = self.pool.get('sale.order') user = self.pool.get("res.users").browse(cr, uid, uid, context=context) + partner_pool = self.pool.get("res.partner") + new_partner_id = False + partner_ids = partner_pool.search(cr, uid, [('name', '=', user.name), ('email', '=', user.user_email)]) + if not partner_ids: + new_partner_id = partner_pool.create(cr, uid, {'name': user.name, 'email': user.user_email}) + partner_invoice_id = self.pool.get('res.partner').address_get(cr, uid, [new_partner_id], ['invoice'])['invoice'] + partner_shipping_id = self.pool.get('res.partner').address_get(cr, uid, [new_partner_id], ['delivery'])['delivery'] for event_id in self.browse(cr, uid, ids, context=context): prod_pricelist_obj = self.pool.get('product.pricelist') sale_order_lines = [] @@ -122,6 +120,9 @@ class event_event(osv.osv): new_sale_id = sale_order.create(cr, uid, { 'date_order': event_id.date_begin, 'pricelist_id': price_list, + 'partner_id': new_partner_id, + 'partner_invoice_id': partner_invoice_id, + 'partner_shipping_id': partner_shipping_id }) if event_id.event_item_ids: for items in event_id.event_item_ids: @@ -145,7 +146,7 @@ class event_event(osv.osv): 'nodestroy': True, 'target': 'new', } - self.write(cr, uid, ids, {'state': 'confirm'}, context=context) + # self.write(cr, uid, ids, {'state': 'confirm'}, context=context) return res class event_items(osv.osv): diff --git a/addons/event_sale/event_sale_view.xml b/addons/event_sale/event_sale_view.xml index 52a0723f950..7f1504b7b69 100644 --- a/addons/event_sale/event_sale_view.xml +++ b/addons/event_sale/event_sale_view.xml @@ -36,15 +36,12 @@ form - +
-
- - -
@@ -53,7 +50,7 @@ event.items tree - + diff --git a/addons/portal_event/__init__.py b/addons/portal_event/__init__.py new file mode 100644 index 00000000000..70c078b769d --- /dev/null +++ b/addons/portal_event/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# 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 . +# +############################################################################## +import portal_event +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/portal_event/__openerp__.py b/addons/portal_event/__openerp__.py new file mode 100644 index 00000000000..88ca9815323 --- /dev/null +++ b/addons/portal_event/__openerp__.py @@ -0,0 +1,40 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2011 OpenERP S.A (). +# +# 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 . +# +############################################################################## + +{ + 'name' : "Portal Event", + 'version' : "1.0", + 'depends' : ["portal", "event_sale"], + 'author' : "OpenERP SA", + 'category': 'Portal', + 'description': """ +This module defines 'portals' to customize the access to your OpenERP database +for external users. + """, + 'update_xml': [ + 'security/portal_event_security.xml', + 'security/ir.model.access.csv', + ], + 'website': 'http://www.openerp.com', + 'installable': True, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: \ No newline at end of file diff --git a/addons/portal_event/portal_event.py b/addons/portal_event/portal_event.py new file mode 100644 index 00000000000..41a7d81bcc5 --- /dev/null +++ b/addons/portal_event/portal_event.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# 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 . +# +############################################################################## + +import time +from osv import fields, osv +from tools.translate import _ + +class event_event(osv.osv): + _inherit = 'event.event' + + def make_quotation(self, cr, uid, ids, partner_id, context=None): + event_pool = self.pool.get('event.event') + register_pool = self.pool.get('event.registration') + sale_order_line_pool = self.pool.get('sale.order.line') + sale_order = self.pool.get('sale.order') + res_partner_obj = self.pool.get('res.partner') + prod_pricelist_obj = self.pool.get('product.pricelist') + res_users_obj = self.pool.get('res.users') + customer = res_partner_obj.browse(cr, uid, partner_id, context=context) + + partner_id = res_users_obj.browse(cr, uid, uid, context=context).partner_id.id + if not partner_id: + raise osv.except_osv(_('Error !'), + _('There is no Partner defined ' \ + 'for this event:')) + + user_name = res_users_obj.browse(cr, uid, uid, context=context).name + price_list = prod_pricelist_obj.search(cr,uid,[],context=context)[0] + for event_id in self.browse(cr, uid, ids, context=context): + sale_order_lines = [] + price_list = prod_pricelist_obj.search(cr,uid,[],context=context)[0] + new_sale_id = sale_order.create(cr, uid, { + 'partner_id': partner_id, + 'pricelist_id': price_list, + 'partner_invoice_id': partner_id, + 'partner_shipping_id': partner_id, + 'date_order': event_id.date_begin + }) + if event_id.event_item_ids: + for items in event_id.event_item_ids: + product = items.product_id.id + sale_order_line = sale_order_line_pool.create(cr, uid, { + 'order_id': new_sale_id, + 'name': items.product_id.name, + 'product_uom_qty': items.qty, + 'product_id': items.product_id.id, + 'product_uom': items.uom_id.id, + 'price_unit': items.price, + 'date_planned': items.sales_end_date, + }, context=context) + return True diff --git a/addons/portal_event/security/ir.model.access.csv b/addons/portal_event/security/ir.model.access.csv new file mode 100644 index 00000000000..2ca1e3def91 --- /dev/null +++ b/addons/portal_event/security/ir.model.access.csv @@ -0,0 +1,4 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_event,event,event.model_event_event,portal_event.group_event_portal,1,0,0,0 +access_registration,registration,event.model_event_registration,portal_event.group_event_portal,1,0,0,0 +access_event_items,event.items,event.model_event_event,portal_event.group_event_portal,1,1,1,0 \ No newline at end of file diff --git a/addons/portal_event/security/portal_event_security.xml b/addons/portal_event/security/portal_event_security.xml new file mode 100644 index 00000000000..64c077c7bb9 --- /dev/null +++ b/addons/portal_event/security/portal_event_security.xml @@ -0,0 +1,33 @@ + + + + + + + + Portal User + + + + + Events Portal + + + + + + Personal Events + + [] + + + + + Personal Registrations + + [('partner_id.email','=',user.login)] + + + + + \ No newline at end of file